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.