Jump to content

How to make prestashop to not update product quantities after order validation


a064855

Recommended Posts

 I am new to prestashop and I am trying to make a payment module where I need to duplicate an order for statistical issues. My problem is that the duplicate order also substracts from product stock and I need to know where, after an order validation, does prestashop update stock to avoid calling the corresponding function. In few words, I call validateOrder() twice but I need that StockAvailable be updated once.

By the way, I examined the whole validateOrder() function searching for the update section / function but I haven't been able to find it.

The only related code that I have been able to find was this:

// updates stock in shops
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))
{
   $product_list = $order->getProducts();
   foreach ($product_list as $product)
   {
      // if the available quantities depends on the physical stock
      if (StockAvailable::dependsOnStock($product['product_id'])) 
      {
         // synchronizes
         StockAvailable::synchronize($product['product_id'], $order->id_shop);
      }
   }
}

but this is only works when advanced stock management is enabled.

Thanks.

Edited by a064855 (see edit history)
Link to comment
Share on other sites

In file classes/PaymentModule.php, validateOrder function has the following lines:

$order_detail = new OrderDetail(null, null, $this->context);
$order_detail->createList($order, $this->context->cart, $id_order_state, $order->product_list, 0, true, $package_list[$id_address][$id_package]['id_warehouse']);

classes/order/OrderDetail.php, createList function has:

$this->create($order, $cart, $product, $id_order_state, $id_order_invoice, $use_taxes, $id_warehouse);

The function create has:

$this->checkProductStock($product, $id_order_state);

Function checkProductStock has:

$update_quantity = StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], -(int)$product['cart_quantity']);

So there is the route to deducting quantity.

 

My suggestion would be to use the same method to add the quantity back before creating duplicate order in your specific payment module. Or you could create an override, that would check if the cart already has an order, so the quantity deduction is not necessary.

 

Hope this helps.

Link to comment
Share on other sites

  • 5 months later...
  • 1 year later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...