Jump to content

Product is out of stock


Recommended Posts

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">

                    $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);



But, in the frontend, the product is showed as "out of stock".  What is wrong?

Link to comment
Share on other sites

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

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...