2

How can we validate coupon code on a custom form on wishlist page? Is there any way to check the validity of the coupon code with ajax functionality?

I have used the following code, but it always return valid message:

    $codeLength = strlen($couponCode); // $couponCode is the coupon code entered by the user.
    $isCodeLengthValid = $codeLength && $codeLength <= Mage_Checkout_Helper_Cart::COUPON_CODE_MAX_LENGTH;
    if (!Mage::getSingleton('checkout/cart')->getQuote()->getItemsCount()) {
       exit('No items in cart');

    }
    Mage::getModel('checkout/cart')->getQuote()->getShippingAddress()->setCollectShippingRates(true);
    Mage::getModel('checkout/cart')->getQuote()->setCouponCode($isCodeLengthValid ? $couponCode : '')
        ->collectTotals()
        ->save();
    if ($codeLength) {
        if ($isCodeLengthValid && $couponCode == Mage::getModel('checkout/cart')->getQuote()->getCouponCode()) {
            $msg = 'Coupon code applied';
        } else {
            $msg = 'Coupon code is not valid';
        }
    } else {
        $msg = 'Coupon code was canceled.';
    }

Simply, I have tried on cart items on ajax page. But it didn't work. I am a newbie in magento. Any help appreciated..

chithra
  • 756
  • 7
  • 12

0 Answers0