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 Stock Status per website 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_Stock_Status extends Mage_Core_Model_Resource_Db_Abstract
 36: {
 37:     /**
 38:      * Resource model initialization
 39:      *
 40:      */
 41:     protected function _construct()
 42:     {
 43:         $this->_init('cataloginventory/stock_status', 'product_id');
 44:     }
 45: 
 46:     /**
 47:      * Save Product Status per website
 48:      *
 49:      * @param Mage_CatalogInventory_Model_Stock_Status $object
 50:      * @param int $productId
 51:      * @param int $status
 52:      * @param float $qty
 53:      * @param int $stockId
 54:      * @param int|null $websiteId
 55:      * @return Mage_CatalogInventory_Model_Resource_Stock_Status
 56:      */
 57:     public function saveProductStatus(Mage_CatalogInventory_Model_Stock_Status $object, $productId, $status, $qty = 0,
 58:         $stockId = 1, $websiteId = null)
 59:     {
 60:         $websites = array_keys($object->getWebsites($websiteId));
 61:         $adapter = $this->_getWriteAdapter();
 62:         foreach ($websites as $websiteId) {
 63:             $select = $adapter->select()
 64:                 ->from($this->getMainTable())
 65:                 ->where('product_id = :product_id')
 66:                 ->where('website_id = :website_id')
 67:                 ->where('stock_id = :stock_id');
 68:             $bind = array(
 69:                 ':product_id' => $productId,
 70:                 ':website_id' => $websiteId,
 71:                 ':stock_id'   => $stockId
 72:             );
 73:             if ($row = $adapter->fetchRow($select, $bind)) {
 74:                 $bind = array(
 75:                     'qty'           => $qty,
 76:                     'stock_status'  => $status
 77:                 );
 78:                 $where = array(
 79:                     $adapter->quoteInto('product_id=?', (int)$row['product_id']),
 80:                     $adapter->quoteInto('website_id=?', (int)$row['website_id']),
 81:                     $adapter->quoteInto('stock_id=?', (int)$row['stock_id']),
 82:                 );
 83:                 $adapter->update($this->getMainTable(), $bind, $where);
 84:             } else {
 85:                 $bind = array(
 86:                     'product_id'    => $productId,
 87:                     'website_id'    => $websiteId,
 88:                     'stock_id'      => $stockId,
 89:                     'qty'           => $qty,
 90:                     'stock_status'  => $status
 91:                 );
 92:                 $adapter->insert($this->getMainTable(), $bind);
 93:             }
 94:         }
 95: 
 96:         return $this;
 97:     }
 98: 
 99:     /**
100:      * Retrieve product status
101:      * Return array as key product id, value - stock status
102:      *
103:      * @param int|array $productIds
104:      * @param int $websiteId
105:      * @param int $stockId
106:      * @return array
107:      */
108:     public function getProductStatus($productIds, $websiteId, $stockId = 1)
109:     {
110:         if (!is_array($productIds)) {
111:             $productIds = array($productIds);
112:         }
113: 
114:         $select = $this->_getReadAdapter()->select()
115:             ->from($this->getMainTable(), array('product_id', 'stock_status'))
116:             ->where('product_id IN(?)', $productIds)
117:             ->where('stock_id=?', (int)$stockId)
118:             ->where('website_id=?', (int)$websiteId);
119:         return $this->_getReadAdapter()->fetchPairs($select);
120:     }
121: 
122:     /**
123:      * Retrieve product(s) data array
124:      *
125:      * @param int|array $productIds
126:      * @param int $websiteId
127:      * @param int $stockId
128:      * @return array
129:      */
130:     public function getProductData($productIds, $websiteId, $stockId = 1)
131:     {
132:         if (!is_array($productIds)) {
133:             $productIds = array($productIds);
134:         }
135: 
136:         $result = array();
137: 
138:         $select = $this->_getReadAdapter()->select()
139:             ->from($this->getMainTable())
140:             ->where('product_id IN(?)', $productIds)
141:             ->where('stock_id=?', (int)$stockId)
142:             ->where('website_id=?', (int)$websiteId);
143:         $result = $this->_getReadAdapter()->fetchAssoc($select);
144:         return $result;
145:     }
146: 
147:     /**
148:      * Retrieve websites and default stores
149:      * Return array as key website_id, value store_id
150:      *
151:      * @return array
152:      */
153:     public function getWebsiteStores()
154:     {
155:         $select = Mage::getModel('core/website')->getDefaultStoresSelect(false);
156:         return $this->_getReadAdapter()->fetchPairs($select);
157:     }
158: 
159:     /**
160:      * Retrieve Product Type
161:      *
162:      * @param array|int $productIds
163:      * @return array
164:      */
165:     public function getProductsType($productIds)
166:     {
167:         if (!is_array($productIds)) {
168:             $productIds = array($productIds);
169:         }
170: 
171:         $select = $this->_getReadAdapter()->select()
172:             ->from(
173:                 array('e' => $this->getTable('catalog/product')),
174:                 array('entity_id', 'type_id')
175:             )
176:             ->where('entity_id IN(?)', $productIds);
177:         return $this->_getReadAdapter()->fetchPairs($select);
178:     }
179: 
180:     /**
181:      * Retrieve Product part Collection array
182:      * Return array as key product id, value product type
183:      *
184:      * @param int $lastEntityId
185:      * @param int $limit
186:      * @return array
187:      */
188:     public function getProductCollection($lastEntityId = 0, $limit = 1000)
189:     {
190:         $select = $this->_getReadAdapter()->select()
191:             ->from(
192:                 array('e' => $this->getTable('catalog/product')),
193:                 array('entity_id', 'type_id')
194:             )
195:             ->order('entity_id ASC')
196:             ->where('entity_id > :entity_id')
197:             ->limit($limit);
198:         return $this->_getReadAdapter()->fetchPairs($select, array(':entity_id' => $lastEntityId));
199:     }
200: 
201:     /**
202:      * Add stock status to prepare index select
203:      *
204:      * @param Varien_Db_Select $select
205:      * @param Mage_Core_Model_Website $website
206:      * @return Mage_CatalogInventory_Model_Resource_Stock_Status
207:      */
208:     public function addStockStatusToSelect(Varien_Db_Select $select, Mage_Core_Model_Website $website)
209:     {
210:         $websiteId = $website->getId();
211:         $select->joinLeft(
212:             array('stock_status' => $this->getMainTable()),
213:             'e.entity_id = stock_status.product_id AND stock_status.website_id='.$websiteId,
214:             array('salable' => 'stock_status.stock_status')
215:         );
216: 
217:         return $this;
218:     }
219: 
220:     /**
221:      * Add stock status limitation to catalog product price index select object
222:      *
223:      * @param Varien_Db_Select $select
224:      * @param string|Zend_Db_Expr $entityField
225:      * @param string|Zend_Db_Expr $websiteField
226:      * @return Mage_CatalogInventory_Model_Resource_Stock_Status
227:      */
228:     public function prepareCatalogProductIndexSelect(Varien_Db_Select $select, $entityField, $websiteField)
229:     {
230:         $select->join(
231:             array('ciss' => $this->getMainTable()),
232:             "ciss.product_id = {$entityField} AND ciss.website_id = {$websiteField}",
233:             array()
234:         );
235:         $select->where('ciss.stock_status = ?', Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK);
236: 
237:         return $this;
238:     }
239: 
240:     /**
241:      * Add only is in stock products filter to product collection
242:      *
243:      * @param Mage_Catalog_Model_Resource_Product_Collection $collection
244:      * @return Mage_CatalogInventory_Model_Resource_Stock_Status
245:      */
246:     public function addIsInStockFilterToCollection($collection)
247:     {
248:         $websiteId = Mage::app()->getStore($collection->getStoreId())->getWebsiteId();
249:         $joinCondition = $this->_getReadAdapter()
250:             ->quoteInto('e.entity_id = stock_status_index.product_id'
251:                 . ' AND stock_status_index.website_id = ?', $websiteId
252:             );
253: 
254:         $joinCondition .= $this->_getReadAdapter()->quoteInto(
255:             ' AND stock_status_index.stock_id = ?',
256:             Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID
257:         );
258: 
259:         $collection->getSelect()
260:             ->join(
261:                 array('stock_status_index' => $this->getMainTable()),
262:                 $joinCondition,
263:                 array()
264:             )
265:             ->where('stock_status_index.stock_status=?', Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK);
266: 
267:         return $this;
268:     }
269: }
270: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0