Siguana Posted December 14, 2023 Share Posted December 14, 2023 I'm using PrestaShop webservice for adding products to the store. All is fine, except when I set the stock of the products. I'm using this code for seting the stock of the products: $productData = '<?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <stock_available> <id><![CDATA[{{'.$idStock.'}}]]></id> <quantity><![CDATA[20]]></quantity> <id_product>{{'.$intID.'}}</id_product> <id_product_attribute><![CDATA[0]]></id_product_attribute> <depends_on_stock>0</depends_on_stock> <out_of_stock>2</out_of_stock> <id_shop>1</id_shop> </stock_available> </prestashop>'; $insertProductUrl = $apiUrl . '/stock_availables/' . $idStock; $ch = curl_init($insertProductUrl); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); curl_setopt($ch, CURLOPT_POSTFIELDS, $productData); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/xml', 'Authorization: Basic ' . base64_encode($apiKey . ':') )); $response = curl_exec($ch); curl_close($ch); But, in the frontend, the product is showed as "out of stock". What is wrong? Link to comment Share on other sites More sharing options...
Siguana Posted December 15, 2023 Author Share Posted December 15, 2023 I was able to fix it with this code: $sqlStock = "UPDATE ps_product_shop SET cache_default_attribute = 0 WHERE id_product = " . $ID . ";"; $resultStock = $DB->query($sqlStock); I don't understand why I have to do this, but it works 🤷🏻 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now