/** * Set validation filter on rule collection * @param Mage_SalesRule_Model_Resource_Rule_Collection * @param string */ protected function addCouponFilter(Mage_SalesRule_Model_Resource_Rule_Collection $ruleCollection, $couponCode) { // multiple coupon compatibility if ($couponCode && !is_array($couponCode)) { $couponCode = explode(',', $couponCode); } $select = $ruleCollection->getSelect(); $select->reset(); $ruleTable = $ruleCollection->getTable('salesrule/rule'); $couponTable = $ruleCollection->getTable('salesrule/coupon'); $select->from(['main_table' => $ruleTable]); if ($couponCode) { $select->joinLeft(['c' => $couponTable], 'main_table.rule_id = c.rule_id ', ['code']); $select->where($select->getAdapter()->quoteInto(' main_table.coupon_type = ?', 1) . $select->getAdapter()->quoteInto(' OR c.code IN(?)', $couponCode)); $select->group('main_table.rule_id'); } else { $select->where('main_table.coupon_type = ?', 1); } $select->order('sort_order'); }