Jump to content

decrementing existence of product


Recommended Posts

You mean which snippet is responsible of decreasing product quantities?

OrderHistory.php

OrderHistory::changeIdOrderState()

 

Look for StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int)$product['product_quantity'], $order->id_shop);

 

And other occurrences of that method

Link to comment
Share on other sites

Nemo1 Hi thank you very much for your answer. 

 

Nemo1, just let me know the resposable of declining product by any method. 

 

Nemo1, based on your answer, I found the file in: 

classes / order / => OrderHistory.php 

 

Nemo1 would do the following: 

 

Instead of reducing the product, the product increases. 

The code to which you refer is me: 

 

StockAvailable :: updateQuantity ($ product ['product_id'], $ product ['product_attribute_id'], - (int) $ product ['product_quantity'], $ Order-> id_shop); 

 

I note that this - (int) $ product ['product_quantity'] 

Changing it to + (int) $ product ['product_quantity'] 

 

It can run?

Link to comment
Share on other sites

Very good Nemo1 thanks for your answer.

 

Nemo1, In prestashop there is an option to cancel or accept orders placed by buyers, specifically php level, where I can find the code where the user (administrator) cancels the purchase they have made?

 

I hope you understand me

Link to comment
Share on other sites

Exactly 

 

I mean, when a customer makes a purchase, the administrator has the option of:

 

* cancel 

* approve 

* among others ... 

 

If for example the customer bought an article available there 20, when it is performed in the 19. 

 

When the administrator cancel the purchase, return again to 20. 

 

I wonder php code level, where it performs that action, that is, that php file I find that? 

 

Muchs thanks for your valuable answers Nemo1. They have been of great benefit.

Link to comment
Share on other sites

It should be the same one I mentioned before actually, as it creates a new order state

 

($old_os->id == Configuration::get('PS_OS_ERROR') || $old_os->id == Configuration::get('PS_OS_CANCELED')) &&
!StockAvailable::dependsOnStock($product['id_product'], (int)$order->id_shop))
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int)$product['product_quantity'], $order->id_shop);
Link to comment
Share on other sites

Hi Nemo1, thanks so much for your answers.

 

 

This code works when you have your prestashop site but the option of multi-shop.

 

1.- ***********************************

 
OrderDetail.php
 
** Original State
 
if (!StockAvailable::dependsOnStock($product['id_product']))
$update_quantity = StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], -(int)$product['cart_quantity']);
 
** Changed State.
 
/**
 * Check the order status
 * @param array $product
 * @param int $id_order_state
 */
protected function checkProductStock($product, $id_order_state)
{
if ($id_order_state != Configuration::get('PS_OS_CANCELED') && $id_order_state != Configuration::get('PS_OS_ERROR'))
{
$update_quantity = true;
if (!StockAvailable::dependsOnStock($product['id_product']))
$update_quantity = StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], +(int)$product['cart_quantity']);
 
if ($update_quantity)
$product['stock_quantity'] -= $product['cart_quantity'];
 
if ($product['stock_quantity'] < 0 && Configuration::get('PS_STOCK_MANAGEMENT'))
$this->outOfStock = true;
Product::updateDefaultAttribute($product['id_product']);
}
}
 
2.- *********************************** State Error/Canceled.
 
OrderHistory.php
 
** Original State:
 
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop);
 
** Changed State.
 
// if waiting for payment => payment error/canceled elseif (!$new_os->logable && !$old_os->logable && in_array($new_os->id, $errorOrCanceledStatuses) && !in_array($old_os->id, $errorOrCanceledStatuses) && !StockAvailable::dependsOnStock($product['id_product'])) StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int)$product['product_quantity'], $order->id_shop);

 

 

 

**********************************************************

 

With this code (adapted to my needs), do the following: 
 
1.-When an order is being performed, rather than decrease existence, increases. 
 
2.-When you want to cancel an order, rather than increasing, decreases.
Link to comment
Share on other sites

×
×
  • Create New...