Question

We are offering free products on certain order limits, over Magento CE 1.7.

In order to encourage customer to go for more purchase, we have to show notices/alerts on cart's page with the closest promo that could be applied on the cart.

I have found a similar post, but this seems to be exhaustive process, as it would require to iterate through all the shopping cart promo rules to find the appropriate rule: Read promotion rule condition - Magento

Looking forward to know if there is any filter available to simplify the process.

Was it helpful?

Solution

Found few filters, and build up above the previously mentioned solution:

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

Looking forward to comments, to improvise it.

Added an article on my blog, with a more descriptive solution: Magento – Closest Promo Rule

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top