Public Member Functions | |
getStockId () | |
getProductId () | |
loadByProduct ($product) | |
subtractQty ($qty) | |
addQty ($qty) | |
getStoreId () | |
assignProduct (Mage_Catalog_Model_Product $product) | |
getMinQty () | |
getMinSaleQty () | |
getMaxSaleQty () | |
getNotifyStockQty () | |
getBackorders () | |
getManageStock () | |
getCanBackInStock () | |
checkQty ($qty) | |
checkQuoteItemQty ($qty, $summaryQty, $origQty=0) | |
addCatalogInventoryToProductCollection ($productCollection) | |
getIsInStock () | |
setProduct ($product) | |
Public Attributes | |
const | XML_PATH_GLOBAL = 'cataloginventory/options/' |
const | XML_PATH_CAN_SUBTRACT = 'cataloginventory/options/can_subtract' |
const | XML_PATH_CAN_BACK_IN_STOCK = 'cataloginventory/options/can_back_in_stock' |
const | XML_PATH_ITEM = 'cataloginventory/item_options/' |
const | XML_PATH_MIN_QTY = 'cataloginventory/item_options/min_qty' |
const | XML_PATH_MIN_SALE_QTY = 'cataloginventory/item_options/min_sale_qty' |
const | XML_PATH_MAX_SALE_QTY = 'cataloginventory/item_options/max_sale_qty' |
const | XML_PATH_BACKORDERS = 'cataloginventory/item_options/backorders' |
const | XML_PATH_NOTIFY_STOCK_QTY = 'cataloginventory/item_options/notify_stock_qty' |
const | XML_PATH_MANAGE_STOCK = 'cataloginventory/item_options/manage_stock' |
Protected Member Functions | |
_construct () | |
_addQuoteItemError (Mage_Sales_Model_Quote_Item $item, $itemError, $quoteError, $errorIndex='error') | |
_beforeSave () | |
_afterSave () |
Definition at line 35 of file Item.php.
_addQuoteItemError | ( | Mage_Sales_Model_Quote_Item $ | item, | |
$ | itemError, | |||
$ | quoteError, | |||
$ | errorIndex = 'error' | |||
) | [protected] |
Add error to Quote Item
Mage_Sales_Model_Quote_Item | $item | |
string | $itemError | |
string | $quoteError | |
string | $errorIndex |
Definition at line 410 of file Item.php.
00411 { 00412 $item->setHasError(true); 00413 $item->setMessage($itemError); 00414 $item->setQuoteMessage($quoteError); 00415 $item->setQuoteMessageIndex($errorIndex); 00416 return $this; 00417 }
_afterSave | ( | ) | [protected] |
Processing object after save data
Reimplemented from Mage_Core_Model_Abstract.
Definition at line 466 of file Item.php.
00467 { 00468 parent::_afterSave(); 00469 Mage::getSingleton('cataloginventory/stock_status') 00470 ->changeItemStatus($this); 00471 return $this; 00472 }
_beforeSave | ( | ) | [protected] |
Before save prepare process
Reimplemented from Mage_Core_Model_Abstract.
Definition at line 424 of file Item.php.
00425 { 00426 // see if quantity is defined for this item type 00427 $typeId = $this->getTypeId(); 00428 if ($productTypeId = $this->getProductTypeId()) { 00429 $typeId = $productTypeId; 00430 } 00431 $isQty = Mage::helper('catalogInventory')->isQty($typeId); 00432 00433 if ($isQty) { 00434 if ($this->getBackorders() == Mage_CatalogInventory_Model_Stock::BACKORDERS_NO 00435 && $this->getQty() <= $this->getMinQty()) { 00436 $this->setIsInStock(false) 00437 ->setStockStatusChangedAutomaticallyFlag(true); 00438 } 00439 00440 // if qty is below notify qty, update the low stock date to today date otherwise set null 00441 $this->setLowStockDate(null); 00442 if ((float)$this->getQty() < $this->getNotifyStockQty()) { 00443 $this->setLowStockDate(Mage::app()->getLocale()->date(null, null, null, false) 00444 ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT) 00445 ); 00446 } 00447 00448 $this->setStockStatusChangedAutomatically(0); 00449 if ($this->hasStockStatusChangedAutomaticallyFlag()) { 00450 $this->setStockStatusChangedAutomatically((int)$this->getStockStatusChangedAutomaticallyFlag()); 00451 } 00452 } 00453 else { 00454 $this->setQty(0); 00455 } 00456 00457 Mage::dispatchEvent('cataloginventory_stock_item_save_before', array('item' => $this)); 00458 return $this; 00459 }
_construct | ( | ) | [protected] |
Initialize resource model
Reimplemented from Varien_Object.
Definition at line 55 of file Item.php.
00056 { 00057 $this->_init('cataloginventory/stock_item'); 00058 }
addCatalogInventoryToProductCollection | ( | $ | productCollection | ) |
Add join for catalog in stock field to product collection
Mage_Catalog_Model_Entity_Product_Collection | $productCollection |
Definition at line 395 of file Item.php.
00396 { 00397 $this->_getResource()->addCatalogInventoryToProductCollection($productCollection); 00398 return $this; 00399 }
addQty | ( | $ | qty | ) |
Add quantity process
float | $qty |
Definition at line 122 of file Item.php.
00123 { 00124 if (!$this->getManageStock()) { 00125 return $this; 00126 } 00127 $config = Mage::getStoreConfigFlag(self::XML_PATH_CAN_SUBTRACT); 00128 if (!$config) { 00129 return $this; 00130 } 00131 00132 $this->setQty($this->getQty()+$qty); 00133 return $this; 00134 }
assignProduct | ( | Mage_Catalog_Model_Product $ | product | ) |
Adding stoc data to product
Mage_Catalog_Model_Product | $product |
Definition at line 157 of file Item.php.
00158 { 00159 if (!$this->getId() || !$this->getProductId()) { 00160 $this->_getResource()->loadByProductId($this, $product->getId()); 00161 $this->setOrigData(); 00162 } 00163 00164 $this->setProduct($product); 00165 $product->setStockItem($this); 00166 00167 $product->setIsInStock($this->getIsInStock()); 00168 Mage::getSingleton('cataloginventory/stock_status') 00169 ->assignProduct($product, $this->getStockId(), $this->getStockStatus()); 00170 return $this; 00171 }
checkQty | ( | $ | qty | ) |
Check quantity
decimal | $qty |
Mage_Core_Exception |
Definition at line 268 of file Item.php.
00269 { 00270 if ($this->getQty() - $qty < 0) { 00271 switch ($this->getBackorders()) { 00272 case Mage_CatalogInventory_Model_Stock::BACKORDERS_YES_NONOTIFY: 00273 case Mage_CatalogInventory_Model_Stock::BACKORDERS_YES_NOTIFY: 00274 break; 00275 default: 00276 /*if ($this->getProduct()) { 00277 Mage::throwException( 00278 Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProduct()->getName()) 00279 ); 00280 } 00281 else { 00282 Mage::throwException(Mage::helper('cataloginventory')->__('The requested quantity is not available.')); 00283 }*/ 00284 return false; 00285 break; 00286 } 00287 } 00288 return true; 00289 }
checkQuoteItemQty | ( | $ | qty, | |
$ | summaryQty, | |||
$ | origQty = 0 | |||
) |
Checking quote item quantity
mixed | $qty quantity of this item (item qty x parent item qty) | |
mixed | $summaryQty quantity of this product in whole shopping cart which should be checked for stock availability | |
mixed | $origQty original qty of item (not multiplied on parent item qty) |
Check quantity type
Adding stock data to quote item
Definition at line 299 of file Item.php.
00300 { 00301 $result = new Varien_Object(); 00302 $result->setHasError(false); 00303 00304 if (!is_numeric($qty)) { 00305 $qty = Mage::app()->getLocale()->getNumber($qty); 00306 } 00307 00308 /** 00309 * Check quantity type 00310 */ 00311 $result->setItemIsQtyDecimal($this->getIsQtyDecimal()); 00312 00313 if (!$this->getIsQtyDecimal()) { 00314 $result->setHasQtyOptionUpdate(true); 00315 $qty = intval($qty); 00316 00317 /** 00318 * Adding stock data to quote item 00319 */ 00320 $result->setItemQty($qty); 00321 00322 if (!is_numeric($qty)) { 00323 $qty = Mage::app()->getLocale()->getNumber($qty); 00324 } 00325 $origQty = intval($origQty); 00326 $result->setOrigQty($origQty); 00327 } 00328 00329 if ($this->getMinSaleQty() && ($qty) < $this->getMinSaleQty()) { 00330 $result->setHasError(true) 00331 ->setMessage(Mage::helper('cataloginventory')->__('The minimum quantity allowed for purchase is %s.', $this->getMinSaleQty() * 1)) 00332 ->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in the requested quantity')) 00333 ->setQuoteMessageIndex('qty'); 00334 return $result; 00335 } 00336 00337 if ($this->getMaxSaleQty() && ($qty) > $this->getMaxSaleQty()) { 00338 $result->setHasError(true) 00339 ->setMessage(Mage::helper('cataloginventory')->__('The maximum quantity allowed for purchase is %s.', $this->getMaxSaleQty() * 1)) 00340 ->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products can not be ordered in requested quantity')) 00341 ->setQuoteMessageIndex('qty'); 00342 return $result; 00343 } 00344 00345 if (!$this->getManageStock()) { 00346 return $result; 00347 } 00348 00349 if (!$this->getIsInStock()) { 00350 $result->setHasError(true) 00351 ->setMessage(Mage::helper('cataloginventory')->__('This product is currently out of stock.')) 00352 ->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products are currently out of stock')) 00353 ->setQuoteMessageIndex('stock'); 00354 $result->setItemUseOldQty(true); 00355 return $result; 00356 } 00357 00358 if (!$this->checkQty($summaryQty)) { 00359 $message = Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProductName()); 00360 $result->setHasError(true) 00361 ->setMessage($message) 00362 ->setQuoteMessage($message) 00363 ->setQuoteMessageIndex('qty'); 00364 return $result; 00365 } 00366 else { 00367 if (($this->getQty() - $summaryQty) < 0) { 00368 if ($this->getProductName()) { 00369 $backorderQty = ($this->getQty() > 0) ? ($summaryQty - $this->getQty()) * 1 : $qty * 1; 00370 if ($backorderQty>$qty) { 00371 $backorderQty = $qty; 00372 } 00373 $result->setItemBackorders($backorderQty); 00374 if ($this->getBackorders() == Mage_CatalogInventory_Model_Stock::BACKORDERS_YES_NOTIFY) { 00375 $result->setMessage(Mage::helper('cataloginventory')->__('This product is not available in the requested quantity. %d of the items will be backordered.', 00376 $backorderQty, 00377 $this->getProductName()) 00378 ) 00379 ; 00380 } 00381 } 00382 } 00383 // no return intentionally 00384 } 00385 00386 return $result; 00387 }
getBackorders | ( | ) |
Retrieve backorders status
Definition at line 230 of file Item.php.
00231 { 00232 if ($this->getUseConfigBackorders()) { 00233 return (int) Mage::getStoreConfig(self::XML_PATH_BACKORDERS); 00234 } 00235 return $this->getData('backorders'); 00236 }
getCanBackInStock | ( | ) |
Retrieve can Back in stock
Definition at line 256 of file Item.php.
00257 { 00258 return Mage::getStoreConfigFlag(self::XML_PATH_CAN_BACK_IN_STOCK); 00259 }
getIsInStock | ( | ) |
Retrieve Stock Availability
Definition at line 479 of file Item.php.
00480 { 00481 if (!$this->getManageStock()) { 00482 return true; 00483 } 00484 return $this->_getData('is_in_stock'); 00485 }
getManageStock | ( | ) |
Retrieve Manage Stock data wraper
Definition at line 243 of file Item.php.
00244 { 00245 if ($this->getUseConfigManageStock()) { 00246 return (int) Mage::getStoreConfigFlag(self::XML_PATH_MANAGE_STOCK); 00247 } 00248 return $this->getData('manage_stock'); 00249 }
getMaxSaleQty | ( | ) |
Retrieve Maximum Qty Allowed in Shopping Cart data wraper
Definition at line 204 of file Item.php.
00205 { 00206 if ($this->getUseConfigMaxSaleQty()) { 00207 return (float) Mage::getStoreConfig(self::XML_PATH_MAX_SALE_QTY); 00208 } 00209 return $this->getData('max_sale_qty'); 00210 }
getMinQty | ( | ) |
Retrieve minimal quantity available for item status in stock
Definition at line 178 of file Item.php.
00179 { 00180 if ($this->getUseConfigMinQty()) { 00181 return (float) Mage::getStoreConfig(self::XML_PATH_MIN_QTY); 00182 } 00183 return $this->getData('min_qty'); 00184 }
getMinSaleQty | ( | ) |
Retrieve Minimum Qty Allowed in Shopping Cart data wraper
Definition at line 191 of file Item.php.
00192 { 00193 if ($this->getUseConfigMinSaleQty()) { 00194 return (float) Mage::getStoreConfig(self::XML_PATH_MIN_SALE_QTY); 00195 } 00196 return $this->getData('min_sale_qty'); 00197 }
getNotifyStockQty | ( | ) |
Retrieve Notify for Quantity Below data wraper
Definition at line 217 of file Item.php.
00218 { 00219 if ($this->getUseConfigNotifyStockQty()) { 00220 return (float) Mage::getStoreConfig(self::XML_PATH_NOTIFY_STOCK_QTY); 00221 } 00222 return (float)$this->getData('notify_stock_qty'); 00223 }
getProductId | ( | ) |
getStockId | ( | ) |
getStoreId | ( | ) |
Retrieve Store Id (product or current)
Definition at line 141 of file Item.php.
00142 { 00143 $storeId = $this->getData('store_id'); 00144 if (is_null($storeId)) { 00145 $storeId = Mage::app()->getStore()->getId(); 00146 $this->setData('store_id', $storeId); 00147 } 00148 return $storeId; 00149 }
loadByProduct | ( | $ | product | ) |
Load item data by product
mixed | $product |
Definition at line 87 of file Item.php.
00088 { 00089 if ($product instanceof Mage_Catalog_Model_Product) { 00090 $product = $product->getId(); 00091 } 00092 $this->_getResource()->loadByProductId($this, $product); 00093 $this->setOrigData(); 00094 return $this; 00095 }
setProduct | ( | $ | product | ) |
Add product data to stock item
Mage_Catalog_Model_Product | $product |
Definition at line 493 of file Item.php.
00494 { 00495 $this->setProductId($product->getId()) 00496 ->setProductName($product->getName()) 00497 ->setStoreId($product->getStoreId()) 00498 ->setProductName($product->getName()) 00499 ->setProductTypeId($product->getTypeId()) 00500 ->setProductStatusChanged($product->dataHasChangedFor('status')) 00501 ->setProductChangedWebsites($product->getIsChangedWebsites()); 00502 00503 return $this; 00504 }
subtractQty | ( | $ | qty | ) |
Subtract quote item quantity
decimal | $qty |
Definition at line 103 of file Item.php.
00104 { 00105 if (!$this->getManageStock()) { 00106 return $this; 00107 } 00108 $config = Mage::getStoreConfigFlag(self::XML_PATH_CAN_SUBTRACT); 00109 if (!$config) { 00110 return $this; 00111 } 00112 $this->setQty($this->getQty()-$qty); 00113 return $this; 00114 }
const XML_PATH_BACKORDERS = 'cataloginventory/item_options/backorders' |
const XML_PATH_CAN_BACK_IN_STOCK = 'cataloginventory/options/can_back_in_stock' |
const XML_PATH_CAN_SUBTRACT = 'cataloginventory/options/can_subtract' |
const XML_PATH_GLOBAL = 'cataloginventory/options/' |
const XML_PATH_ITEM = 'cataloginventory/item_options/' |
const XML_PATH_MANAGE_STOCK = 'cataloginventory/item_options/manage_stock' |
const XML_PATH_MAX_SALE_QTY = 'cataloginventory/item_options/max_sale_qty' |
const XML_PATH_MIN_QTY = 'cataloginventory/item_options/min_qty' |
const XML_PATH_MIN_SALE_QTY = 'cataloginventory/item_options/min_sale_qty' |
const XML_PATH_NOTIFY_STOCK_QTY = 'cataloginventory/item_options/notify_stock_qty' |