Public Member Functions | |
saveProductStatus (Mage_CatalogInventory_Model_Stock_Status $object, $productId, $status, $qty=0, $stockId=1, $websiteId=null) | |
getProductStatus ($productIds, $websiteId, $stockId=1) | |
getProductData ($productIds, $websiteId, $stockId=1) | |
getWebsiteStores () | |
getProductsType ($productIds) | |
getProductCollection ($lastEntityId=0, $limit=1000) | |
addStockStatusToSelect (Varien_Db_Select $select, Mage_Core_Model_Website $website) | |
Protected Member Functions | |
_construct () |
Definition at line 34 of file Status.php.
_construct | ( | ) | [protected] |
Resource model initialization
Reimplemented from Mage_Core_Model_Resource_Abstract.
Definition at line 40 of file Status.php.
00041 { 00042 $this->_init('cataloginventory/stock_status', 'product_id'); 00043 }
addStockStatusToSelect | ( | Varien_Db_Select $ | select, | |
Mage_Core_Model_Website $ | website | |||
) |
Add stock status to prepare index select
Varien_Db_Select | $select | |
Mage_Core_Model_Website | $website |
Definition at line 204 of file Status.php.
00205 { 00206 $websiteId = $website->getId(); 00207 $select->joinLeft( 00208 array('stock_status' => $this->getMainTable()), 00209 'e.entity_id=stock_status.product_id AND stock_status.website_id='.$websiteId, 00210 array('salable' => 'stock_status.stock_status') 00211 ); 00212 00213 return $this; 00214 }
getProductCollection | ( | $ | lastEntityId = 0 , |
|
$ | limit = 1000 | |||
) |
Retrieve Product part Collection array Return array as key product id, value product type
int | $lastEntityId | |
int | $limit |
Definition at line 186 of file Status.php.
00186 { 00187 $select = $this->_getReadAdapter()->select() 00188 ->from( 00189 array('e' => $this->getTable('catalog/product')), 00190 array('entity_id', 'type_id')) 00191 ->order('entity_id ASC') 00192 ->where('entity_id>?', $lastEntityId) 00193 ->limit($limit); 00194 return $this->_getReadAdapter()->fetchPairs($select); 00195 }
getProductData | ( | $ | productIds, | |
$ | websiteId, | |||
$ | stockId = 1 | |||
) |
Retrieve product(s) data array
int|array | $productIds | |
int | $websiteId | |
int | $stockId |
Definition at line 127 of file Status.php.
00128 { 00129 if (!is_array($productIds)) { 00130 $productIds = array($productIds); 00131 } 00132 00133 $data = array(); 00134 00135 $select = $this->_getReadAdapter()->select() 00136 ->from($this->getMainTable()) 00137 ->where('product_id IN(?)', $productIds) 00138 ->where('stock_id=?', $stockId) 00139 ->where('website_id=?', $websiteId); 00140 $query = $this->_getReadAdapter()->query($select); 00141 while ($row = $query->fetch()) { 00142 $data[$row['product_id']] = $row; 00143 } 00144 return $data; 00145 }
getProductStatus | ( | $ | productIds, | |
$ | websiteId, | |||
$ | stockId = 1 | |||
) |
Retrieve product status Return array as key product id, value - stock status
int|array | $productIds | |
int | $websiteId | |
int | $stockId |
Definition at line 104 of file Status.php.
00105 { 00106 if (!is_array($productIds)) { 00107 $productIds = array($productIds); 00108 } 00109 00110 $select = $this->_getReadAdapter()->select() 00111 ->from($this->getMainTable(), array('product_id', 'stock_status')) 00112 ->where('product_id IN(?)', $productIds) 00113 ->where('stock_id=?', $stockId) 00114 ->where('website_id=?', $websiteId); 00115 return $this->_getReadAdapter()->fetchPairs($select); 00116 }
getProductsType | ( | $ | productIds | ) |
Retrieve Product Type
array|int | $productIds |
Definition at line 164 of file Status.php.
00165 { 00166 if (!is_array($productIds)) { 00167 $productIds = array($productIds); 00168 } 00169 00170 $select = $this->_getReadAdapter()->select() 00171 ->from( 00172 array('e' => $this->getTable('catalog/product')), 00173 array('entity_id', 'type_id')) 00174 ->where('entity_id IN(?)', $productIds); 00175 return $this->_getReadAdapter()->fetchPairs($select); 00176 }
getWebsiteStores | ( | ) |
Retrieve websites and default stores Return array as key website_id, value store_id
Definition at line 153 of file Status.php.
00153 { 00154 $select = Mage::getModel('core/website')->getDefaultStoresSelect(false); 00155 return $this->_getReadAdapter()->fetchPairs($select); 00156 }
saveProductStatus | ( | Mage_CatalogInventory_Model_Stock_Status $ | object, | |
$ | productId, | |||
$ | status, | |||
$ | qty = 0 , |
|||
$ | stockId = 1 , |
|||
$ | websiteId = null | |||
) |
Save Product Status per website
Mage_CatalogInventory_Model_Stock_Status | $object | |
int | $productId | |
int | $status | |
float | $qty | |
int | $stockId | |
int|null | $websiteId |
Definition at line 56 of file Status.php.
00058 { 00059 $websites = array_keys($object->getWebsites($websiteId)); 00060 00061 foreach ($websites as $websiteId) { 00062 $select = $this->_getWriteAdapter()->select() 00063 ->from($this->getMainTable()) 00064 ->where('product_id=?', $productId) 00065 ->where('website_id=?', $websiteId) 00066 ->where('stock_id=?', $stockId); 00067 if ($row = $this->_getWriteAdapter()->fetchRow($select)) { 00068 $bind = array( 00069 'qty' => $qty, 00070 'stock_status' => $status 00071 ); 00072 $where = array( 00073 $this->_getWriteAdapter()->quoteInto('product_id=?', $row['product_id']), 00074 $this->_getWriteAdapter()->quoteInto('website_id=?', $row['website_id']), 00075 $this->_getWriteAdapter()->quoteInto('stock_id=?', $row['stock_id']), 00076 ); 00077 $this->_getWriteAdapter()->update($this->getMainTable(), $bind, $where); 00078 } 00079 else { 00080 $bind = array( 00081 'product_id' => $productId, 00082 'website_id' => $websiteId, 00083 'stock_id' => $stockId, 00084 'qty' => $qty, 00085 'stock_status' => $status 00086 ); 00087 $this->_getWriteAdapter()->insert($this->getMainTable(), $bind); 00088 } 00089 } 00090 00091 return $this; 00092 }