找到幾個過濾器和前面提到的解決方案上面的建立:
$attr_match = sprintf('%%%s%%', substr(serialize(array('attribute' => 'base_subtotal')), 5, -1));
$type_match = sprintf('%%%s%%', substr(serialize(array('type' => 'salesrule/rule_condition_address')), 5, -1));
$opr_grt_match = sprintf('%%%s%%', substr(serialize(array('operator' => '>')), 5, -1));
$opr_grteq_match = sprintf('%%%s%%', substr(serialize(array('operator' => '>=')), 5, -1));
$collection = Mage::getResourceModel('salesrule/rule_collection')
->addWebsiteGroupDateFilter(Mage::app()->getWebsite()->getId(), $group_id)
->addFieldToFilter('main_table.coupon_type', Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON)
->addFieldToFilter('main_table.conditions_serialized', array(
'like' => $attr_match,
))
->addFieldToFilter('main_table.conditions_serialized', array(
'like' => $type_match,
))
->addFieldToFilter('main_table.conditions_serialized', array(array(
'like' => $opr_grt_match
),array(
'like' => $opr_grteq_match
)))
;
$quote = Mage::getSingleton('checkout/session')->getQuote();
$applied_rules = $quote->getAppliedRuleIds();
if($applied_rules) {
$collection->addFieldToFilter('main_table.rule_id',array(
'nin' => explode(",", $applied_rules),
));
}
$rules = $collection->setOrder('main_table.sort_order', Varien_Data_Collection::SORT_ORDER_ASC)->load();
期待的意見,湊合吧。
在我的博客上添加了一篇文章,提供了更具描述性的解決方案: Magento – Closest Promo Rule