Saikios Saikios - 8 days ago 5
PHP Question

Adding products in cart by sku on prestashop

I'm using prestashop webservice for an integration,

I'm sending throw POST
http://url/prestashop/api/carts?schema=blank&ws_key=MYKEY=keywords&language=1

with this xml

<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<customer>
<id_customer>12</id_customer>
<id_currency>1</id_currency>
<id_lang>1</id_lang>
<associations>
<cart_rows>
<cart_row>
<CartRow>
<id_product>1</id_product>
<id_product_attribute>1</id_product_attribute>
<id_address_delivery>10</id_address_delivery>
<quantity>1</quantity>
</CartRow>
</cart_row>
</cart_rows>
</associations>
</customer>
</prestashop>


I have two issues I would like to fix,

First:
I'm getting this error:

<![CDATA[[SQL Error] Column 'id_product_attribute' cannot be null. From CartCore->setWsCartRows() Query was : INSERT INTO `ps_cart_product`(`id_cart`, `id_product`, `id_product_attribute`, `id_address_delivery`, `quantity`, `date_add`, `id_shop`) VALUES (18, 0, NULL, 0, 0, NOW(), 1)]]>


but the id attribute and product are on the database (I checked on the table products and prorduct_attribute)

Second:

I only have the sku is there any way to get the id_product and the id_product_attribute throw the webservice product? or do I have to build a custom module or something to get the productid?

Thanks a lot for the help!

Answer

Your XML es wrong formed. Notice that in query error id_product and id_product_attribute values are 0 and NULL, so data you are passing into XML never find correct destination in webservice.

If you have SKU you must first get products filtered by reference (or ean13 or UPC or the field that SKU represent in Prestashop). That way you will have id_product and id_product_attribute yo pass it to webservice in your XML.

Good luck.

Comments