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:  * Rule report resource model with aggregation by created at
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_SalesRule
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_SalesRule_Model_Resource_Report_Rule_Createdat extends Mage_Reports_Model_Resource_Report_Abstract
 36: {
 37:     /**
 38:      * Resource Report Rule constructor
 39:      *
 40:      */
 41:     protected function _construct()
 42:     {
 43:         $this->_init('salesrule/coupon_aggregated', 'id');
 44:     }
 45: 
 46:     /**
 47:      * Aggregate Coupons data by order created at
 48:      *
 49:      * @param mixed $from
 50:      * @param mixed $to
 51:      * @return Mage_SalesRule_Model_Resource_Report_Rule_Createdat
 52:      */
 53:     public function aggregate($from = null, $to = null)
 54:     {
 55:         return $this->_aggregateByOrder('created_at', $from, $to);
 56:     }
 57: 
 58:     /**
 59:      * Aggregate coupons reports by orders
 60:      *
 61:      * @throws Exception
 62:      * @param string $aggregationField
 63:      * @param mixed $from
 64:      * @param mixed $to
 65:      * @return Mage_SalesRule_Model_Resource_Report_Rule_Createdat
 66:      */
 67:     protected function _aggregateByOrder($aggregationField, $from, $to)
 68:     {
 69:         $from = $this->_dateToUtc($from);
 70:         $to   = $this->_dateToUtc($to);
 71: 
 72:         $this->_checkDates($from, $to);
 73: 
 74:         $table = $this->getMainTable();
 75:         $sourceTable = $this->getTable('sales/order');
 76:         $adapter = $this->_getWriteAdapter();
 77:         $adapter->beginTransaction();
 78: 
 79:         try {
 80:             if ($from !== null || $to !== null) {
 81:                 $subSelect = $this->_getTableDateRangeSelect($sourceTable, 'created_at', 'updated_at', $from, $to);
 82:             } else {
 83:                 $subSelect = null;
 84:             }
 85: 
 86:             $this->_clearTableByDateRange($table, $from, $to, $subSelect);
 87: 
 88:             // convert dates from UTC to current admin timezone
 89:             $periodExpr = $adapter->getDatePartSql(
 90:                 $this->getStoreTZOffsetQuery($sourceTable, $aggregationField, $from, $to)
 91:             );
 92: 
 93:             $columns = array(
 94:                 'period'                  => $periodExpr,
 95:                 'store_id'                => 'store_id',
 96:                 'order_status'            => 'status',
 97:                 'coupon_code'             => 'coupon_code',
 98:                 'rule_name'               => 'coupon_rule_name',
 99:                 'coupon_uses'             => 'COUNT(entity_id)',
100: 
101:                 'subtotal_amount'         =>
102:                     $adapter->getIfNullSql('SUM((base_subtotal - ' .
103:                         $adapter->getIfNullSql('base_subtotal_canceled', 0).') * base_to_global_rate)', 0),
104: 
105:                 'discount_amount'         =>
106:                     $adapter->getIfNullSql('SUM((ABS(base_discount_amount) - ' .
107:                         $adapter->getIfNullSql('base_discount_canceled', 0).') * base_to_global_rate)', 0),
108: 
109:                 'total_amount'            =>
110:                     $adapter->getIfNullSql('SUM((base_subtotal - ' .
111:                         $adapter->getIfNullSql('base_subtotal_canceled', 0) . ' - '.
112:                         $adapter->getIfNullSql('ABS(base_discount_amount) - ' .
113:                         $adapter->getIfNullSql('base_discount_canceled', 0), 0). ')
114:                         * base_to_global_rate)', 0),
115: 
116:                 'subtotal_amount_actual'  =>
117:                     $adapter->getIfNullSql('SUM((base_subtotal_invoiced - ' .
118:                         $adapter->getIfNullSql('base_subtotal_refunded', 0). ') * base_to_global_rate)', 0),
119: 
120:                 'discount_amount_actual'  =>
121:                     $adapter->getIfNullSql('SUM((base_discount_invoiced - ' .
122:                         $adapter->getIfNullSql('base_discount_refunded', 0) . ')
123:                         * base_to_global_rate)', 0),
124: 
125:                 'total_amount_actual'     =>
126:                     $adapter->getIfNullSql('SUM((base_subtotal_invoiced - ' .
127:                         $adapter->getIfNullSql('base_subtotal_refunded', 0) . ' - ' .
128:                         $adapter->getIfNullSql('base_discount_invoiced - ' .
129:                         $adapter->getIfNullSql('base_discount_refunded', 0), 0) .
130:                         ') * base_to_global_rate)', 0),
131:             );
132: 
133:             $select = $adapter->select();
134:             $select->from(array('source_table' => $sourceTable), $columns)
135:                  ->where('coupon_code IS NOT NULL');
136: 
137:             if ($subSelect !== null) {
138:                 $select->having($this->_makeConditionFromDateRangeSelect($subSelect, 'period'));
139:             }
140: 
141:             $select->group(array(
142:                 $periodExpr,
143:                 'store_id',
144:                 'status',
145:                 'coupon_code'
146:             ));
147: 
148:             $select->having('COUNT(entity_id) > 0');
149:             $select->insertFromSelect($table, array_keys($columns));
150: 
151:             $adapter->query($select->insertFromSelect($table, array_keys($columns)));
152: 
153:             $select->reset();
154: 
155:             $columns = array(
156:                 'period'                  => 'period',
157:                 'store_id'                => new Zend_Db_Expr('0'),
158:                 'order_status'            => 'order_status',
159:                 'coupon_code'             => 'coupon_code',
160:                 'rule_name'               => 'rule_name',
161:                 'coupon_uses'             => 'SUM(coupon_uses)',
162:                 'subtotal_amount'         => 'SUM(subtotal_amount)',
163:                 'discount_amount'         => 'SUM(discount_amount)',
164:                 'total_amount'            => 'SUM(total_amount)',
165:                 'subtotal_amount_actual'  => 'SUM(subtotal_amount_actual)',
166:                 'discount_amount_actual'  => 'SUM(discount_amount_actual)',
167:                 'total_amount_actual'     => 'SUM(total_amount_actual)',
168:             );
169: 
170:             $select
171:                 ->from($table, $columns)
172:                 ->where('store_id <> 0');
173: 
174:             if ($subSelect !== null) {
175:                 $select->where($this->_makeConditionFromDateRangeSelect($subSelect, 'period'));
176:             }
177: 
178:             $select->group(array(
179:                 'period',
180:                 'order_status',
181:                 'coupon_code'
182:             ));
183: 
184:             $adapter->query($select->insertFromSelect($table, array_keys($columns)));
185:             $adapter->commit();
186:         } catch (Exception $e) {
187:             $adapter->rollBack();
188:             throw $e;
189:         }
190: 
191:         return $this;
192:     }
193: }
194: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0