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_CatalogInventory_Block_Adminhtml_Form_Field_Customergroup
  • Mage_CatalogInventory_Block_Adminhtml_Form_Field_Minsaleqty
  • Mage_CatalogInventory_Block_Qtyincrements
  • Mage_CatalogInventory_Block_Stockqty_Abstract
  • Mage_CatalogInventory_Block_Stockqty_Composite
  • Mage_CatalogInventory_Block_Stockqty_Default
  • Mage_CatalogInventory_Block_Stockqty_Type_Configurable
  • Mage_CatalogInventory_Block_Stockqty_Type_Grouped
  • Mage_CatalogInventory_Helper_Data
  • Mage_CatalogInventory_Helper_Minsaleqty
  • Mage_CatalogInventory_Model_Api2_Stock_Item
  • Mage_CatalogInventory_Model_Api2_Stock_Item_Rest
  • Mage_CatalogInventory_Model_Api2_Stock_Item_Rest_Admin_V1
  • Mage_CatalogInventory_Model_Api2_Stock_Item_Validator_Item
  • Mage_CatalogInventory_Model_Indexer_Stock
  • Mage_CatalogInventory_Model_Mysql4_Indexer_Stock
  • Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Configurable
  • Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Default
  • Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Grouped
  • Mage_CatalogInventory_Model_Mysql4_Stock
  • Mage_CatalogInventory_Model_Mysql4_Stock_Item
  • Mage_CatalogInventory_Model_Mysql4_Stock_Item_Collection
  • Mage_CatalogInventory_Model_Mysql4_Stock_Status
  • Mage_CatalogInventory_Model_Observer
  • Mage_CatalogInventory_Model_Resource_Indexer_Stock
  • Mage_CatalogInventory_Model_Resource_Indexer_Stock_Configurable
  • Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default
  • Mage_CatalogInventory_Model_Resource_Indexer_Stock_Grouped
  • Mage_CatalogInventory_Model_Resource_Stock
  • Mage_CatalogInventory_Model_Resource_Stock_Item
  • Mage_CatalogInventory_Model_Resource_Stock_Item_Collection
  • Mage_CatalogInventory_Model_Resource_Stock_Status
  • Mage_CatalogInventory_Model_Source_Backorders
  • Mage_CatalogInventory_Model_Source_Stock
  • Mage_CatalogInventory_Model_Stock
  • Mage_CatalogInventory_Model_Stock_Item
  • Mage_CatalogInventory_Model_Stock_Item_Api
  • Mage_CatalogInventory_Model_Stock_Item_Api_V2
  • Mage_CatalogInventory_Model_Stock_Status
  • Mage_CatalogInventory_Model_System_Config_Backend_Minqty
  • Mage_CatalogInventory_Model_System_Config_Backend_Minsaleqty
  • Mage_CatalogInventory_Model_System_Config_Backend_Qtyincrements

Interfaces

  • Mage_CatalogInventory_Model_Mysql4_Indexer_Stock_Interface
  • Mage_CatalogInventory_Model_Resource_Indexer_Stock_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_CatalogInventory
 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:  * CatalogInventory Default Stock Status Indexer Resource Model
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_CatalogInventory
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default
 36:     extends Mage_Catalog_Model_Resource_Product_Indexer_Abstract
 37:     implements Mage_CatalogInventory_Model_Resource_Indexer_Stock_Interface
 38: {
 39:     /**
 40:      * Current Product Type Id
 41:      *
 42:      * @var string
 43:      */
 44:     protected $_typeId;
 45: 
 46:     /**
 47:      * Product Type is composite flag
 48:      *
 49:      * @var bool
 50:      */
 51:     protected $_isComposite    = false;
 52: 
 53:     /**
 54:      * Initialize connection and define main table name
 55:      *
 56:      */
 57:     protected function _construct()
 58:     {
 59:         $this->_init('cataloginventory/stock_status', 'product_id');
 60:     }
 61: 
 62:     /**
 63:      * Reindex all stock status data for default logic product type
 64:      *
 65:      * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default
 66:      */
 67:     public function reindexAll()
 68:     {
 69:         $this->useIdxTable(true);
 70:         $this->beginTransaction();
 71:         try {
 72:             $this->_prepareIndexTable();
 73:             $this->commit();
 74:         } catch (Exception $e) {
 75:             $this->rollBack();
 76:             throw $e;
 77:         }
 78:         return $this;
 79:     }
 80: 
 81:     /**
 82:      * Reindex stock data for defined product ids
 83:      *
 84:      * @param int|array $entityIds
 85:      * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default
 86:      */
 87:     public function reindexEntity($entityIds)
 88:     {
 89:         $this->_updateIndex($entityIds);
 90:         return $this;
 91:     }
 92: 
 93:     /**
 94:      * Set active Product Type Id
 95:      *
 96:      * @param string $typeId
 97:      * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default
 98:      */
 99:     public function setTypeId($typeId)
100:     {
101:         $this->_typeId = $typeId;
102:         return $this;
103:     }
104: 
105:     /**
106:      * Retrieve active Product Type Id
107:      *
108:      * @throws Mage_Core_Exception
109:      *
110:      * @return string
111:      */
112:     public function getTypeId()
113:     {
114:         if (is_null($this->_typeId)) {
115:             Mage::throwException(Mage::helper('cataloginventory')->__('Undefined product type.'));
116:         }
117:         return $this->_typeId;
118:     }
119: 
120:     /**
121:      * Set Product Type Composite flag
122:      *
123:      * @param bool $flag
124:      * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default
125:      */
126:     public function setIsComposite($flag)
127:     {
128:         $this->_isComposite = (bool)$flag;
129:         return $this;
130:     }
131: 
132:     /**
133:      * Check product type is composite
134:      *
135:      * @return bool
136:      */
137:     public function getIsComposite()
138:     {
139:         return $this->_isComposite;
140:     }
141: 
142:     /**
143:      * Retrieve is Global Manage Stock enabled
144:      *
145:      * @return bool
146:      */
147:     protected function _isManageStock()
148:     {
149:         return Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK);
150:     }
151: 
152:     /**
153:      * Get the select object for get stock status by product ids
154:      *
155:      * @param int|array $entityIds
156:      * @param bool $usePrimaryTable use primary or temporary index table
157:      * @return Varien_Db_Select
158:      */
159:     protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = false)
160:     {
161:         $adapter = $this->_getWriteAdapter();
162:         $qtyExpr = $adapter->getCheckSql('cisi.qty > 0', 'cisi.qty', 0);
163:         $select  = $adapter->select()
164:             ->from(array('e' => $this->getTable('catalog/product')), array('entity_id'));
165:         $this->_addWebsiteJoinToSelect($select, true);
166:         $this->_addProductWebsiteJoinToSelect($select, 'cw.website_id', 'e.entity_id');
167:         $select->columns('cw.website_id')
168:             ->join(
169:                 array('cis' => $this->getTable('cataloginventory/stock')),
170:                 '',
171:                 array('stock_id'))
172:             ->joinLeft(
173:                 array('cisi' => $this->getTable('cataloginventory/stock_item')),
174:                 'cisi.stock_id = cis.stock_id AND cisi.product_id = e.entity_id',
175:                 array())
176:             ->columns(array('qty' => $qtyExpr))
177:             ->where('cw.website_id != 0')
178:             ->where('e.type_id = ?', $this->getTypeId());
179: 
180:         // add limitation of status
181:         $condition = $adapter->quoteInto('=?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
182:         $this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id', $condition);
183: 
184:         if ($this->_isManageStock()) {
185:             $statusExpr = $adapter->getCheckSql('cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 0',
186:                 1, 'cisi.is_in_stock');
187:         } else {
188:             $statusExpr = $adapter->getCheckSql('cisi.use_config_manage_stock = 0 AND cisi.manage_stock = 1',
189:                 'cisi.is_in_stock', 1);
190:         }
191: 
192:         $select->columns(array('status' => $statusExpr));
193: 
194:         if (!is_null($entityIds)) {
195:             $select->where('e.entity_id IN(?)', $entityIds);
196:         }
197: 
198:         return $select;
199:     }
200: 
201:     /**
202:      * Prepare stock status data in temporary index table
203:      *
204:      * @param int|array $entityIds  the product limitation
205:      * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default
206:      */
207:     protected function _prepareIndexTable($entityIds = null)
208:     {
209:         $adapter = $this->_getWriteAdapter();
210:         $select  = $this->_getStockStatusSelect($entityIds);
211:         $query   = $select->insertFromSelect($this->getIdxTable());
212:         $adapter->query($query);
213: 
214:         return $this;
215:     }
216: 
217:     /**
218:      * Update Stock status index by product ids
219:      *
220:      * @param array|int $entityIds
221:      * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default
222:      */
223:     protected function _updateIndex($entityIds)
224:     {
225:         $adapter = $this->_getWriteAdapter();
226:         $select  = $this->_getStockStatusSelect($entityIds, true);
227:         $query   = $adapter->query($select);
228: 
229:         $i      = 0;
230:         $data   = array();
231:         while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
232:             $i ++;
233:             $data[] = array(
234:                 'product_id'    => (int)$row['entity_id'],
235:                 'website_id'    => (int)$row['website_id'],
236:                 'stock_id'      => (int)$row['stock_id'],
237:                 'qty'           => (float)$row['qty'],
238:                 'stock_status'  => (int)$row['status'],
239:             );
240:             if (($i % 1000) == 0) {
241:                 $this->_updateIndexTable($data);
242:                 $data = array();
243:             }
244:         }
245:         $this->_updateIndexTable($data);
246: 
247:         return $this;
248:     }
249: 
250:     /**
251:      * Update stock status index table (INSERT ... ON DUPLICATE KEY UPDATE ...)
252:      *
253:      * @param array $data
254:      * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default
255:      */
256:     protected function _updateIndexTable($data)
257:     {
258:         if (empty($data)) {
259:             return $this;
260:         }
261: 
262:         $adapter = $this->_getWriteAdapter();
263:         $adapter->insertOnDuplicate($this->getMainTable(), $data, array('qty', 'stock_status'));
264: 
265:         return $this;
266:     }
267: 
268:     /**
269:      * Retrieve temporary index table name
270:      *
271:      * @param string $table
272:      * @return string
273:      */
274:     public function getIdxTable($table = null)
275:     {
276:         if ($this->useIdxTable()) {
277:             return $this->getTable('cataloginventory/stock_status_indexer_idx');
278:         }
279:         return $this->getTable('cataloginventory/stock_status_indexer_tmp');
280:     }
281: }
282: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0