2
votes

I am using Prestashop Advance Stock Management System for some products. While I place order with the product (having advance stock management enabled), the quantity is deducting from the real input value(the input box which allows us to enter quantity manually) not from stock (I can see the same quantity in stock management list). After I change the order status to "Shipped/Invoiced" the stock quantity is reduced.

When I cancel that order, the quantity is not increased in stock. I want to automatically increase the stock quantity when I cancel the order. I am newbie and I don't have any idea how to do it. Please help me to resolve this issue.

Thanks in advance

2
I do not checked the issue in shop, but logically it looks correct. Imean, you shipped order "stock - qty", then you cancel order (no stock operations), then you need to get back products, maybe check it and update qty e.g. if products still new etc. - Serge P
But what i need is , the product quantity should automatically increase while i cancel an order. - viji
Did my solution helped you? You didn't give any comments on your question or answer? What about bounty? - Somnath Muluk

2 Answers

0
votes

You should call OrderDetail::checkProductStock which in turn calls StockAvailable::updateQuantity

$update_quantity = StockAvailable::updateQuantity(...

What's interesting is that before updating the quantity there's this condition

if (!StockAvailable::dependsOnStock($product['id_product']))

I suggest that you override this method and return true when you need to.

Also you can set a global flag before duplicating the order and then check that flag and if it's true return true to prevent updating the stock.

the override code in override/classes/stock/StockAvailable.php

class StockAvailable extends StockAvailableCore 
{

  public static function dependsOnStock($id_product, $id_shop = null)
  {
    $no_quantity_update = isset($GLOBALS['no_quantity_update']) && $GLOBALS['no_quantity_update'];
    if ($no_quantity_update) 
      return true;
    else return parent::dependsOnStock($id_product, $id_shop = null);
  }

}

To make this override effective, delete the file cache/class_index.php to refresh the overrides list

Your module code:

//set to false just to be sure
$GLOBALS['no_quantity_update'] = false;
$this->module->validateOrder($cart->id, Configuration...

You can modify directly on the core code but that's not recommended

Also you can check different hooks list.

0
votes
$productid = $request->input('productid');
$userid = $request->input('userid');  
$quantityt= $request->input('quantity');

$data2=Cart::where('productid',$productid)->where('userid',$userid)->pluck('id');

$productq=Products::where('id',$productid)->get();

foreach($productq as $pro)
{
    $product = Products::find($pro->id);
    $product->quantity = $pro->quantity + $quantityt;
    $product->save();
}