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:  * Product Low Stock Report 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_Lowstock_Collection extends Mage_Reports_Model_Resource_Product_Collection
 36: {
 37:     /**
 38:      * CatalogInventory Stock Item Resource instance
 39:      *
 40:      * @var Mage_CatalogInventory_Model_Resource_Stock_Item
 41:      */
 42:     protected $_inventoryItemResource      = null;
 43: 
 44:     /**
 45:      * Flag about is joined CatalogInventory Stock Item
 46:      *
 47:      * @var bool
 48:      */
 49:     protected $_inventoryItemJoined        = false;
 50: 
 51:     /**
 52:      * Alias for CatalogInventory Stock Item Table
 53:      *
 54:      * @var string
 55:      */
 56:     protected $_inventoryItemTableAlias    = 'lowstock_inventory_item';
 57: 
 58:     /**
 59:      * Retrieve CatalogInventory Stock Item Resource instance
 60:      *
 61:      * @return Mage_CatalogInventory_Model_Resource_Stock_Item
 62:      */
 63:     protected function _getInventoryItemResource()
 64:     {
 65:         if ($this->_inventoryItemResource === null) {
 66:             $this->_inventoryItemResource = Mage::getResourceSingleton('cataloginventory/stock_item');
 67:         }
 68:         return $this->_inventoryItemResource;
 69:     }
 70: 
 71:     /**
 72:      * Retrieve CatalogInventory Stock Item Table
 73:      *
 74:      * @return string
 75:      */
 76:     protected function _getInventoryItemTable()
 77:     {
 78:         return $this->_getInventoryItemResource()->getMainTable();
 79:     }
 80: 
 81:     /**
 82:      * Retrieve CatalogInventory Stock Item Table Id field name
 83:      *
 84:      * @return string
 85:      */
 86:     protected function _getInventoryItemIdField()
 87:     {
 88:         return $this->_getInventoryItemResource()->getIdFieldName();
 89:     }
 90: 
 91:     /**
 92:      * Retrieve alias for CatalogInventory Stock Item Table
 93:      *
 94:      * @return string
 95:      */
 96:     protected function _getInventoryItemTableAlias()
 97:     {
 98:         return $this->_inventoryItemTableAlias;
 99:     }
100: 
101:     /**
102:      * Add catalog inventory stock item field to select
103:      *
104:      * @param string $field
105:      * @param string $alias
106:      * @return Mage_Reports_Model_Resource_Product_Lowstock_Collection
107:      */
108:     protected function _addInventoryItemFieldToSelect($field, $alias = null)
109:     {
110:         if (empty($alias)) {
111:             $alias = $field;
112:         }
113: 
114:         if (isset($this->_joinFields[$alias])) {
115:             return $this;
116:         }
117: 
118:         $this->_joinFields[$alias] = array(
119:             'table' => $this->_getInventoryItemTableAlias(),
120:             'field' => $field
121:         );
122: 
123:         $this->getSelect()->columns(array($alias => $field), $this->_getInventoryItemTableAlias());
124:         return $this;
125:     }
126: 
127:     /**
128:      * Retrieve catalog inventory stock item field correlation name
129:      *
130:      * @param string $field
131:      * @return string
132:      */
133:     protected function _getInventoryItemField($field)
134:     {
135:         return sprintf('%s.%s', $this->_getInventoryItemTableAlias(), $field);
136:     }
137: 
138:     /**
139:      * Join catalog inventory stock item table for further stock_item values filters
140:      *
141:      * @param unknown_type $fields
142:      * @return Mage_Reports_Model_Resource_Product_Lowstock_Collection
143:      */
144:     public function joinInventoryItem($fields = array())
145:     {
146:         if (!$this->_inventoryItemJoined) {
147:             $this->getSelect()->join(
148:                 array($this->_getInventoryItemTableAlias() => $this->_getInventoryItemTable()),
149:                 sprintf('e.%s = %s.product_id',
150:                     $this->getEntity()->getEntityIdField(),
151:                     $this->_getInventoryItemTableAlias()
152:                 ),
153:                 array()
154:             );
155:             $this->_inventoryItemJoined = true;
156:         }
157: 
158:         if (!is_array($fields)) {
159:             if (empty($fields)) {
160:                 $fields = array();
161:             } else {
162:                 $fields = array($fields);
163:             }
164:         }
165: 
166:         foreach ($fields as $alias => $field) {
167:             if (!is_string($alias)) {
168:                 $alias = null;
169:             }
170:             $this->_addInventoryItemFieldToSelect($field, $alias);
171:         }
172: 
173:         return $this;
174:     }
175: 
176:     /**
177:      * Add filter by product type(s)
178:      *
179:      * @param array|string $typeFilter
180:      * @return Mage_Reports_Model_Resource_Product_Lowstock_Collection
181:      */
182:     public function filterByProductType($typeFilter)
183:     {
184:         if (!is_string($typeFilter) && !is_array($typeFilter)) {
185:             Mage::throwException(
186:                 Mage::helper('catalog')->__('Wrong product type filter specified')
187:             );
188:         }
189:         $this->addAttributeToFilter('type_id', $typeFilter);
190:         return $this;
191:     }
192: 
193:     /**
194:      * Add filter by product types from config
195:      * Only types witch has QTY parameter
196:      *
197:      * @return Mage_Reports_Model_Resource_Product_Lowstock_Collection
198:      */
199:     public function filterByIsQtyProductTypes()
200:     {
201:         $this->filterByProductType(
202:             array_keys(array_filter(Mage::helper('cataloginventory')->getIsQtyTypeIds()))
203:         );
204:         return $this;
205:     }
206: 
207:     /**
208:      * Add Use Manage Stock Condition to collection
209:      *
210:      * @param int|null $storeId
211:      * @return Mage_Reports_Model_Resource_Product_Lowstock_Collection
212:      */
213:     public function useManageStockFilter($storeId = null)
214:     {
215:         $this->joinInventoryItem();
216:         $manageStockExpr = $this->getConnection()->getCheckSql(
217:             $this->_getInventoryItemField('use_config_manage_stock') . ' = 1',
218:             (int) Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK, $storeId),
219:             $this->_getInventoryItemField('manage_stock')
220:         );
221:         $this->getSelect()->where($manageStockExpr . ' = ?', 1);
222:         return $this;
223:     }
224: 
225:     /**
226:      * Add Notify Stock Qty Condition to collection
227:      *
228:      * @param int $storeId
229:      * @return Mage_Reports_Model_Resource_Product_Lowstock_Collection
230:      */
231:     public function useNotifyStockQtyFilter($storeId = null)
232:     {
233:         $this->joinInventoryItem(array('qty'));
234:         $notifyStockExpr = $this->getConnection()->getCheckSql(
235:             $this->_getInventoryItemField('use_config_notify_stock_qty') . ' = 1',
236:             (int)Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_NOTIFY_STOCK_QTY, $storeId),
237:             $this->_getInventoryItemField('notify_stock_qty')
238:         );
239:         $this->getSelect()->where('qty < ?', $notifyStockExpr);
240:         return $this;
241:     }
242: }
243: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0