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: * Report Sold Products collection
30: *
31: * @category Mage
32: * @package Mage_Reports
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Reports_Model_Resource_Product_Sold_Collection extends Mage_Reports_Model_Resource_Product_Collection
36: {
37: /**
38: * Initialize resources
39: *
40: */
41: protected function _construct()
42: {
43: parent::_construct();
44: $this->_useAnalyticFunction = true;
45: }
46: /**
47: * Set Date range to collection
48: *
49: * @param int $from
50: * @param int $to
51: * @return Mage_Reports_Model_Resource_Product_Sold_Collection
52: */
53: public function setDateRange($from, $to)
54: {
55: $this->_reset()
56: ->addAttributeToSelect('*')
57: ->addOrderedQty($from, $to)
58: ->setOrder('ordered_qty', self::SORT_ORDER_DESC);
59: return $this;
60: }
61:
62: /**
63: * Set store filter to collection
64: *
65: * @param array $storeIds
66: * @return Mage_Reports_Model_Resource_Product_Sold_Collection
67: */
68: public function setStoreIds($storeIds)
69: {
70: if ($storeIds) {
71: $this->getSelect()->where('order_items.store_id IN (?)', (array)$storeIds);
72: }
73: return $this;
74: }
75:
76: /**
77: * Add website product limitation
78: *
79: * @return Mage_Reports_Model_Resource_Product_Sold_Collection
80: */
81: protected function _productLimitationJoinWebsite()
82: {
83: $filters = $this->_productLimitationFilters;
84: $conditions = array('product_website.product_id=e.entity_id');
85: if (isset($filters['website_ids'])) {
86: $conditions[] = $this->getConnection()
87: ->quoteInto('product_website.website_id IN(?)', $filters['website_ids']);
88:
89: $subQuery = $this->getConnection()->select()
90: ->from(array('product_website' => $this->getTable('catalog/product_website')),
91: array('product_website.product_id')
92: )
93: ->where(join(' AND ', $conditions));
94: $this->getSelect()->where('e.entity_id IN( '.$subQuery.' )');
95: }
96:
97: return $this;
98: }
99: }
100: