Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_SalesRule_Exception
  • Mage_SalesRule_Helper_Coupon
  • Mage_SalesRule_Helper_Data
  • Mage_SalesRule_Model_Coupon
  • Mage_SalesRule_Model_Coupon_Codegenerator
  • Mage_SalesRule_Model_Coupon_Massgenerator
  • Mage_SalesRule_Model_Mysql4_Coupon
  • Mage_SalesRule_Model_Mysql4_Coupon_Collection
  • Mage_SalesRule_Model_Mysql4_Coupon_Usage
  • Mage_SalesRule_Model_Mysql4_Report_Collection
  • Mage_SalesRule_Model_Mysql4_Report_Rule
  • Mage_SalesRule_Model_Mysql4_Report_Updatedat_Collection
  • Mage_SalesRule_Model_Mysql4_Rule
  • Mage_SalesRule_Model_Mysql4_Rule_Collection
  • Mage_SalesRule_Model_Mysql4_Rule_Customer
  • Mage_SalesRule_Model_Mysql4_Rule_Customer_Collection
  • Mage_SalesRule_Model_Mysql4_Rule_Product
  • Mage_SalesRule_Model_Mysql4_Rule_Product_Collection
  • Mage_SalesRule_Model_Observer
  • Mage_SalesRule_Model_Quote_Discount
  • Mage_SalesRule_Model_Quote_Freeshipping
  • Mage_SalesRule_Model_Quote_Nominal_Discount
  • Mage_SalesRule_Model_Resource_Coupon
  • Mage_SalesRule_Model_Resource_Coupon_Collection
  • Mage_SalesRule_Model_Resource_Coupon_Usage
  • Mage_SalesRule_Model_Resource_Report_Collection
  • Mage_SalesRule_Model_Resource_Report_Rule
  • Mage_SalesRule_Model_Resource_Report_Rule_Createdat
  • Mage_SalesRule_Model_Resource_Report_Rule_Updatedat
  • Mage_SalesRule_Model_Resource_Report_Updatedat_Collection
  • Mage_SalesRule_Model_Resource_Rule
  • Mage_SalesRule_Model_Resource_Rule_Collection
  • Mage_SalesRule_Model_Resource_Rule_Customer
  • Mage_SalesRule_Model_Resource_Rule_Customer_Collection
  • Mage_SalesRule_Model_Resource_Rule_Product
  • Mage_SalesRule_Model_Resource_Rule_Product_Collection
  • Mage_SalesRule_Model_Rule
  • Mage_SalesRule_Model_Rule_Action_Collection
  • Mage_SalesRule_Model_Rule_Action_Product
  • Mage_SalesRule_Model_Rule_Condition_Address
  • Mage_SalesRule_Model_Rule_Condition_Combine
  • Mage_SalesRule_Model_Rule_Condition_Product
  • Mage_SalesRule_Model_Rule_Condition_Product_Combine
  • Mage_SalesRule_Model_Rule_Condition_Product_Found
  • Mage_SalesRule_Model_Rule_Condition_Product_Subselect
  • Mage_SalesRule_Model_Rule_Customer
  • Mage_SalesRule_Model_Rule_Product
  • Mage_SalesRule_Model_System_Config_Source_Coupon_Format
  • Mage_SalesRule_Model_Validator

Interfaces

  • Mage_SalesRule_Model_Coupon_CodegeneratorInterface
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_SalesRule
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: /**
 29:  * Sales Rules resource collection model
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_SalesRule
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_SalesRule_Model_Resource_Rule_Collection extends Mage_Rule_Model_Resource_Rule_Collection_Abstract
 36: {
 37:     /**
 38:      * Store associated with rule entities information map
 39:      *
 40:      * @var array
 41:      */
 42:     protected $_associatedEntitiesMap = array(
 43:         'website' => array(
 44:             'associations_table' => 'salesrule/website',
 45:             'rule_id_field'      => 'rule_id',
 46:             'entity_id_field'    => 'website_id'
 47:         ),
 48:         'customer_group' => array(
 49:             'associations_table' => 'salesrule/customer_group',
 50:             'rule_id_field'      => 'rule_id',
 51:             'entity_id_field'    => 'customer_group_id'
 52:         )
 53:     );
 54: 
 55:     /**
 56:      * Set resource model and determine field mapping
 57:      */
 58:     protected function _construct()
 59:     {
 60:         $this->_init('salesrule/rule');
 61:         $this->_map['fields']['rule_id'] = 'main_table.rule_id';
 62:     }
 63: 
 64:     /**
 65:      * Filter collection by specified website, customer group, coupon code, date.
 66:      * Filter collection to use only active rules.
 67:      * Involved sorting by sort_order column.
 68:      *
 69:      * @param int $websiteId
 70:      * @param int $customerGroupId
 71:      * @param string $couponCode
 72:      * @param string|null $now
 73:      * @use $this->addWebsiteGroupDateFilter()
 74:      *
 75:      * @return Mage_SalesRule_Model_Resource_Rule_Collection
 76:      */
 77:     public function setValidationFilter($websiteId, $customerGroupId, $couponCode = '', $now = null)
 78:     {
 79:         if (!$this->getFlag('validation_filter')) {
 80: 
 81:             /* We need to overwrite joinLeft if coupon is applied */
 82:             $this->getSelect()->reset();
 83:             parent::_initSelect();
 84: 
 85:             $this->addWebsiteGroupDateFilter($websiteId, $customerGroupId, $now);
 86:             $select = $this->getSelect();
 87: 
 88:             if (strlen($couponCode)) {
 89:                 $select->joinLeft(
 90:                     array('rule_coupons' => $this->getTable('salesrule/coupon')),
 91:                     'main_table.rule_id = rule_coupons.rule_id ',
 92:                     array('code')
 93:                 );
 94:             $select->where('(main_table.coupon_type = ? ', Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON)
 95:                 ->orWhere('(main_table.coupon_type = ? AND rule_coupons.type = 0',
 96:                     Mage_SalesRule_Model_Rule::COUPON_TYPE_AUTO)
 97:                 ->orWhere('main_table.coupon_type = ? AND main_table.use_auto_generation = 1 ' .
 98:                     'AND rule_coupons.type = 1', Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC)
 99:                 ->orWhere('main_table.coupon_type = ? AND main_table.use_auto_generation = 0 ' .
100:                     'AND rule_coupons.type = 0)', Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC)
101:                 ->where('rule_coupons.code = ?)', $couponCode);
102:             } else {
103:                 $this->addFieldToFilter('main_table.coupon_type', Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON);
104:             }
105:             $this->setOrder('sort_order', self::SORT_ORDER_ASC);
106:             $this->setFlag('validation_filter', true);
107:         }
108: 
109:         return $this;
110:     }
111: 
112:     /**
113:      * Filter collection by website(s), customer group(s) and date.
114:      * Filter collection to only active rules.
115:      * Sorting is not involved
116:      *
117:      * @param int $websiteId
118:      * @param int $customerGroupId
119:      * @param string|null $now
120:      * @use $this->addWebsiteFilter()
121:      *
122:      * @return Mage_SalesRule_Model_Mysql4_Rule_Collection
123:      */
124:     public function addWebsiteGroupDateFilter($websiteId, $customerGroupId, $now = null)
125:     {
126:         if (!$this->getFlag('website_group_date_filter')) {
127:             if (is_null($now)) {
128:                 $now = Mage::getModel('core/date')->date('Y-m-d');
129:             }
130: 
131:             $this->addWebsiteFilter($websiteId);
132: 
133:             $entityInfo = $this->_getAssociatedEntityInfo('customer_group');
134:             $connection = $this->getConnection();
135:             $this->getSelect()
136:                 ->joinInner(
137:                     array('customer_group_ids' => $this->getTable($entityInfo['associations_table'])),
138:                     $connection->quoteInto(
139:                         'main_table.' . $entityInfo['rule_id_field']
140:                             . ' = customer_group_ids.' . $entityInfo['rule_id_field']
141:                             . ' AND customer_group_ids.' . $entityInfo['entity_id_field'] . ' = ?',
142:                         (int)$customerGroupId
143:                     ),
144:                     array()
145:                 )
146:                 ->where('from_date is null or from_date <= ?', $now)
147:                 ->where('to_date is null or to_date >= ?', $now);
148: 
149:             $this->addIsActiveFilter();
150: 
151:             $this->setFlag('website_group_date_filter', true);
152:         }
153: 
154:         return $this;
155:     }
156: 
157:     /**
158:      * Add primary coupon to collection
159:      *
160:      * @return Mage_SalesRule_Model_Resource_Rule_Collection
161:      */
162:     public function _initSelect()
163:     {
164:         parent::_initSelect();
165:         $this->getSelect()
166:             ->joinLeft(
167:                 array('rule_coupons' => $this->getTable('salesrule/coupon')),
168:                 'main_table.rule_id = rule_coupons.rule_id AND rule_coupons.is_primary = 1',
169:                 array('code')
170:             );
171:         return $this;
172:     }
173: 
174:     /**
175:      * Find product attribute in conditions or actions
176:      *
177:      * @param string $attributeCode
178:      *
179:      * @return Mage_SalesRule_Model_Resource_Rule_Collection
180:      */
181:     public function addAttributeInConditionFilter($attributeCode)
182:     {
183:         $match = sprintf('%%%s%%', substr(serialize(array('attribute' => $attributeCode)), 5, -1));
184:         $field = $this->_getMappedField('conditions_serialized');
185:         $cCond = $this->_getConditionSql($field, array('like' => $match));
186:         $field = $this->_getMappedField('actions_serialized');
187:         $aCond = $this->_getConditionSql($field, array('like' => $match));
188: 
189:         $this->getSelect()->where(sprintf('(%s OR %s)', $cCond, $aCond), null, Varien_Db_Select::TYPE_CONDITION);
190: 
191:         return $this;
192:     }
193: 
194:     /**
195:      * Excludes price rules with generated specific coupon codes from collection
196:      *
197:      * @return Mage_SalesRule_Model_Resource_Rule_Collection
198:      */
199:     public function addAllowedSalesRulesFilter()
200:     {
201:         $this->addFieldToFilter(
202:             'main_table.use_auto_generation',
203:             array('neq' => 1)
204:         );
205: 
206:         return $this;
207:     }
208: }
209: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0