2013-06-24 110 views
0

我使用的是magento 1.7.0.2。出於某種原因,我一直收到「優惠券代碼」XXX「無效」。我調查了一下,發現了什麼問題,但我不知道如何解決。magento優惠券代碼無效

文件中

:\應用\代碼\核心\法師\結帳\控制器\ cartController.php

$couponCode = (string) $this->getRequest()->getParam('coupon_code'); 
if ($this->getRequest()->getParam('remove') == 1) { 
    $couponCode = ''; 
} 
$oldCouponCode = $this->_getQuote()->getCouponCode(); 

if (!strlen($couponCode) && !strlen($oldCouponCode)) { 
    $this->_goBack(); 
    return; 
} 

try { 
    $this->_getQuote()->getShippingAddress()->setCollectShippingRates(true); 
    $this->_getQuote()->setCouponCode(strlen($couponCode) ? $couponCode : '') 
    ->collectTotals() 
    ->save(); 

    if ($couponCode) { 
     if ($couponCode == $this->_getQuote()->getCouponCode()) { 
      $this->_getSession()->addSuccess(
       $this->__('Coupon code "%s" was applied.',Mage::helper('core')->htmlEscape($couponCode)) 
       ); 
     } 
     else { 
      $this->_getSession()->addError(
      $this->__('Coupon code "%s" is not valid.', Mage::helper('core')->htmlEscape($couponCode)) 
       ); 
     } 
    } else { 
     $this->_getSession()->addSuccess($this->__('Coupon code was canceled.')); 
    } 

的問題是,$this->_getQuote()->getCouponCode()來自空。它以「'的形式出現。

編輯:

進一步的調查使我的一個更具體的問題..

->collectTotals()->save();,這樣做的所有的爛攤子.. 出於某種原因,如果我刪除它運行完美,但在優惠券不適用。

這怎麼解決?

+0

檢查$ couponCode的值。 'var_dump($ couponCode);' –

+0

$ couponCode是我在表格中輸入的數字... ,因爲您可以看到它已被打印在錯誤中。 – user2312281

+0

這可能會導致你的'$ couponCode'變成空白:'strlen($ couponCode)? $ couponCode:''' –

回答

2

這是Magento從該版本的一個常見的錯誤,雖然他們告訴這個錯誤是固定的,但它不是。同樣在Mangeto的bug追蹤器中,它仍然表明這個問題到目前爲止一直是「進行中」。在這裏我從https://github.com/husseycoding/cartrulefix發現:

購物車價格規則修正 當建立在Magento CE 1.9的購物車價格規則,並使用「停止進一步的規則處理」,邏輯已經從1.8 CE改變,現在是有缺陷。這個有缺陷的邏輯現在停止了規則正確應用於購物車中的多個產品,並且不考慮在項目級別停止進一步規則處理。這意味着你得到應用爲每個bug報告在這裏不正確的折扣金額:

http://www.magentocommerce.com/bug-tracking/issue/index/id/67

這個擴展修正缺陷的邏輯和原因「停止進一步的規則處理」項目級別允許的規則是要考慮處理購物車中的所有物品。

+0

您可能還想提及您是該擴展程序的作者,否則這看起來像垃圾郵件。 – andrewsi