isLogged() && Configuration::get('INVITE_CREDIT_ENABLE') == 1) { include_once(dirname(__FILE__).'/invite.php'); // si présent dans les exclusions $sql = 'SELECT id_customer FROM `'._DB_PREFIX_.'customer_credits` WHERE id_customer = ' .(int) $cookie->id_customer; if(Db::getInstance()->getValue($sql)){ Tools::redirectLink(Link::getPageLink('order.php', TRUE)); } $invite = new Invite(); $total = $cart->getOrderTotal(TRUE, Cart::ONLY_PRODUCTS) + $cart->getOrderTotal(TRUE, Cart::ONLY_DISCOUNTS); $credit = $invite->get_credit_value((int) $cookie->id_customer); if($credit > $total) { $invite->set_credit_value((int) $cookie->id_customer, $credit - $total); $credit = $total; } else { $invite->set_credit_value((int) $cookie->id_customer, 0); } $discount = new Discount(); $discount->id_customer = (int) $cookie->id_customer; $discount->id_discount_type = 2; $discount->cumulable = 1; $discount->cumulable_reduction = 1; $discount->minimal = 0; $discount->cart_display = 1; $discount->active = 1; $discount->quantity = 1; $discount->quantity_per_user = 1; $discount->date_from = date('Y-m-d H:i:s'); $discount->date_to = date('Y-m-d H:i:s', time() + 31536000); // + 1 year $name = Tools::passwdGen(8); if(Discount::discountExists(Configuration::get('INVITE_DISCOUNT_PREFIX').$name)) { // It should not happen, but who knows... $name = Tools::passwdGen(8); } $discount->name = Configuration::get('INVITE_DISCOUNT_PREFIX').$name; $discount->description = Configuration::getInt('INVITE_DISCOUNT_DESCRIPTION'); $discount->id_currency = 1; $discount->value = $credit; $discount->add(); $cart->addDiscount($discount->id); } Tools::redirectLink(Link::getPageLink('order.php', TRUE));