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 report coupons collection
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_SalesRule
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_SalesRule_Model_Resource_Report_Collection extends Mage_Sales_Model_Resource_Report_Collection_Abstract
 36: {
 37:     /**
 38:      * Period format for report (day, month, year)
 39:      *
 40:      * @var string
 41:      */
 42:     protected $_periodFormat;
 43: 
 44:     /**
 45:      * Aggregated Data Table
 46:      *
 47:      * @var string
 48:      */
 49:     protected $_aggregationTable = 'salesrule/coupon_aggregated';
 50: 
 51:     /**
 52:      * array of columns that should be aggregated
 53:      *
 54:      * @var array
 55:      */
 56:     protected $_selectedColumns    = array();
 57: 
 58:     /**
 59:      * array where rules ids stored
 60:      *
 61:      * @var array
 62:      */
 63:     protected $_rulesIdsFilter;
 64: 
 65:     /**
 66:      * Initialize custom resource model
 67:      *
 68:      */
 69:     public function __construct()
 70:     {
 71:         parent::_construct();
 72:         $this->setModel('adminhtml/report_item');
 73:         $this->_resource = Mage::getResourceModel('sales/report')->init($this->_aggregationTable);
 74:         $this->setConnection($this->getResource()->getReadConnection());
 75:     }
 76: 
 77:     /**
 78:      * collect columns for collection
 79:      *
 80:      * @return unknown
 81:      */
 82:     protected function _getSelectedColumns()
 83:     {
 84:         $adapter = $this->getConnection();
 85:         if ('month' == $this->_period) {
 86:             $this->_periodFormat = $adapter->getDateFormatSql('period', '%Y-%m');
 87:         } elseif ('year' == $this->_period) {
 88:             $this->_periodFormat =
 89:                 $adapter->getDateExtractSql('period', Varien_Db_Adapter_Interface::INTERVAL_YEAR);
 90:         } else {
 91:             $this->_periodFormat = $adapter->getDateFormatSql('period', '%Y-%m-%d');
 92:         }
 93: 
 94:         if (!$this->isTotals() && !$this->isSubTotals()) {
 95:             $this->_selectedColumns = array(
 96:                 'period'                  => $this->_periodFormat,
 97:                 'coupon_code',
 98:                 'rule_name',
 99:                 'coupon_uses'             => 'SUM(coupon_uses)',
100:                 'subtotal_amount'         => 'SUM(subtotal_amount)',
101:                 'discount_amount'         => 'SUM(discount_amount)',
102:                 'total_amount'            => 'SUM(total_amount)',
103:                 'subtotal_amount_actual'  => 'SUM(subtotal_amount_actual)',
104:                 'discount_amount_actual'  => 'SUM(discount_amount_actual)',
105:                 'total_amount_actual'     => 'SUM(total_amount_actual)',
106:             );
107:         }
108: 
109:         if ($this->isTotals()) {
110:             $this->_selectedColumns = $this->getAggregatedColumns();
111:         }
112: 
113:         if ($this->isSubTotals()) {
114:             $this->_selectedColumns =
115:                 $this->getAggregatedColumns() +
116:                     array('period' => $this->_periodFormat);
117:         }
118: 
119:         return $this->_selectedColumns;
120:     }
121: 
122:     /**
123:      * Add selected data
124:      *
125:      * @return Mage_SalesRule_Model_Resource_Report_Collection
126:      */
127:     protected function _initSelect()
128:     {
129:         $this->getSelect()->from($this->getResource()->getMainTable(), $this->_getSelectedColumns());
130:         if ($this->isSubTotals()) {
131:             $this->getSelect()->group($this->_periodFormat);
132:         } else if (!$this->isTotals()) {
133:             $this->getSelect()->group(array(
134:                 $this->_periodFormat,
135:                 'coupon_code'
136:             ));
137:         }
138: 
139:         return $this;
140:     }
141: 
142:     /**
143:      * Add filtering by rules ids
144:      *
145:      * @param array $rulesList
146:      * @return Mage_SalesRule_Model_Resource_Report_Collection
147:      */
148:     public function addRuleFilter($rulesList)
149:     {
150:         $this->_rulesIdsFilter = $rulesList;
151:         return $this;
152:     }
153: 
154:     /**
155:      * Apply filtering by rules ids
156:      *
157:      * @return Mage_SalesRule_Model_Resource_Report_Collection
158:      */
159:     protected function _applyRulesFilter()
160:     {
161:         if (empty($this->_rulesIdsFilter) || !is_array($this->_rulesIdsFilter)) {
162:             return $this;
163:         }
164: 
165:         $rulesList = Mage::getResourceModel('salesrule/report_rule')->getUniqRulesNamesList();
166: 
167:         $rulesFilterSqlParts = array();
168: 
169:         foreach ($this->_rulesIdsFilter as $ruleId) {
170:             if (!isset($rulesList[$ruleId])) {
171:                 continue;
172:             }
173:             $ruleName = $rulesList[$ruleId];
174:             $rulesFilterSqlParts[] = $this->getConnection()->quoteInto('rule_name = ?', $ruleName);
175:         }
176: 
177:         if (!empty($rulesFilterSqlParts)) {
178:             $this->getSelect()->where(implode($rulesFilterSqlParts, ' OR '));
179:         }
180:     }
181: 
182:     /**
183:      * Apply collection custom filter
184:      *
185:      * @return Mage_Sales_Model_Resource_Report_Collection_Abstract
186:      */
187:     protected function _applyCustomFilter()
188:     {
189:         $this->_applyRulesFilter();
190:         return parent::_applyCustomFilter();
191:     }
192: }
193: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0