0
votes

I am writing a separate php file outsite Magento to support for our local application.

Apply coupon code part not working for me. But the same coupon works in Magento(userend) and Magento API call too.

I am trying with the same code what Magento have in API.

$quoteId = 10001;
$coupon = 'TESTCOUPON';
$storeId = 2;

$quote = Mage::getModel("sales/quote");
$quote->setStoreId($storeId);
$quote->load($quoteId);

if (!$quote->getItemsCount()) {
        echo ('quote_is_empty');
        exit;
}

$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->setCouponCode($coupon)
        ->collectTotals()
        ->save();

if (!$coupon == $quote->getCouponCode()) {
        echo ('coupon_code_is_not_valid');
        exit;
}
else{
        echo 'coupon applied';
        exit;
}

The above code through coupon_code_is_not_valid. If anyone have any idea for this let me know.

1
Do you want to get the coupon code applied when product was ordered?Mukesh
yes, after products are added to cart/quote.Sankar Subburaj
Your code is correct, what issue you are facing?Mukesh
when I run the code it through coupon_code_is_not_validSankar Subburaj
compare the stings in case insensitive modeMukesh

1 Answers

0
votes

Try following

if (strcasecmp($coupon,$quote->getCouponCode()) == 0 ){
    echo 'coupon applied';
     exit;
}