Reputation: 1652
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
Upvotes: 2
Views: 2670
Reputation: 57
$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();
}
Upvotes: 0
Reputation: 57626
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.
Upvotes: 0