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;
 }
Example #2
0
 public function addWebsiteGroupDateFilter($websiteId, $customerGroupId, $now = null)
 {
     if (method_exists('Mage', 'getEdition')) {
         // available from CE 1.7
         return parent::addWebsiteGroupDateFilter($websiteId, $customerGroupId, $now);
     }
     $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 (is_null($now)) {
         $now = Mage::getModel('core/date')->date('Y-m-d');
     }
     $this->getSelect()->where('from_date is null or from_date<=?', $now);
     $this->getSelect()->where('to_date is null or to_date>=?', $now);
     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;
 }
Example #4
0
 public function setValidationFilter($websiteId, $customerGroupId, $couponCode = '', $now = null)
 {
     if (!$this->getFlag('validation_filter')) {
         /* We need to overwrite joinLeft if coupon is applied */
         $this->getSelect()->reset();
         parent::_initSelect();
         $now = Mage::getModel('core/date')->date(MW_FollowUpEmail_Model_Mysql4_Emailqueue::MYSQL_DATETIME_FORMAT);
         $this->addFieldToFilter('website_ids', array('finset' => (int) $websiteId))->addFieldToFilter('is_active', 1);
         $select = $this->getSelect();
         if (strlen($couponCode)) {
             $select->joinLeft(array('fue_coupons' => $this->getTable('followupemail/coupons')), 'main_table.rule_id = fue_coupons.sale_rule_id ', array('code'));
             $select->where('(main_table.coupon_type != ? ', Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON)->where('fue_coupons.code = ?)', $couponCode)->where('fue_coupons.coupon_status	 = ?', MW_FollowUpEmail_Model_System_Config_Statuscoupon::COUPON_STATUS_SENT)->where('fue_coupons.expiration_date is null or fue_coupons.expiration_date >= ?', $now);
         } else {
             $this->addFieldToFilter('main_table.coupon_type', Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON);
         }
         $this->setOrder('sort_order', self::SORT_ORDER_ASC);
         $this->setFlag('validation_filter', true);
     }
     return $this;
 }