/** * Lock product items * * @param Mage_CatalogInventory_Model_Stock $stock * @param int|array $productIds * @return Mage_CatalogInventory_Model_Resource_Stock */ public function lockProductItems($stock, $productIds) { $itemTable = $this->getTable('cataloginventory/stock_item'); $select = $this->_getWriteAdapter()->select()->from($itemTable)->where('stock_id in IN(?)', $stock->getStockIds())->where('product_id IN(?)', $productIds)->forUpdate(true); /** * We use write adapter for resolving problems with replication */ $this->_getWriteAdapter()->query($select); return $this; }
/** * @param Varien_Object $item * @return $this|Mage_CatalogInventory_Model_Stock */ public function registerItemSale(Varien_Object $item) { if (Mage::helper("shopgate")->isShopgateApiRequest() && Mage::helper("shopgate/config")->getIsMagentoVersionLower15()) { return $this; } return parent::registerItemSale($item); }
/** * Retrieve stock identifier * * @return int */ public function getId() { if ($this->getIdFieldName()) { return $this->_getData($this->getIdFieldName()); } else { return parent::getId(); } }
/** * Delete a stock. * * @return $this|Mage_Core_Model_Abstract */ public function delete() { if (intval($this->getId()) == self::DEFAULT_STOCK_ID) { Mage::logException(new Exception('default or unknown stock can\'t be deleted')); } else { parent::delete(); } return $this; }
/** * Update items low stock date basing on their quantities and config settings * */ public function updateLowStockDate() { $this->_initConfig(); $adapter = $this->_getWriteAdapter(); $condition = $adapter->quoteInto('(use_config_notify_stock_qty = 1 AND qty < ?)', $this->_configNotifyStockQty) . ' OR (use_config_notify_stock_qty = 0 AND qty < notify_stock_qty)'; $currentDbTime = $adapter->quoteInto('?', $this->formatDate(true)); $conditionalDate = $adapter->getCheckSql($condition, $currentDbTime, 'NULL'); $value = array('low_stock_date' => new Zend_Db_Expr($conditionalDate)); $select = $adapter->select()->from($this->getTable('catalog/product'), 'entity_id')->where('type_id IN(?)', $this->_configTypeIds); $where = sprintf('stock_id = %1$d' . ' AND ((use_config_manage_stock = 1 AND 1 = %2$d) OR (use_config_manage_stock = 0 AND manage_stock = 1))' . ' AND product_id IN (%3$s)', $this->_stock->getId(), $this->_isConfigManageStock, $select->assemble()); $adapter->update($this->getTable('cataloginventory/stock_item'), $value, $where); }
/** * Correct particular stock products qty based on operator * * @param Mage_CatalogInventory_Model_Stock $stock * @param array $productQtys array($productId => $qty) * @param string $operator +/- * @return Mage_CatalogInventory_Model_Mysql4_Stock */ public function correctItemsQty($stock, $productQtys, $operator = '-') { if (empty($productQtys)) { return $this; } $query = 'UPDATE ' . $this->getTable('cataloginventory/stock_item') . ' SET `qty`=CASE `product_id` '; foreach ($productQtys as $productId => $qty) { $query .= $this->_getWriteAdapter()->quoteInto(' WHEN ? ', $productId); $query .= $this->_getWriteAdapter()->quoteInto(' THEN `qty`' . $operator . '? ', $qty); } $query .= ' ELSE `qty` END'; $query .= $this->_getWriteAdapter()->quoteInto(' WHERE `product_id` IN (?)', array_keys($productQtys)); $query .= $this->_getWriteAdapter()->quoteInto(' AND `stock_id` =?', $stock->getId()); $this->_getWriteAdapter()->beginTransaction(); $this->_getWriteAdapter()->query($query); $this->_getWriteAdapter()->commit(); return $this; }
public function revertProductsSale($items) { parent::revertProductsSale($items); Mage::dispatchEvent('cataloginventory_stock_revert_products_sale', array('items' => $items)); return $this; }