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_Reports_Block_Product_Abstract
  • Mage_Reports_Block_Product_Compared
  • Mage_Reports_Block_Product_Viewed
  • Mage_Reports_Block_Product_Widget_Compared
  • Mage_Reports_Block_Product_Widget_Viewed
  • Mage_Reports_Exception
  • Mage_Reports_Helper_Data
  • Mage_Reports_Model_Config
  • Mage_Reports_Model_Event
  • Mage_Reports_Model_Event_Observer
  • Mage_Reports_Model_Event_Type
  • Mage_Reports_Model_Flag
  • Mage_Reports_Model_Grouped_Collection
  • Mage_Reports_Model_Mysql4_Accounts_Collection
  • Mage_Reports_Model_Mysql4_Coupons_Collection
  • Mage_Reports_Model_Mysql4_Customer_Collection
  • Mage_Reports_Model_Mysql4_Customer_Orders_Collection
  • Mage_Reports_Model_Mysql4_Customer_Totals_Collection
  • Mage_Reports_Model_Mysql4_Entity_Summary_Collection_Abstract
  • Mage_Reports_Model_Mysql4_Event
  • Mage_Reports_Model_Mysql4_Event_Collection
  • Mage_Reports_Model_Mysql4_Event_Type
  • Mage_Reports_Model_Mysql4_Event_Type_Collection
  • Mage_Reports_Model_Mysql4_Invoiced_Collection
  • Mage_Reports_Model_Mysql4_Order_Collection
  • Mage_Reports_Model_Mysql4_Product_Collection
  • Mage_Reports_Model_Mysql4_Product_Downloads_Collection
  • Mage_Reports_Model_Mysql4_Product_Index_Abstract
  • Mage_Reports_Model_Mysql4_Product_Index_Collection_Abstract
  • Mage_Reports_Model_Mysql4_Product_Index_Compared
  • Mage_Reports_Model_Mysql4_Product_Index_Compared_Collection
  • Mage_Reports_Model_Mysql4_Product_Index_Viewed
  • Mage_Reports_Model_Mysql4_Product_Index_Viewed_Collection
  • Mage_Reports_Model_Mysql4_Product_Lowstock_Collection
  • Mage_Reports_Model_Mysql4_Product_Ordered_Collection
  • Mage_Reports_Model_Mysql4_Product_Sold_Collection
  • Mage_Reports_Model_Mysql4_Product_Viewed_Collection
  • Mage_Reports_Model_Mysql4_Quote_Collection
  • Mage_Reports_Model_Mysql4_Refunded_Collection
  • Mage_Reports_Model_Mysql4_Report_Abstract
  • Mage_Reports_Model_Mysql4_Report_Collection
  • Mage_Reports_Model_Mysql4_Review_Collection
  • Mage_Reports_Model_Mysql4_Review_Customer_Collection
  • Mage_Reports_Model_Mysql4_Review_Product_Collection
  • Mage_Reports_Model_Mysql4_Shipping_Collection
  • Mage_Reports_Model_Mysql4_Tag_Collection
  • Mage_Reports_Model_Mysql4_Tag_Customer_Collection
  • Mage_Reports_Model_Mysql4_Tag_Product_Collection
  • Mage_Reports_Model_Mysql4_Tax_Collection
  • Mage_Reports_Model_Mysql4_Wishlist_Collection
  • Mage_Reports_Model_Mysql4_Wishlist_Product_Collection
  • Mage_Reports_Model_Product_Index_Abstract
  • Mage_Reports_Model_Product_Index_Compared
  • Mage_Reports_Model_Product_Index_Viewed
  • Mage_Reports_Model_Report
  • Mage_Reports_Model_Resource_Accounts_Collection
  • Mage_Reports_Model_Resource_Coupons_Collection
  • Mage_Reports_Model_Resource_Customer_Collection
  • Mage_Reports_Model_Resource_Customer_Orders_Collection
  • Mage_Reports_Model_Resource_Customer_Totals_Collection
  • Mage_Reports_Model_Resource_Entity_Summary_Collection_Abstract
  • Mage_Reports_Model_Resource_Event
  • Mage_Reports_Model_Resource_Event_Collection
  • Mage_Reports_Model_Resource_Event_Type
  • Mage_Reports_Model_Resource_Event_Type_Collection
  • Mage_Reports_Model_Resource_Helper_Mysql4
  • Mage_Reports_Model_Resource_Invoiced_Collection
  • Mage_Reports_Model_Resource_Order_Collection
  • Mage_Reports_Model_Resource_Product_Collection
  • Mage_Reports_Model_Resource_Product_Downloads_Collection
  • Mage_Reports_Model_Resource_Product_Index_Abstract
  • Mage_Reports_Model_Resource_Product_Index_Collection_Abstract
  • Mage_Reports_Model_Resource_Product_Index_Compared
  • Mage_Reports_Model_Resource_Product_Index_Compared_Collection
  • Mage_Reports_Model_Resource_Product_Index_Viewed
  • Mage_Reports_Model_Resource_Product_Index_Viewed_Collection
  • Mage_Reports_Model_Resource_Product_Lowstock_Collection
  • Mage_Reports_Model_Resource_Product_Ordered_Collection
  • Mage_Reports_Model_Resource_Product_Sold_Collection
  • Mage_Reports_Model_Resource_Product_Viewed_Collection
  • Mage_Reports_Model_Resource_Quote_Collection
  • Mage_Reports_Model_Resource_Refunded_Collection
  • Mage_Reports_Model_Resource_Report_Abstract
  • Mage_Reports_Model_Resource_Report_Collection
  • Mage_Reports_Model_Resource_Report_Collection_Abstract
  • Mage_Reports_Model_Resource_Report_Product_Viewed
  • Mage_Reports_Model_Resource_Report_Product_Viewed_Collection
  • Mage_Reports_Model_Resource_Review_Collection
  • Mage_Reports_Model_Resource_Review_Customer_Collection
  • Mage_Reports_Model_Resource_Review_Product_Collection
  • Mage_Reports_Model_Resource_Shipping_Collection
  • Mage_Reports_Model_Resource_Shopcart_Product_Collection
  • Mage_Reports_Model_Resource_Tag_Collection
  • Mage_Reports_Model_Resource_Tag_Customer_Collection
  • Mage_Reports_Model_Resource_Tag_Product_Collection
  • Mage_Reports_Model_Resource_Tax_Collection
  • Mage_Reports_Model_Resource_Wishlist_Collection
  • Mage_Reports_Model_Resource_Wishlist_Product_Collection
  • Mage_Reports_Model_Session
  • Mage_Reports_Model_Test
  • Mage_Reports_Model_Totals

Interfaces

  • Mage_Reports_Model_Resource_Helper_Interface
  • 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_Reports
 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:  * Reports quote collection
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Reports
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Reports_Model_Resource_Quote_Collection extends Mage_Sales_Model_Resource_Quote_Collection
 36: {
 37: 
 38:     const SELECT_COUNT_SQL_TYPE_CART = 1;
 39: 
 40:     protected $_selectCountSqlType = 0;
 41: 
 42:     /**
 43:      * Join fields
 44:      *
 45:      * @var array
 46:      */
 47:     protected $_joinedFields     = array();
 48: 
 49:     /**
 50:      * Map
 51:      *
 52:      * @var array
 53:      */
 54:     protected $_map              = array('fields' => array('store_id' => 'main_table.store_id'));
 55: 
 56:     /**
 57:      * Set type for COUNT SQL select
 58:      *
 59:      * @param int $type
 60:      * @return Mage_Reports_Model_Mysql4_Quote_Collection
 61:      */
 62:     public function setSelectCountSqlType($type)
 63:     {
 64:         $this->_selectCountSqlType = $type;
 65:         return $this;
 66:     }
 67: 
 68:     protected function _construct()
 69:     {
 70:         parent::_construct();
 71:         /**
 72:          * Allow to use analytic function
 73:          */
 74:         $this->_useAnalyticFunction = true;
 75:     }
 76: 
 77: 
 78:     /**
 79:      * Prepare for abandoned report
 80:      *
 81:      * @param array $storeIds
 82:      * @param string $filter
 83:      * @return Mage_Reports_Model_Resource_Quote_Collection
 84:      */
 85:     public function prepareForAbandonedReport($storeIds, $filter = null)
 86:     {
 87:         $this->addFieldToFilter('items_count', array('neq' => '0'))
 88:             ->addFieldToFilter('main_table.is_active', '1')
 89:             ->addSubtotal($storeIds, $filter)
 90:             ->addCustomerData($filter)
 91:             ->setOrder('updated_at');
 92:         if (is_array($storeIds) && !empty($storeIds)) {
 93:             $this->addFieldToFilter('store_id', array('in' => $storeIds));
 94:         }
 95: 
 96: 
 97:         return $this;
 98:     }
 99: 
100:     /**
101:      * Prepare select query for products in carts report
102:      *
103:      * @return Mage_Reports_Model_Resource_Quote_Collection
104:      */
105:     public function prepareForProductsInCarts()
106:     {
107:         $productEntity          = Mage::getResourceSingleton('catalog/product_collection');
108:         $productAttrName        = $productEntity->getAttribute('name');
109:         $productAttrNameId      = (int) $productAttrName->getAttributeId();
110:         $productAttrNameTable   = $productAttrName->getBackend()->getTable();
111:         $productAttrPrice       = $productEntity->getAttribute('price');
112:         $productAttrPriceId     = (int) $productAttrPrice->getAttributeId();
113:         $productAttrPriceTable  = $productAttrPrice->getBackend()->getTable();
114: 
115:         $ordersSubSelect = clone $this->getSelect();
116:         $ordersSubSelect->reset()
117:             ->from(
118:                 array('oi' => $this->getTable('sales/order_item')),
119:                 array(
120:                    'orders' => new Zend_Db_Expr('COUNT(1)'),
121:                    'product_id'))
122:             ->group('oi.product_id');
123: 
124:         $this->getSelect()
125:             ->useStraightJoin(true)
126:             ->reset(Zend_Db_Select::COLUMNS)
127:             ->joinInner(
128:                 array('quote_items' => $this->getTable('sales/quote_item')),
129:                 'quote_items.quote_id = main_table.entity_id',
130:                 null)
131:             ->joinInner(
132:                 array('e' => $this->getTable('catalog/product')),
133:                 'e.entity_id = quote_items.product_id',
134:                 null)
135:             ->joinInner(
136:                 array('product_name' => $productAttrNameTable),
137:                 "product_name.entity_id = e.entity_id AND product_name.attribute_id = {$productAttrNameId}",
138:                 array('name'=>'product_name.value'))
139:             ->joinInner(
140:                 array('product_price' => $productAttrPriceTable),
141:                 "product_price.entity_id = e.entity_id AND product_price.attribute_id = {$productAttrPriceId}",
142:                 array('price' => new Zend_Db_Expr('product_price.value * main_table.base_to_global_rate')))
143:             ->joinLeft(
144:                 array('order_items' => new Zend_Db_Expr(sprintf('(%s)', $ordersSubSelect))),
145:                 'order_items.product_id = e.entity_id',
146:                 array()
147:             )
148:             ->columns('e.*')
149:             ->columns(array('carts' => new Zend_Db_Expr('COUNT(quote_items.item_id)')))
150:             ->columns('order_items.orders')
151:             ->where('main_table.is_active = ?', 1)
152:             ->group('quote_items.product_id');
153: 
154:         return $this;
155:     }
156: 
157:     /**
158:      * Add store ids to filter
159:      *
160:      * @param array $storeIds
161:      * @return Mage_Reports_Model_Resource_Quote_Collection
162:      */
163:     public function addStoreFilter($storeIds)
164:     {
165:         $this->addFieldToFilter('store_id', array('in' => $storeIds));
166:         return $this;
167:     }
168: 
169:     /**
170:      * Add customer data
171:      *
172:      * @param unknown_type $filter
173:      * @return Mage_Reports_Model_Resource_Quote_Collection
174:      */
175:     public function addCustomerData($filter = null)
176:     {
177:         $customerEntity         = Mage::getResourceSingleton('customer/customer');
178:         $attrFirstname          = $customerEntity->getAttribute('firstname');
179:         $attrFirstnameId        = (int) $attrFirstname->getAttributeId();
180:         $attrFirstnameTableName = $attrFirstname->getBackend()->getTable();
181: 
182:         $attrLastname           = $customerEntity->getAttribute('lastname');
183:         $attrLastnameId         = (int) $attrLastname->getAttributeId();
184:         $attrLastnameTableName  = $attrLastname->getBackend()->getTable();
185: 
186:         $attrEmail       = $customerEntity->getAttribute('email');
187:         $attrEmailTableName = $attrEmail->getBackend()->getTable();
188: 
189:         $adapter = $this->getSelect()->getAdapter();
190:         $customerName = $adapter->getConcatSql(array('cust_fname.value', 'cust_lname.value'), ' ');
191:         $this->getSelect()
192:             ->joinInner(
193:                 array('cust_email' => $attrEmailTableName),
194:                 'cust_email.entity_id = main_table.customer_id',
195:                 array('email' => 'cust_email.email')
196:             )
197:             ->joinInner(
198:                 array('cust_fname' => $attrFirstnameTableName),
199:                 implode(' AND ', array(
200:                     'cust_fname.entity_id = main_table.customer_id',
201:                     $adapter->quoteInto('cust_fname.attribute_id = ?', (int)$attrFirstnameId),
202:                 )),
203:                 array('firstname' => 'cust_fname.value')
204:             )
205:             ->joinInner(
206:                 array('cust_lname' => $attrLastnameTableName),
207:                 implode(' AND ', array(
208:                     'cust_lname.entity_id = main_table.customer_id',
209:                      $adapter->quoteInto('cust_lname.attribute_id = ?', (int)$attrLastnameId)
210:                 )),
211:                 array(
212:                     'lastname'      => 'cust_lname.value',
213:                     'customer_name' => $customerName
214:                 )
215:             );
216: 
217:         $this->_joinedFields['customer_name'] = $customerName;
218:         $this->_joinedFields['email']         = 'cust_email.email';
219: 
220:         if ($filter) {
221:             if (isset($filter['customer_name'])) {
222:                 $likeExpr = '%' . $filter['customer_name'] . '%';
223:                 $this->getSelect()->where($this->_joinedFields['customer_name'] . ' LIKE ?', $likeExpr);
224:             }
225:             if (isset($filter['email'])) {
226:                 $likeExpr = '%' . $filter['email'] . '%';
227:                 $this->getSelect()->where($this->_joinedFields['email'] . ' LIKE ?', $likeExpr);
228:             }
229:         }
230: 
231:         return $this;
232:     }
233: 
234:     /**
235:      * Add subtotals
236:      *
237:      * @param array $storeIds
238:      * @param array $filter
239:      * @return Mage_Reports_Model_Resource_Quote_Collection
240:      */
241:     public function addSubtotal($storeIds = '', $filter = null)
242:     {
243:         if (is_array($storeIds)) {
244:             $this->getSelect()->columns(array(
245:                 'subtotal' => '(main_table.base_subtotal_with_discount*main_table.base_to_global_rate)'
246:             ));
247:             $this->_joinedFields['subtotal'] =
248:                 '(main_table.base_subtotal_with_discount*main_table.base_to_global_rate)';
249:         } else {
250:             $this->getSelect()->columns(array('subtotal' => 'main_table.base_subtotal_with_discount'));
251:             $this->_joinedFields['subtotal'] = 'main_table.base_subtotal_with_discount';
252:         }
253: 
254:         if ($filter && is_array($filter) && isset($filter['subtotal'])) {
255:             if (isset($filter['subtotal']['from'])) {
256:                 $this->getSelect()->where(
257:                     $this->_joinedFields['subtotal'] . ' >= ?',
258:                     $filter['subtotal']['from'], Zend_Db::FLOAT_TYPE
259:                 );
260:             }
261:             if (isset($filter['subtotal']['to'])) {
262:                 $this->getSelect()->where(
263:                     $this->_joinedFields['subtotal'] . ' <= ?',
264:                     $filter['subtotal']['to'], Zend_Db::FLOAT_TYPE
265:                 );
266:             }
267:         }
268: 
269:         return $this;
270:     }
271: 
272:     /**
273:      * Get select count sql
274:      *
275:      * @return unknown
276:      */
277:     public function getSelectCountSql()
278:     {
279:         $countSelect = clone $this->getSelect();
280:         $countSelect->reset(Zend_Db_Select::ORDER);
281:         $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
282:         $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
283:         $countSelect->reset(Zend_Db_Select::COLUMNS);
284:         $countSelect->reset(Zend_Db_Select::GROUP);
285:         $countSelect->resetJoinLeft();
286: 
287:         if ($this->_selectCountSqlType == self::SELECT_COUNT_SQL_TYPE_CART) {
288:             $countSelect->columns("COUNT(DISTINCT e.entity_id)");
289:         } else {
290:             $countSelect->columns("COUNT(DISTINCT main_table.entity_id)");
291:         }
292: 
293:         return $countSelect;
294:     }
295: }
296: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0