Jump to content

Stock amount product with combinations


Recommended Posts

Hi, I have a question about stock amount for a product with combinations.

I have a 'mother' product with reference 1214 which has 2 daughters with reference 1214-1 and 1214-2

The stock amount for 1214-1 = 2 and for 1214-2 = 3

I have been told that the normal behaviour would be that the mother with reference 1214 should be in sync with the combinations-daughters, therefor stock of the mother product should be 2 + 3 = 5.

In our situation, the stock of the mother product is always '0'.

Normally this would not be a problem, but in category view it looks like the product combinations are not in stock (because the mother has 0 stock), while the combinations are in stock.

Does anybody know if there is a setting to make the mother product behave like this?

Or what is causing the mother to show 0 in stock?

I hope I made the issue clear, if not, please feel free to ask me.

Best regards, Ellen

Prestashop version 8.1.1

 

 

Link to comment
Share on other sites

Hi.

So there will probably be an error in saving to the database.
You need to check the ps_stock_available table to find the product ID.
It should be there if the column id_product_attribute = 0 then quantity should be the sum of all id_product_attribute quantity.

obrazek.png.dc2b986d19e733b21bc77587aa0b8625.png

Edited by ps8moduly.cz (see edit history)
Link to comment
Share on other sites

Thank you, I checked some products and it looks like the new products - added after migration to 8.1.1 behave correctly. But the old products don't.

So, something must have gone wrong during migration, no clue if this can be resolved. I asked the developer.

If you have a solution, ;) That would be great! So, I can share it with them.

Cheers, Ellen

Link to comment
Share on other sites

Here is a complete script that will update everything in the database. You will then need to clear the cache.

Upload the file to the root of the eshop and run it in the address bar.

E.g.: https://my-shop.com/update-attributes-stock.php

update-attributes-stock.zip

 

Sample code:

include_once('./config/config.inc.php');

$db = Db::getInstance();
$sql = 'SELECT a.id_product FROM '._DB_PREFIX_.'stock_available a WHERE a.id_product_attribute > 0 GROUP BY a.id_product';
$products = Db::getInstance()->ExecuteS( $sql );

if ($products) {
    foreach($products as $product) {
        $getAttributesQty = $db->getvalue('SELECT SUM(a.quantity) as qty FROM '._DB_PREFIX_.'stock_available a WHERE a.id_product = '.$product['id_product'].' AND a.id_product_attribute > 0');
        $getAttributesPhysicalQty = $db->getvalue('SELECT SUM(a.physical_quantity) as qty FROM '._DB_PREFIX_.'stock_available a WHERE a.id_product = '.$product['id_product'].' AND a.id_product_attribute > 0');
        $db->update('stock_available', array('quantity' => $getAttributesQty, 'physical_quantity' => $getAttributesPhysicalQty), 'id_product = '.$product['id_product'].' AND id_product_attribute = 0');
        echo 'updated product: '.$product['id_product'].' | quantity: '.$getAttributesQty.' | physical quantity: '.$getAttributesPhysicalQty.'<br>';
    }
} 

 

Edited by ps8moduly.cz (see edit history)
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...