Jump to content

Edit History

innovacy

innovacy

  

In newer PrestaShop versions, the stock of a combination is managed by the stock_available entity. The "quantity" field is not being used and has been superseded. To update the stock of a combination using the PrestaShop Web Service API, follow these steps:

Retrieve the id_stock_available: To get the id_stock_available for a specific combination, you can use the GET method with the /combinations resource:

GET https://yourshop.com/api/stock_availables?display=[id]&filter[id_product]=YOUR_PRODUCT_ID&filter[id_product_attribute]=YOUR_COMBINATION_ID

Replace yourshop.com with your domain, YOUR_PRODUCT_ID with the specific product ID you want to update, and YOUR_COMBINATION_ID with the specific combination ID (id_product_attribute).

Update the stock available quantity: Now that you have the id_stock_available (returned as id), you can update the stock quantity using the PUT method with the /stock_availables resource:

PUT https://yourshop.com/api/stock_availables/STOCK_AVAILABLE_ID

Replace yourshop.com with your domain, and STOCK_AVAILABLE_ID with the id_stock_available you obtained in the previous step.

In the XML body of your PUT request, set the new stock quantity:

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
    <stock_available>
        <id><![CDATA[STOCK_AVAILABLE_ID]]></id>
        <id_product><![CDATA[YOUR_PRODUCT_ID]]></id_product>
        <id_product_attribute><![CDATA[YOUR_COMBINATION_ID]]></id_product_attribute>
        <quantity><![CDATA[NEW_QUANTITY]]></quantity>
        <depends_on_stock><![CDATA[0]]></depends_on_stock>
        <out_of_stock><![CDATA[2]]></out_of_stock>
    </stock_available>
</prestashop>

Replace STOCK_AVAILABLE_ID with the id_stock_available, YOUR_PRODUCT_ID with the specific product ID you want to update, YOUR_COMBINATION_ID with the specific combination ID (id_product_attribute), and NEW_QUANTITY with the desired stock quantity.

In newer versions of PrestaShop, you can utilize the PATCH method to update only the id and quantity, allowing you to bypass the need to include other required fields. That's the method we use to efficiently perform tens of thousands of stock updates on a daily basis.

Please refer to the API reference to ensure that all my provided examples are accurate, as I haven't tested them personally, but simply sharing them based on my memory of the PrestaShop API.

innovacy

innovacy

In newer PrestaShop versions, the stock of a combination is managed by the stock_available entity. The "quantity" field is not being used and has been superseded. To update the stock of a combination using the PrestaShop Web Service API, follow these steps:

Retrieve the id_stock_available: To get the id_stock_available for a specific combination, you can use the GET method with the /combinations resource:

GET https://yourshop.com/api/combinations?display=[id,id_stock_available]&filter[id_product_attribute]=YOUR_COMBINATION_ID

Replace yourshop.com with your domain, and YOUR_COMBINATION_ID with the specific combination ID you want to update.

Update the stock available quantity: Now that you have the id_stock_available, you can update the stock quantity using the PUT method with the /stock_availables resource:

PUT https://yourshop.com/api/stock_availables/STOCK_AVAILABLE_ID

Replace yourshop.com with your domain, and STOCK_AVAILABLE_ID with the id_stock_available you obtained in the previous step.

In the XML body of your PUT request, set the new stock quantity:

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
    <stock_available>
        <id><![CDATA[STOCK_AVAILABLE_ID]]></id>
        <quantity><![CDATA[NEW_QUANTITY]]></quantity>
    </stock_available>
</prestashop>

Replace STOCK_AVAILABLE_ID with the id_stock_available, and NEW_QUANTITY with the desired stock quantity.

×
×
  • Create New...