我使用的是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();
,这样做的所有的烂摊子.. 出于某种原因,如果我删除它运行完美,但在优惠券不适用。
这怎么解决?
检查$ couponCode的值。 'var_dump($ couponCode);' –
$ couponCode是我在表格中输入的数字... ,因为您可以看到它已被打印在错误中。 – user2312281
这可能会导致你的'$ couponCode'变成空白:'strlen($ couponCode)? $ couponCode:''' –