Housy Posted January 12, 2011 Share Posted January 12, 2011 Hello,for example if costumer ordered 5 pieces of one product, which is 10 pieces in stock and i cancel that order, then the stock isn't changed back to 10 pieces. Why is that?Thanks,Housy Link to comment Share on other sites More sharing options...
noesac Posted January 12, 2011 Share Posted January 12, 2011 Yes I've found this happening to me on the odd occasion. I think it's just a bug but not one I have been able to consistently replicate. Link to comment Share on other sites More sharing options...
Housy Posted January 14, 2011 Author Share Posted January 14, 2011 Well this problem or bug it's really annoying, cause for example if i have one last piece in stock and i bought that last piece but then i decide i don't want this product, i want other product. Then i have to cancel this order and then my stock for that product will be 0 (zero), so then this product is out of stock.Stock just isn't changed back to its original state, when i cancel the order it should be set back to 1, not 0 (zero).Is it somehow possible to fix that problem/bug?Thank you,Housy Link to comment Share on other sites More sharing options...
Housy Posted January 17, 2011 Author Share Posted January 17, 2011 Nobody knows :question: It's just annoying, i have to repair/change the stock back to original state every time manually :-S Housy Link to comment Share on other sites More sharing options...
noesac Posted January 26, 2011 Share Posted January 26, 2011 Yeah I wish there was a solution, it's really annoying Link to comment Share on other sites More sharing options...
inveostore.com Posted January 27, 2011 Share Posted January 27, 2011 It might be related to Bug 6817 Link to comment Share on other sites More sharing options...
noesac Posted January 27, 2011 Share Posted January 27, 2011 is it safe to implement this in 1.3.1? Link to comment Share on other sites More sharing options...
inveostore.com Posted January 27, 2011 Share Posted January 27, 2011 Yes. But please see comments to this fix and also replace quotes (’ with '). Link to comment Share on other sites More sharing options...
noesac Posted January 27, 2011 Share Posted January 27, 2011 hum I don't quite understand what you mean about the quotes? Link to comment Share on other sites More sharing options...
noesac Posted January 27, 2011 Share Posted January 27, 2011 Is this right?Find: UPDATE `‘._DB_PREFIX_.‘product‘.($product_pack->product_attribute_id ? ‘_attribute‘ : ‘‘).‘`Replace with: UPDATE `‘._DB_PREFIX_.‘product‘.($orderDetail->product_attribute_id ? ‘_attribute‘ : ‘‘).‘`Find: ($product_pack->product_attribute_id ? ‘ AND `product_attribute_id` = ‘.intval($product_pack->product_attribute_id) : ‘‘));Replace with: ($orderDetail->product_attribute_id ? ‘ AND `product_attribute_id` = ‘.intval($orderDetail->product_attribute_id) : ‘‘));Find: if ($product_pack->product_attribute_id)Replace with: if ($orderDetail->product_attribute_id)I did two things: 1) Did a search / replace all with id_product_attribute to product_attribute_id2) Did a search / replace all with ’ to ‘ Link to comment Share on other sites More sharing options...
noesac Posted January 27, 2011 Share Posted January 27, 2011 Actually the fix above kind of scares me...looks risky!Do you think it would be safer if I just replaced these three instances of $product_pack with $orderDetail? Link to comment Share on other sites More sharing options...
inveostore.com Posted January 27, 2011 Share Posted January 27, 2011 After applying that fix, Product::reinjectQuantities() method should look: public static function reinjectQuantities(&$orderDetail, $quantity) { if (!Validate::isLoadedObject($orderDetail)) die(Tools::displayError()); if (Pack::isPack(intval($orderDetail->product_id))) { $products_pack = Pack::getItems(intval($orderDetail->product_id), intval(Configuration::get('PS_LANG_DEFAULT'))); foreach($products_pack AS $product_pack) { // Added - note: PS fix this incorrectly by using id_product_attribute instead of product_attribute_id Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'product'.($orderDetail->product_attribute_id ? '_attribute' : '').'` SET `quantity` = `quantity`+'.intval($product_pack->pack_quantity * $quantity).' WHERE `id_product` = '.intval($product_pack->id). ($orderDetail->product_attribute_id ? ' AND `id_product_attribute` = '.intval($orderDetail->product_attribute_id) : '')); if ($orderDetail->product_attribute_id) Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'product` SET `quantity` = ( SELECT SUM(`quantity`) FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product` = '.intval($product_pack->id).' ) WHERE `id_product` = '.intval($product_pack->id)); } } $sql = ' UPDATE `'._DB_PREFIX_.'product'.($orderDetail->product_attribute_id ? '_attribute' : '').'` SET `quantity` = `quantity`+'.intval($quantity).' WHERE `id_product` = '.intval($orderDetail->product_id). ($orderDetail->product_attribute_id ? ' AND `id_product_attribute` = '.intval($orderDetail->product_attribute_id) : ''); if ($orderDetail->product_attribute_id) Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'product` SET `quantity` = ( SELECT SUM(`quantity`) FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product` = '.intval($orderDetail->product_id).' ) WHERE `id_product` = '.intval($orderDetail->product_id)); if (!Db::getInstance()->Execute($sql) OR !Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'order_detail` SET `product_quantity_reinjected` = `product_quantity_reinjected` + '.intval($quantity).' WHERE `id_order_detail` = '.intval($orderDetail->id))) return false; $orderDetail->product_quantity_reinjected += intval($quantity); return true; } Link to comment Share on other sites More sharing options...
noesac Posted January 27, 2011 Share Posted January 27, 2011 Ok sure, so if I replace my code with that one it should fix the problem?Are you sure it works with v1.3.1? Link to comment Share on other sites More sharing options...
inveostore.com Posted January 27, 2011 Share Posted January 27, 2011 It may solve your problem (if it was caused by this bug) and it is safe to test this code with other PS version. There is nothing you can lost. Link to comment Share on other sites More sharing options...
noesac Posted January 27, 2011 Share Posted January 27, 2011 Great thanks! What other things does this page do? I just implemented it and want to run a few tests to make sure it's ok. What's the best way to confirm that it hasn't affected any other part of the site? Link to comment Share on other sites More sharing options...
inveostore.com Posted January 27, 2011 Share Posted January 27, 2011 If your product page display fine, then there is no parse error on Product class and the only thing which is now affected is product quantity re-injection which is only called when order is cancelled. Link to comment Share on other sites More sharing options...
noesac Posted January 27, 2011 Share Posted January 27, 2011 Great thanks! It's not causing any errors so that part of it looks fine, however I just tested it by creating a new order then cancelling it, but the quantity still remains. I'm not sure if the fix worked Link to comment Share on other sites More sharing options...
inveostore.com Posted January 27, 2011 Share Posted January 27, 2011 Code I have posted we use in our store and works fine (it corrects quantities for product with attributes). If it did not help, it was likely another bug. Link to comment Share on other sites More sharing options...
noesac Posted January 27, 2011 Share Posted January 27, 2011 ok no probs thanks Link to comment Share on other sites More sharing options...
Housy Posted January 27, 2011 Author Share Posted January 27, 2011 I just tested it by creating a new order then cancelling it, but the quantity still remains. I'm not sure if the fix worked Same here, with no luck :down: Any other solution maybe?Housy Link to comment Share on other sites More sharing options...
Recommended Posts