Jump to content

Can't create a product with Prestasharp (C# library)


metispt

Recommended Posts

Hello there,

 

I am using Prestasharp (https://github.com/Bukimedia/PrestaSharp) to update my site automatically via webservices.

 

Upon invoking the ProductFactory.Add(product), the response I get is "BadRequest"

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<message><![CDATA[Internal error. To see this error please display the PHP errors.]]></message>
</error>
</errors>
</prestashop>
  HttpStatusCode: BadRequest
  ResponseContent=
<prestashop>
<product>
  <id_category_default>4</id_category_default>
  <id_tax_rules_group>1</id_tax_rules_group>
  <id_shop_default>0</id_shop_default>
  <on_sale>1</on_sale>
  <online_only>0</online_only>
  <ean13></ean13>
  <upc></upc>
  <ecotax>0</ecotax>
  <minimal_quantity>0</minimal_quantity>
  <price>2.85000000000000000</price>
  <wholesale_price>0</wholesale_price>
  <unity>UN</unity>
  <unit_price_ratio>0</unit_price_ratio>
  <additional_shipping_cost>0</additional_shipping_cost>
  <reference>5031REF549</reference>
  <supplier_reference></supplier_reference>
  <location></location>
  <width>0</width>
  <height>0</height>
  <depth>0</depth>
  <weight>0</weight>
  <quantity_discount>0</quantity_discount>
  <customizable>0</customizable>
  <uploadable_files>0</uploadable_files>
  <text_fields>0</text_fields>
  <active>0</active>
  <id_product_redirected>0</id_product_redirected>
  <available_for_order>0</available_for_order>
  <condition>new</condition>
  <show_price>1</show_price>
  <indexed>1</indexed>
  <visibility>both</visibility>
  <cache_is_pack>0</cache_is_pack>
  <cache_has_attachments>0</cache_has_attachments>
  <is_virtual>0</is_virtual>
  <cache_default_attribute>0</cache_default_attribute>
  <advanced_stock_management>0</advanced_stock_management>
  <meta_description />
  <meta_keywords />
  <meta_title />
  <link_rewrite>
    <language id="1">sacos-aspirador-ref-549</language>
    <language id="2">sacos-aspirador-ref-549</language>
  </link_rewrite>
  <name>
    <language id="1">Sacos Aspirador Refª549</language>
    <language id="2">Sacos Aspirador Refª549</language>
  </name>
  <description />
  <description_short />
  <available_now />
  <available_later />
  <associations>
    <categories>
      <category>
        <id>4</id>
      </category>
    </categories>
    <images />
    <combinations />
    <product_option_values />
    <product_features />
    <tags />
    <stock_availables />
    <product_bundle />
    <accessories />
  </associations>
</product>
</prestashop>

I know that the Prestashop API is very picky about the data that it will accept, but I can't see what is wrong anywhere.

 

Someone has any experience with this?

 

Link to comment
Share on other sites

Tank you very much!

I did enable the debug mode in Prestashop and it gave me more detailed hints at what was wrong.

 

I happened to have a couple of errors (at least), among those (as a note to myself but also to others that may experience this sort of problems):

1. The price being sent contained many more decimals than it apparently supports. I solved it by using the Prestasharp function GetPrestaShopPrice().

2. The LinkRewrite field is very sensitive. I created a function to sanitize this field and replace all characters that I could think of with dashes.

3. The Name field is also sensitive to certain characters (I didn't know that). I created a function to sanitize this field and remove all characters that I could think of .

 

Next stop: upload images, wish me luck!

  • Like 1
Link to comment
Share on other sites

Tank you very much!

I did enable the debug mode in Prestashop and it gave me more detailed hints at what was wrong.

 

I happened to have a couple of errors (at least), among those (as a note to myself but also to others that may experience this sort of problems):

1. The price being sent contained many more decimals than it apparently supports. I solved it by using the Prestasharp function GetPrestaShopPrice().

2. The LinkRewrite field is very sensitive. I created a function to sanitize this field and replace all characters that I could think of with dashes.

3. The Name field is also sensitive to certain characters (I didn't know that). I created a function to sanitize this field and remove all characters that I could think of .

 

Next stop: upload images, wish me luck!

 

Wishing you best of luck!  Let us know how you get along,  sounds like great work.  There is good demand for webservice experience.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...