【发布时间】:2013-06-24 17:08:40
【问题描述】:
我正在使用 magento 1.7.0.2。出于某种原因,我不断收到“优惠券代码“XXX”无效。”我调查了一下,发现问题出在哪里,但我不知道如何解决。
在文件中:\app\code\core\mage\checkout\controllers\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 是我在表单中输入的数字...您可以看到它已经在错误中打印。
-
这可能会导致您的
$couponCode变为空白:strlen($couponCode) ? $couponCode : '' -
所以你需要做的是在这个检查之前弄清楚为什么
$couponCode是空的......这可能来自:$couponCode = (string) $this->getRequest()->getParam('coupon_code'); if ($this->getRequest()->getParam('remove') == 1) { $couponCode = ''; } -
我一直在调查,似乎是数据库错误。在表
salesrule中有两列称为website_id和customers_group_ids,其中Array所以我将其更改为他们正确的ID。现在我每次尝试创建一个新的购物车规则时都会遇到一个新问题,输入到它们的值是array我不知道这是在哪个文件中处理并以这种方式插入到数据库中。
标签: php magento magento-1.7