Jump to content

Recommended Posts

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);
            }
        }
    }

Edited by Likhama Hudda (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...