ellenb4t Posted January 2 Share Posted January 2 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 More sharing options...
ps8modules.com Posted January 2 Share Posted January 2 (edited) 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. Edited January 2 by ps8moduly.cz (see edit history) Link to comment Share on other sites More sharing options...
ellenb4t Posted January 3 Author Share Posted January 3 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 More sharing options...
ps8modules.com Posted January 3 Share Posted January 3 Hi. It can be solved with a small php script. It depends on how many products with combinations need to be fixed and also if the combination IDs are correct. Link to comment Share on other sites More sharing options...
ps8modules.com Posted January 3 Share Posted January 3 (edited) 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 January 3 by ps8moduly.cz (see edit history) Link to comment Share on other sites More sharing options...
ellenb4t Posted January 6 Author Share Posted January 6 Thank you very much for your help! I will give this to the developer and hopefully it will be resolved this way. 1 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