public function setValidationFilter($websiteId, $customerGroupId, $couponCode = '', $now = null) { $isMagentoVersion = Mage::helper('followupemail')->checkVersion('1.6'); if (!$couponCode || !Mage::helper('followupemail/coupon')->isFUECoupon($couponCode) || $isMagentoVersion) { return parent::setValidationFilter($websiteId, $customerGroupId, $couponCode, $now); } 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) { $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 extra_coupon.code = ' . $this->getConnection()->quote($couponCode), array()); $this->getSelect()->group('main_table.rule_id'); $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)); } 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'); $this->getSelect()->where('extra_coupon.code = ?', $couponCode); return $this; }
public function setValidationFilter($websiteId, $customerGroupId, $couponCode = '', $now = null) { if (version_compare(Mage::getVersion(), '1.4.1.0') < 0) { return parent::setValidationFilter($websiteId, $customerGroupId, $couponCode, $now); } if ($this->getFlag('validation_filter')) { return $this; } if ($couponCode) { $couponCode = explode(',', $couponCode); } // multiple coupon compatibility $this->getSelect()->reset(); $this->getSelect()->from(array('main_table' => $this->getTable('salesrule/rule'))); $this->addWebsiteGroupDateFilter($websiteId, $customerGroupId, $now); if ($couponCode) { $this->getSelect()->joinLeft(array('c' => $this->getTable('salesrule/coupon')), 'main_table.rule_id = c.rule_id ', array('code')); // Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON is not defined $this->getSelect()->where($this->getSelect()->getAdapter()->quoteInto(' main_table.coupon_type = ?', 1) . $this->getSelect()->getAdapter()->quoteInto(' OR c.code IN(?)', $couponCode)); $this->getSelect()->group('main_table.rule_id'); } else { $this->getSelect()->where('main_table.coupon_type = ?', 1); } $this->getSelect()->order('sort_order'); $this->setFlag('validation_filter', true); return $this; }
public function setValidationFilter($websiteId, $customerGroupId, $couponCode = '', $now = null) { /* */ $iStoreId = Mage::app()->getStore()->getId(); $iSiteId = Mage::app()->getWebsite()->getId(); $performer = Aitoc_Aitsys_Abstract_Service::get()->platform()->getModule('Aitoc_Aitindividpromo')->getLicense()->getPerformer(); $ruler = $performer->getRuler(); if (!($ruler->checkRule('store', $iStoreId, 'store') || $ruler->checkRule('store', $iSiteId, 'website'))) { return parent::setValidationFilter($websiteId, $customerGroupId, $couponCode); } /* */ if (is_null($now)) { $now = Mage::getModel('core/date')->date('Y-m-d'); } $this->addBindParam('code', $couponCode); $this->getSelect()->where('is_active=1'); $this->getSelect()->where('find_in_set(?, website_ids)', (int) $websiteId); $iCustomerId = Mage::getSingleton('customer/session')->getCustomerId(); $oResource = Mage::getSingleton('core/resource'); $sTable = $oResource->getTableName('aitoc_salesrule_assign_cutomer'); if ($sTable) { if (!$iCustomerId) { $iCustomerId = 0; // fix for create order by admin if ($_SESSION and isset($_SESSION['adminhtml_quote']) and isset($_SESSION['adminhtml_quote']['customer_id']) and $_SESSION['adminhtml_quote']['customer_id']) { $iCustomerId = $_SESSION['adminhtml_quote']['customer_id']; } } $this->getSelect()->joinLeft(array('rc' => $sTable), 'main_table.rule_id = rc.entity_id AND rc.customer_id = ' . $iCustomerId); $sWhere = '(rc.entity_id IS NOT NULL) OR (find_in_set("' . (int) $customerGroupId . '", customer_group_ids))'; $this->getSelect()->where($sWhere); } if (empty($couponCode)) { $this->getSelect()->where("code is null or code=''"); } else { $this->getSelect()->where("code is null or code='' or code=:code"); } $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; }