/** * Update the stock item "is_in_stock" status * * @param Mage_CatalogInventory_Model_Stock_Item $stockItem Stock item for the product being updated * @param int $quantity Inventory quantity stock item is being set to * @return bool if a change was made */ protected function updateProductInStockStatus(Mage_CatalogInventory_Model_Stock_Item $stockItem, $quantity) { $shouldSet = $quantity > $stockItem->getMinQty(); $change = $shouldSet !== $stockItem->getIsInStock(); if ($change) { $stockItem->setIsInStock($shouldSet); } return $change; }
/** * Change Stock Item status process * * @param Mage_CatalogInventory_Model_Stock_Item $item * @return Mage_CatalogInventory_Model_Stock_Status */ public function changeItemStatus(Mage_CatalogInventory_Model_Stock_Item $item) { $productId = $item->getProductId(); if (!($productType = $item->getProductTypeId())) { $productType = $this->getProductType($productId); } $status = (int) $item->getIsInStock(); $qty = (int) $item->getQty(); $this->_processChildren($productId, $productType, $qty, $status, $item->getStockId()); $this->_processParents($productId, $item->getStockId()); return $this; }
public function getIsInStock() { $result = $this->getAlwaysInStock() || parent::getIsInStock(); Mage::dispatchEvent('udropship_stock_item_getIsInStock', array('item' => $this, 'vars' => array('result' => &$result))); return $result; }
/** * Set inventory data to custom attribute * * @param Varien_Object $object * @return Mage_Eav_Model_Entity_Attribute_Backend_Abstract */ public function afterLoad($object) { $this->_inventory->loadByProduct($object); $object->setData($this->getAttribute()->getAttributeCode(), array('is_in_stock' => $this->_inventory->getIsInStock(), 'qty' => $this->_inventory->getQty())); return parent::afterLoad($object); }
public function insertStockHistory(Mage_CatalogInventory_Model_Stock_Item $stockItem, $message = '') { Mage::getModel('jr_stockhistory/stock_history')->setItemId($stockItem->getId())->setUser($this->_getUsername())->setUserId($this->_getUserId())->setQty($stockItem->getQty())->setIsInStock((int) $stockItem->getIsInStock())->setMessage($message)->save(); Mage::getModel('catalog/product')->load($stockItem->getProductId())->cleanCache(); }
public function insertStockMovement(Mage_CatalogInventory_Model_Stock_Item $stockItem, $message = '') { if ($stockItem->getId()) { Mage::getModel('bubble_stockmovements/stock_movement')->setItemId($stockItem->getId())->setUser($this->_getUsername())->setUserId($this->_getUserId())->setIsAdmin((int) Mage::getSingleton('admin/session')->isLoggedIn())->setQty($stockItem->getQty())->setIsInStock((int) $stockItem->getIsInStock())->setMessage($message)->save(); Mage::getModel('catalog/product')->load($stockItem->getProductId())->cleanCache(); } }
/** * Creates a new StockMovement object and commits to database. * * @param Mage_CatalogInventory_Model_Stock_Item $stockItem * @param string $message * @param null $origQty */ public function insertStockMovement($stockItem, $message = '', $origQty = null) { if ($stockItem->getId()) { $origQty = $origQty !== null ? $origQty : $stockItem->getOriginalInventoryQty(); // Do not create entry if the quantity hasn't changed if ($origQty == $stockItem->getQty()) { return; } Mage::getModel('bubble_stockmovements/stock_movement')->setItemId($stockItem->getId())->setUser($this->_getUsername())->setUserId($this->_getUserId())->setIsAdmin((int) Mage::getSingleton('admin/session')->isLoggedIn())->setQty($stockItem->getQty())->setOriginalQty($origQty !== null ? $origQty : $stockItem->getOriginalInventoryQty())->setIsInStock((int) $stockItem->getIsInStock())->setMessage($message)->save(); } }