Mage_CatalogInventory_Model_Mysql4_Stock_Item_Collection Class Reference

Inheritance diagram for Mage_CatalogInventory_Model_Mysql4_Stock_Item_Collection:

Mage_Core_Model_Mysql4_Collection_Abstract Varien_Data_Collection_Db Varien_Data_Collection

List of all members.

Public Member Functions

 addStockFilter ($stock)
 addProductsFilter ($products)
 joinStockStatus ($storeId=null)
 addManagedFilter ($isStockManagedInConfig)
 addQtyFilter ($comparsionMethod, $qty)
 load ($printQuery=false, $logQuery=false)

Protected Member Functions

 _construct ()


Detailed Description

Definition at line 34 of file Collection.php.


Member Function Documentation

_construct (  )  [protected]

Initialization here

Reimplemented from Mage_Core_Model_Mysql4_Collection_Abstract.

Definition at line 36 of file Collection.php.

00037     {
00038         $this->_init('cataloginventory/stock_item');
00039     }

addManagedFilter ( isStockManagedInConfig  ) 

Definition at line 103 of file Collection.php.

00104     {
00105         if ($isStockManagedInConfig) {
00106             $this->getSelect()->where('(manage_stock = 1 OR use_config_manage_stock = 1)');
00107         } else {
00108             $this->addFieldToFilter('manage_stock', 1);
00109         }
00110 
00111         return $this;
00112     }

addProductsFilter ( products  ) 

Add product filter to collection

Parameters:
mixed $products
Returns:
Mage_CatalogInventory_Model_Mysql4_Stock_Item_Collection

Definition at line 64 of file Collection.php.

00065     {
00066         $productIds = array();
00067         foreach ($products as $product) {
00068             if ($product instanceof Mage_Catalog_Model_Product) {
00069                 $productIds[] = $product->getId();
00070             }
00071             else {
00072                 $productIds[] = $product;
00073             }
00074         }
00075         if (empty($productIds)) {
00076             $productIds[] = false;
00077             $this->_setIsLoaded(true);
00078         }
00079         $this->addFieldToFilter('main_table.product_id', array('in'=>$productIds));
00080         return $this;
00081     }

addQtyFilter ( comparsionMethod,
qty 
)

Definition at line 114 of file Collection.php.

00115     {
00116         $allowedMethods = array('<', '>', '=', '<=', '>=', '<>');
00117         if (!in_array($comparsionMethod, $allowedMethods)) {
00118             Mage::throwException(Mage::helper('cataloginventory')->__('%s is not correct comparsion method.', $comparsionMethod));
00119         }
00120         $this->getSelect()->where("main_table.qty {$comparsionMethod} ?", $qty);
00121         return $this;
00122     }

addStockFilter ( stock  ) 

Add stock filter to collection

Parameters:
mixed $stock
Returns:
Mage_CatalogInventory_Model_Mysql4_Stock_Item_Collection

Definition at line 47 of file Collection.php.

00048     {
00049         if ($stock instanceof Mage_CatalogInventory_Model_Stock) {
00050             $this->addFieldToFilter('main_table.stock_id', $stock->getId());
00051         }
00052         else {
00053             $this->addFieldToFilter('main_table.stock_id', $stock);
00054         }
00055         return $this;
00056     }

joinStockStatus ( storeId = null  ) 

Join Stock Status to collection

Parameters:
int $storeId
Returns:
Mage_CatalogInventory_Model_Mysql4_Stock_Item_Collection

Definition at line 89 of file Collection.php.

00090     {
00091         $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
00092         $this->getSelect()->joinLeft(
00093             array('status_table' => $this->getTable('cataloginventory/stock_status')),
00094             '`main_table`.`product_id`=`status_table`.`product_id`'
00095                 . ' AND `main_table`.`stock_id`=`status_table`.`stock_id`'
00096                 . $this->getConnection()->quoteInto(' AND `status_table`.`website_id`=?', $websiteId),
00097             array('stock_status')
00098         );
00099 
00100         return $this;
00101     }

load ( printQuery = false,
logQuery = false 
)

Load data

Returns:
Varien_Data_Collection_Db

Reimplemented from Mage_Core_Model_Mysql4_Collection_Abstract.

Definition at line 129 of file Collection.php.

00130     {
00131         if (!$this->isLoaded()) {
00132             $this->getSelect()->joinInner(array('_products_table' => $this->getTable('catalog/product')),
00133                 'main_table.product_id=_products_table.entity_id', 'type_id'
00134             );
00135         }
00136         return parent::load($printQuery, $logQuery);
00137     }


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

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