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.