In this blog, we will discuss how Stocks work in magento. There are certain setting which we can do from Magento Core files and from System > Configuration.
Firstly we will see what we can do from Magento Admin Panel
Configuring the Inventory Stock Options
- From the Admin panel, select System > Configuration.
- In the Configuration panel on the left, under Catalog, select Inventory.
- Click to expand the Stock Options section. Then, do the following:
- If you want to show the OutOfStock products on the Frontend then set Yes Includes “out of stock” products in the list else set No to “out of stock” products from the lists.
- If you want to display of the stock availability message on the product detail page, set Display products availability in stock in the frontend to Yes else set No
- Click to expand the Product Stock Options section. Then, do the following:
- If you want the inventory options are available for this single product to manage your inventory then goto Manage Stock and set Yes else set No to Manage Stock
- If you want that customer can order a product even if its quantity is below 0 then goto Backorders and from there we can set Allow Quantity Below 0 or we can set Allow Quantity Below 0 and Notify Customer or if we dont want the customer to order a praticular product if its quantity is below 0 then we can set No BackOrders
- Click the Save Config button to save the setting.
Secondly,we can also work with Magento Stock Inventory Core files.
For that, Magento has a specific module for handling the Stock, named as ‘ StockInventory ‘. Basically how it works, whenever we add a product to cart it goes to checkQuoteItemQty()
function of Mage_CatalogInventory_Model_Observer
Observer. This function checks whether the requested product is in Stock or not. If the quantity of that particular product is available then it goes to checkQuoteItemQty()
function of Mage_CatalogInventory_Model_Stock_Item
and again it reverifies for product availability and if it is available then it added that product to cart else it throws an error message showing ‘ This product is currently out of stock ‘.
So, from there you can also add the product directly to the cart without checking the product availability by modifying both the files. Most of the Stock related Operations are managed from these two files.
Next we have a Resource Model class named Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default
for simple, virtual and downloadable products, Mage_CatalogInventory_Model_Resource_Indexer_Stock_Configurable
for configurable products and Mage_CatalogInventory_Model_Resource_Indexer_Stock_Grouped
for Grouped Products which manages the Stock of Magento Products. These classes used for reindexing of the Stock Inventory.
Basically what these Resource Model files does is that it changes the Stock_Status whenever admin Reindex the Product Prices or Stock Status according to the Quantity Availability.
Whenever we place an order in Magento, the quantity of product reduces, and then again product that is ordered is reindexed. This is done by _updateIndex()
function of the Mage_CatalogInventory_Model_Resource_Indexer_Stock_Default
class which checks the quantity availability and changes the Stock_Status accordingly.
The post How to manage Stock Classes in Magento appeared first on Excellence Technologies Magento Blog | Magento Tutorials | Magento Developer.