我一直在看salesrule_coupon
表,我发现如果规则本身是"自动"类型,我可以将许多优惠券代码映射到单个规则.这非常方便,因为我的客户需要我们定期将代码与数据源同步.
因此,在加载这些数千个代码(使用自定义模块和直接SQL调用)时,它们加载得很好,我可以测试并验证它们中的许多代码是否正常工作.
然而,在这些代码列表中,我们停止工作.前30个左右可以正常工作,但此后,Magento说代码无效.
我还在调试这个,如果我发现任何东西,我会发布更新......但是我已经尝试过并且经历了两个单独的价格规则.第31条代码中有一条规则,第39条则是第二条规则.
真正奇怪的是,如果我将这些代码更改为指向不同的规则(少于30个代码的规则),则会识别并接受它们.没有其他改变,我可以确定.
关于如何在这里进行的任何想法?有没有人尝过这个?这是一个有趣的.
当我为我的一个客户创建类似的东西时,我修复了同样的问题.检索有效优惠券Magento Core Sales Rule模块的问题来源FIND_IN_SET()
与GROUP_CONCAT()
MySQL函数一起使用,而不是为连接表添加附加条件.因此,FIND_IN_SET
只需将组连接中使用的优惠券代码的数量截断为31项(32位掩码).另外我注意到他们正在使用HAVING而不是where,所以它会影响性能.
所以你需要做的是以下几点:
Mage_SalesRule_Model_Mysql4_Rule_Collection
(salesrule/rule_collection
)然后在重写核心模型的资源模型中,您需要重新定义此方法setValidationFilter($websiteId, $customerGroupId, $couponCode='', $now=null)
,该方法在前端应用销售规则的限制.这里是我使用的方法体:
/**
* Fix for validation with auto-coupons
* @todo remove this fix, after the bug in core will be fixed
*
* (non-PHPdoc)
* @see Mage_SalesRule_Model_Mysql4_Rule_Collection::setValidationFilter()
*/
public function setValidationFilter($websiteId, $customerGroupId, $couponCode='', $now=null)
{
if (is_null($now)) {
$now = Mage::getModel('core/date')->date('Y-m-d');
}
$this->getSelect()->where('is_active=1');
$this->getSelect()->where('find_in_set(?, website_ids)', (int)$websiteId);
$this->getSelect()->where('find_in_set(?, customer_group_ids)', (int)$customerGroupId);
if ($couponCode) {
$couponCondition = $this->getConnection()->quoteInto(
'extra_coupon.code = ?',
$couponCode
);
$this->getSelect()->joinLeft(
array('extra_coupon' => $this->getTable('salesrule/coupon')),
'extra_coupon.rule_id = main_table.rule_id AND extra_coupon.is_primary IS NULL AND ' . $couponCondition,
array()
);
$this->getSelect()->where('('
. $this->getSelect()->getAdapter()->quoteInto(' main_table.coupon_type <> ?', Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC)
. $this->getSelect()->getAdapter()->quoteInto(' OR primary_coupon.code = ?', $couponCode) . ')'
);
$this->getSelect()->where('('
. $this->getSelect()->getAdapter()->quoteInto(' main_table.coupon_type <> ?', Mage_SalesRule_Model_Rule::COUPON_TYPE_AUTO)
. $this->getSelect()->getAdapter()->quoteInto(' OR extra_coupon.code IS NOT NULL') . ')'
);
} else {
$this->getSelect()->where('main_table.coupon_type = ?', Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON);
}
$this->getSelect()->where('from_date is null or from_date<=?', $now);
$this->getSelect()->where('to_date is null or to_date>=?', $now);
$this->getSelect()->order('sort_order');
return $this;
}
Run Code Online (Sandbox Code Playgroud)测试修复并享受Magento开发:)