Custom coupon code apply for mobile web services API. I have create after very hard work. so help to you
if (!empty($data['id_shop']) && !empty($data['id_lang']) & !empty($data['id_cart']) & !empty($data['coupon_code'])) {
$context = Context::getContext()->cart = new Cart($data['id_cart']);
$context = Context::getContext();
$cart = new Cart($data['id_cart']);
if (($cartRule = new CartRule(CartRule::getIdByCode($data['coupon_code'])))) {
if ($error = $cartRule->checkValidity($context, false, true)) {
$success_array = array('success' => '0', 'text' => $error);
echo $senddata = json_encode($success_array);
} else {
$cart->addCartRule($cartRule->id);
$cartProducts = $cart->getCartRules();
$success_array = array('success' => '1', 'id_cart_rule' => $cartProducts[0]['id_cart_rule'], 'discount_price' => $cartProducts[0]['value_real']);
echo $senddata = json_encode($success_array);
}
}
}
Edit History
if (!empty($data['id_shop']) && !empty($data['id_lang']) & !empty($data['id_cart']) & !empty($data['coupon_code'])) {
$context = Context::getContext()->cart = new Cart($data['id_cart']);
$context = Context::getContext();
$cart = new Cart($data['id_cart']);
if (($cartRule = new CartRule(CartRule::getIdByCode($data['coupon_code'])))) {
if ($error = $cartRule->checkValidity($context, false, true)) {
$success_array = array('success' => '0', 'text' => $error);
echo $senddata = json_encode($success_array);
} else {
$cart->addCartRule($cartRule->id);
$cartProducts = $cart->getCartRules();
$success_array = array('success' => '1', 'id_cart_rule' => $cartProducts[0]['id_cart_rule'], 'discount_price' => $cartProducts[0]['value_real']);
echo $senddata = json_encode($success_array);
}
}
}