Public Member Functions | |
lockProductItems ($stock, $productIds) | |
setInStockFilterToCollection ($collection) | |
updateSetOutOfStock () | |
updateSetInStock () | |
updateLowStockDate () | |
Protected Member Functions | |
_construct () | |
_initConfig () | |
Protected Attributes | |
$_isConfig | |
$_isConfigManageStock | |
$_isConfigBackorders | |
$_configMinQty | |
$_configTypeIds | |
$_configNotifyStockQty | |
$_stock |
Definition at line 34 of file Stock.php.
_construct | ( | ) | [protected] |
Resource initialization
Reimplemented from Mage_Core_Model_Resource_Abstract.
Definition at line 44 of file Stock.php.
00045 { 00046 $this->_init('cataloginventory/stock', 'stock_id'); 00047 }
_initConfig | ( | ) | [protected] |
Load some inventory configuration settings
Definition at line 99 of file Stock.php.
00100 { 00101 if (!$this->_isConfig) { 00102 $this->_isConfig = true; 00103 $this->_isConfigManageStock = (int)Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK); 00104 $this->_isConfigBackorders = (int)Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_BACKORDERS); 00105 $this->_configMinQty = (int)Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MIN_QTY); 00106 $this->_configNotifyStockQty = (int)Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_NOTIFY_STOCK_QTY); 00107 $this->_configTypeIds = array_keys(Mage::helper('catalogInventory')->getIsQtyTypeIds(true)); 00108 $this->_stock = Mage::getModel('cataloginventory/stock'); 00109 } 00110 }
lockProductItems | ( | $ | stock, | |
$ | productIds | |||
) |
We use write adapter for resolving problems with replication
Definition at line 49 of file Stock.php.
00050 { 00051 $itemTable = $this->getTable('cataloginventory/stock_item'); 00052 $select = $this->_getReadAdapter()->select() 00053 ->from($itemTable) 00054 ->where('stock_id=?', $stock->getId()) 00055 ->where('product_id IN(?)', $productIds) 00056 ->forUpdate(true); 00057 /** 00058 * We use write adapter for resolving problems with replication 00059 */ 00060 $this->_getWriteAdapter()->query($select); 00061 return $this; 00062 }
setInStockFilterToCollection | ( | $ | collection | ) |
add join to select only in stock products
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection | $collection |
Definition at line 70 of file Stock.php.
00071 { 00072 $manageStock = Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK); 00073 $cond = array( 00074 '{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=1 AND {{table}}.is_in_stock=1', 00075 '{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=0', 00076 ); 00077 00078 if ($manageStock) { 00079 $cond[] = '{{table}}.use_config_manage_stock = 1 AND {{table}}.is_in_stock=1'; 00080 } 00081 else { 00082 $cond[] = '{{table}}.use_config_manage_stock = 1'; 00083 } 00084 00085 $collection->joinField( 00086 'inventory_in_stock', 00087 'cataloginventory/stock_item', 00088 'is_in_stock', 00089 'product_id=entity_id', 00090 '('.join(') OR (', $cond) . ')' 00091 ); 00092 return $this; 00093 }
updateLowStockDate | ( | ) |
Update items low stock date basing on their quantities and config settings
Definition at line 161 of file Stock.php.
00162 { 00163 $nowUTC = Mage::app()->getLocale()->date(null, null, null, false)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); 00164 $this->_initConfig(); 00165 $this->_getWriteAdapter()->update($this->getTable('cataloginventory/stock_item'), 00166 array('low_stock_date' => new Zend_Db_Expr(sprintf('CASE 00167 WHEN (use_config_notify_stock_qty = 1 AND qty < %d) OR (use_config_notify_stock_qty = 0 AND qty < notify_stock_qty) 00168 THEN %s ELSE NULL 00169 END 00170 ', $this->_configNotifyStockQty, $this->_getWriteAdapter()->quote($nowUTC) 00171 ))), 00172 sprintf('stock_id = %d 00173 AND (use_config_manage_stock = 1 AND 1 = %d OR use_config_manage_stock = 0 AND manage_stock = 1) 00174 AND product_id IN (SELECT entity_id FROM %s WHERE type_id IN (%s))', 00175 $this->_stock->getId(), 00176 $this->_isConfigManageStock, 00177 $this->getTable('catalog/product'), $this->_getWriteAdapter()->quote($this->_configTypeIds) 00178 )); 00179 }
updateSetInStock | ( | ) |
Set items in stock basing on their quantities and config settings
Definition at line 139 of file Stock.php.
00140 { 00141 $this->_initConfig(); 00142 $this->_getWriteAdapter()->update($this->getTable('cataloginventory/stock_item'), 00143 array('is_in_stock' => 1), 00144 sprintf('stock_id = %d 00145 AND is_in_stock = 0 00146 AND stock_status_changed_automatically = 1 00147 AND (use_config_manage_stock = 1 AND 1 = %d OR use_config_manage_stock = 0 AND manage_stock = 1) 00148 AND (use_config_min_qty = 1 AND qty > %d OR use_config_min_qty = 0 AND qty > min_qty) 00149 AND product_id IN (SELECT entity_id FROM %s WHERE type_id IN (%s))', 00150 $this->_stock->getId(), 00151 $this->_isConfigManageStock, 00152 $this->_configMinQty, 00153 $this->getTable('catalog/product'), $this->_getWriteAdapter()->quote($this->_configTypeIds) 00154 )); 00155 }
updateSetOutOfStock | ( | ) |
Set items out of stock basing on their quantities and config settings
Definition at line 116 of file Stock.php.
00117 { 00118 $this->_initConfig(); 00119 $this->_getWriteAdapter()->update($this->getTable('cataloginventory/stock_item'), 00120 array('is_in_stock' => 0, 'stock_status_changed_automatically' => 1), 00121 sprintf('stock_id = %d 00122 AND is_in_stock = 1 00123 AND (use_config_manage_stock = 1 AND 1 = %d OR use_config_manage_stock = 0 AND manage_stock = 1) 00124 AND (use_config_backorders = 1 AND %d = %d OR use_config_backorders = 0 AND backorders = %d) 00125 AND (use_config_min_qty = 1 AND qty <= %d OR use_config_min_qty = 0 AND qty <= min_qty) 00126 AND product_id IN (SELECT entity_id FROM %s WHERE type_id IN (%s))', 00127 $this->_stock->getId(), 00128 $this->_isConfigManageStock, 00129 Mage_CatalogInventory_Model_Stock::BACKORDERS_NO, $this->_isConfigBackorders, Mage_CatalogInventory_Model_Stock::BACKORDERS_NO, 00130 $this->_configMinQty, 00131 $this->getTable('catalog/product'), $this->_getWriteAdapter()->quote($this->_configTypeIds) 00132 )); 00133 }