我們正在使用Magento主要用於交易,並已完全通過自定義應用程序重寫前端。我無法在報價對象上應用優惠券代碼(購物車價格規則)。優惠券代碼似乎被拒絕 - setCouponCode不返回任何錯誤,但getCouponCode返回空字符串。Magento:setCouponCode似乎沒有在報價模式上應用優惠券
我已通過管理後臺進行交易驗證了優惠券代碼的有效性。這是下面的代碼片段。
有人可以幫我獲得報價模型對象接受並應用優惠券代碼嗎?
功能add_coupon($ shoppingCartId,$ COUPONCODE){
try {
$quoteObj = Mage::getModel('sales/quote')->load($shoppingCartId);
$quoteObj->getShippingAddress()->setCollectShippingRates(true);
$quoteObj->getShippingAddress()->setCouponCode($coupon)
->setTotalsCollectedFlag(true)
->collectTotals()
->save();
} catch (Exception $e) {
return array("status"=>"failed", "message"=>"Error applying coupon.");
}
if ($coupon) {
if (!$coupon == $quoteObj->getCouponCode()) {
return array("status"=>"failed", "message"=>"Coupon code is not valid.");
}
}
return array("status"=>"success");
}
這項工作如何,優惠券適用於付款步驟,我們是否應該在第一次創建購物車時申請空白優惠券? – 2016-05-19 08:35:19