a064855 Posted June 2, 2015 Share Posted June 2, 2015 (edited) 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 shopsif (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 June 2, 2015 by a064855 (see edit history) Link to comment Share on other sites More sharing options...
pishkus Posted June 4, 2015 Share Posted June 4, 2015 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 More sharing options...
a064855 Posted June 5, 2015 Author Share Posted June 5, 2015 Thanks very much! Link to comment Share on other sites More sharing options...
jonyellery Posted November 23, 2015 Share Posted November 23, 2015 Thank you so much! I search for the answer all my friday. Link to comment Share on other sites More sharing options...
octagonal elf Posted July 22, 2017 Share Posted July 22, 2017 Hi. I have similar problem, the difference is, I need to deduct the quantity across all attributes, any idea how do I ignore the "id_product_attribute" and make updateQuantity( ) to update based on "id_product" ? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now