-- HikaShop version -- : 5.1.1
-- Joomla version -- : 5
-- PHP version -- : 8
-- Browser(s) name and version -- :  Chrome
Hi,
I would like to create programatically in my plugin a system to give a calculate discount on checkout for a customer who has an "avoir (french in text) like a invoice credit" from another gift - i tried to make that in my my plugin
function onAfterCartProductsLoad(&$cart)
    { if ($avoir > 0) {
                // Créer un objet de remise
                $discount = new stdClass();
                file_put_contents("logBob.txt", "--- onAfterCartProductsLoad --- discount" .PHP_EOL, FILE_APPEND);
                $discount->discount_id = 0; // 0 pour indiquer qu'il s'agit d'une remise à la volée
                $discount->discount_value = -$avoir; // Remise négative pour réduire le total
                $discount->discount_type = 'cart'; // Type "cart" pour le total du panier
                $discount->discount_name = "Avoir client";
                file_put_contents("logBob.txt", "--- onAfterCartProductsLoad --- discount name" .PHP_EOL, FILE_APPEND);
                // Ajouter la remise au panier
                if (!isset($cart->cart_discounts)) {
                    $cart->cart_discounts = [];
                }
                $cart->cart_discounts[] = $discount;
                file_put_contents("logBob.txt", "--- onAfterCartProductsLoad --- discount name".print_r($cart->cart_discounts,true).PHP_EOL, FILE_APPEND);
                // Mettre à jour le total du panier
                $cart->full_total->prices[0]->price_value -= $avoir;
                $cart->full_total->prices[0]->price_value_with_tax -= $avoir;
                // Forcer la mise à jour des totaux des produits et du panier
                foreach ($cart->cart_products as &$product) {
                    if (!isset($product->total)) {
                        continue;
                    }
                    // Ajuster les totaux pour refléter la remise
                    $product->total->prices[0]->price_value -= $avoir / count($cart->cart_products);
                    $product->total->prices[0]->price_value_with_tax -= $avoir / count($cart->cart_products);
                }
            }
...but when i click pay button - the cart is empty as i cancelled
I dont understand or i don't know why it's not easy to create a discount on subtotal or total
easily
Could you help me Please ?