【问题标题】:Find closest promo rule查找最接近的促销规则
【发布时间】:2013-05-27 17:59:58
【问题描述】:

我们提供超过 Magento CE 1.7 的特定订单限制的免费产品。

为了鼓励客户进行更多购买,我们必须在购物车页面上显示通知/警报,并在购物车上显示最接近的促销。

我找到了一个类似的帖子,但这似乎是一个详尽的过程,因为它需要遍历所有购物车促销规则才能找到合适的规则: Read promotion rule condition - Magento

期待知道是否有任何过滤器可用于简化流程。

【问题讨论】:

    标签: magento magento-1.7 promotions


    【解决方案1】:

    找到几个过滤器,并在前面提到的解决方案之上构建:

    $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();
    

    期待cmets,即兴发挥吧。

    在我的博客上添加了一篇文章,提供了更具描述性的解决方案: Magento – Closest Promo Rule

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-18
      • 1970-01-01
      • 2019-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多