Jump to content

When i cancel my order in admin area, the stock isn't changed back to its original state!


Recommended Posts

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

  • 2 weeks later...

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_id

2) Did a search / replace all with ’ to ‘

Link to comment
Share on other sites

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

×
×
  • Create New...