plugins - PrestaShop 1.6 How to add a discount to order? -


i'm writing module prestashop 1.6. 1 of task of module give customer discount whole order in cart , display it. question method should use total value of products in cart , add single discount whole order?

check code create new cart rule:

$cart_rule = new cartrule(); $cart_rule->id_customer = $this->context->cart->id_customer; $cart_rule->name = array(     configuration::get('ps_lang_default') => $this->l('cartrule title') ); $cart_rule->date_from = date('y-m-d h:i:s', time()); $cart_rule->date_to = date('y-m-d h:i:s', time() + 24 * 3600); $cart_rule->quantity = 1; $cart_rule->quantity_per_user = 1; $cart_rule->minimum_amount_currency = $this->context->cart->id_currency; $cart_rule->reduction_currency = $this->context->cart->id_currency; $cart_rule->free_shipping = true; $cart_rule->reduction_amount = 50; #discount value $cart_rule->active = 1; $cart_rule->add();  // add cart rule cart , in order $values = array(     'tax_incl' => $cart_rule->getcontextualvalue(true),     'tax_excl' => $cart_rule->getcontextualvalue(false) ); $this->context->cart->addcartrule($cart_rule->id, $cart_rule->name[configuration::get('ps_lang_default')], $values); 

Comments