00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 class Mage_SalesRule_Model_Mysql4_Rule_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
00029 {
00030 protected function _construct()
00031 {
00032 parent::_construct();
00033 $this->_init('salesrule/rule');
00034 }
00035
00036 public function setValidationFilter($websiteId, $customerGroupId, $couponCode='', $now=null)
00037 {
00038 if (is_null($now)) {
00039 $now = Mage::getModel('core/date')->date('Y-m-d');
00040 }
00041
00042 $this->addBindParam('coupon_code', $couponCode);
00043 $this->getSelect()->where('is_active=1');
00044 $this->getSelect()->where('find_in_set(?, website_ids)', (int)$websiteId);
00045 $this->getSelect()->where('find_in_set(?, customer_group_ids)', (int)$customerGroupId);
00046 if (empty($couponCode)) {
00047 $this->getSelect()->where("coupon_code is null or coupon_code=''");
00048 }
00049 else {
00050 $this->getSelect()->where("coupon_code is null or coupon_code='' or coupon_code=:coupon_code");
00051 }
00052 $this->getSelect()->where('from_date is null or from_date<=?', $now);
00053 $this->getSelect()->where('to_date is null or to_date>=?', $now);
00054 $this->getSelect()->order('sort_order');
00055
00056 return $this;
00057 }
00058
00059
00060
00061
00062
00063
00064
00065 public function addWebsiteFilter($websiteIds)
00066 {
00067 if (!is_array($websiteIds)) {
00068 $websiteIds = array($websiteIds);
00069 }
00070 $parts = array();
00071 foreach ($websiteIds as $websiteId) {
00072 $parts[] = $this->getConnection()->quoteInto('FIND_IN_SET(?, main_table.website_ids)', $websiteId);
00073 }
00074 if ($parts) {
00075 $this->getSelect()->where(new Zend_Db_Expr(implode(' OR ', $parts)));
00076 }
00077 return $this;
00078 }
00079 }