Mage_CatalogInventory_Model_Stock Class Reference

Inheritance diagram for Mage_CatalogInventory_Model_Stock:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 getId ()
 addItemsToProducts ($productCollection)
 getItemCollection ()
 registerItemSale (Varien_Object $item)
 backItemQty ($productId, $qty)
 lockProductItems ($productIds)
 addInStockFilterToCollection ($collection)

Public Attributes

const BACKORDERS_NO = 0
const BACKORDERS_YES_NONOTIFY = 1
const BACKORDERS_YES_NOTIFY = 2
const BACKORDERS_BELOW = 1
const BACKORDERS_YES = 2
const STOCK_OUT_OF_STOCK = 0
const STOCK_IN_STOCK = 1
const DEFAULT_STOCK_ID = 1

Protected Member Functions

 _construct ()


Detailed Description

Stock model

Author:
Magento Core Team <core@magentocommerce.com>

Definition at line 32 of file Stock.php.


Member Function Documentation

_construct (  )  [protected]

Enter description here...

Reimplemented from Varien_Object.

Definition at line 47 of file Stock.php.

00048     {
00049         $this->_init('cataloginventory/stock');
00050     }

addInStockFilterToCollection ( collection  ) 

Enter description here...

Parameters:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection $collection
Returns:
Mage_CatalogInventory_Model_Stock $this

Definition at line 162 of file Stock.php.

00163     {
00164         $this->getResource()->setInStockFilterToCollection($collection);
00165         return $this;
00166     }

addItemsToProducts ( productCollection  ) 

Add stock item objects to products

Parameters:
collection $products
Returns:
Mage_CatalogInventory_Model_Stock

Definition at line 68 of file Stock.php.

00069     {
00070         $items = $this->getItemCollection()
00071             ->addProductsFilter($productCollection)
00072             ->joinStockStatus($productCollection->getStoreId())
00073             ->load();
00074         foreach ($items as $item) {
00075             foreach($productCollection as $product){
00076                 if($product->getId()==$item->getProductId()){
00077                     if($product instanceof Mage_Catalog_Model_Product) {
00078                         $item->assignProduct($product);
00079                     }
00080                 }
00081             }
00082         }
00083         return $this;
00084     }

backItemQty ( productId,
qty 
)

Get back to stock (when order is canceled or whatever else)

Parameters:
int $productId
numeric $qty
Returns:
Mage_CatalogInventory_Model_Stock

Definition at line 130 of file Stock.php.

00131     {
00132         $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
00133         if ($stockItem->getId() && Mage::helper('catalogInventory')->isQty($stockItem->getTypeId())) {
00134             $stockItem->addQty($qty);
00135             if ($stockItem->getCanBackInStock() && $stockItem->getQty() > $stockItem->getMinQty()) {
00136                 $stockItem->setIsInStock(true)
00137                     ->setStockStatusChangedAutomaticallyFlag(true);
00138             }
00139             $stockItem->save();
00140         }
00141         return $this;
00142     }

getId (  ) 

Retrieve stock identifier

Returns:
int

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 57 of file Stock.php.

00058     {
00059         return self::DEFAULT_STOCK_ID;
00060     }

getItemCollection (  ) 

Retrieve items collection object with stock filter

Returns:
unknown

Definition at line 91 of file Stock.php.

00092     {
00093         return Mage::getResourceModel('cataloginventory/stock_item_collection')
00094             ->addStockFilter($this->getId());
00095     }

lockProductItems ( productIds  ) 

Lock stock items for product ids array

Parameters:
array $productIds
Returns:
Mage_CatalogInventory_Model_Stock

Definition at line 150 of file Stock.php.

00151     {
00152         $this->_getResource()->lockProductItems($this, $productIds);
00153         return $this;
00154     }

registerItemSale ( Varien_Object item  ) 

Subtract ordered qty for product

Parameters:
Varien_Object $item
Returns:
Mage_CatalogInventory_Model_Stock

Definition at line 103 of file Stock.php.

00104     {
00105         if ($productId = $item->getProductId()) {
00106             $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
00107             if (Mage::helper('catalogInventory')->isQty($stockItem->getTypeId())) {
00108                 if ($item->getStoreId()) {
00109                     $stockItem->setStoreId($item->getStoreId());
00110                 }
00111                 if ($stockItem->checkQty($item->getQtyOrdered()) || Mage::app()->getStore()->isAdmin()) {
00112                     $stockItem->subtractQty($item->getQtyOrdered());
00113                     $stockItem->save();
00114                 }
00115             }
00116         }
00117         else {
00118             Mage::throwException(Mage::helper('cataloginventory')->__('Can not specify product identifier for order item'));
00119         }
00120         return $this;
00121     }


Member Data Documentation

const BACKORDERS_BELOW = 1

Definition at line 39 of file Stock.php.

const BACKORDERS_NO = 0

Definition at line 34 of file Stock.php.

const BACKORDERS_YES = 2

Definition at line 40 of file Stock.php.

Definition at line 35 of file Stock.php.

Definition at line 36 of file Stock.php.

const DEFAULT_STOCK_ID = 1

Definition at line 45 of file Stock.php.

const STOCK_IN_STOCK = 1

Definition at line 43 of file Stock.php.

const STOCK_OUT_OF_STOCK = 0

Definition at line 42 of file Stock.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:48 2009 for Magento by  doxygen 1.5.8