Automatically increase stock after order - Prestashop

I manually manage my stocks on Prestashop. I am looking for a solution to automatically return the initial stock after a sales order.

For example, a product is ordered in two copies with an initial stock of 7. I would like the stock to remain at 7 after the order and not at 5.

Do you know a technique that would allow me to realize this automatically?


ANSWERS:


Put a Hook on Order Confirmation (displayOrderConfirmation) in a new module (you can generate one at ) and check whats inside the cart then put it again in your stocks :

public function hookDisplayOrderConfirmation($params) {
    $order = $params['order'];
    $cart = new Cart($order->id_cart); 
    $products = $cart->getProducts(); 
    foreach ($products as $product) {
       $removed_qty = (int) $product['quantity'];
       $past_qty = (int) StockAvailable::getQuantityAvailableByProduct($product['id_product'], $product['id_product_attribute']);
       $new_qty = $removed_qty + $past_qty;
       StockAvailable::setQuantity($product['id_product'], $product['id_product_attribute'], $new_qty);
    }
}


 MORE:


 ? Http body empty when adding customer via prestashop webservice
 ? prestashop multiple domains for same shop
 ? Prestashop: Modify mailalert module to have more visible product quantity
 ? Prestashop 1.6 overriding FrontController.php for adding custom hook
 ? Is there a way to make Prestashop's Layared Filter Module to use query parameters instead of anchors (hashes)?
 ? Access to a sub tag in jquery
 ? Prestashop: How i can to develop website without effect the online store
 ? PrestaShop, Class not found in ModuleAdminController::getController
 ? prestashop 1.6 - check if user is in group
 ? Call a prestashop module with ajax