Extending Magento Stock Status Options
Magento’s default stock status options are limited to “In Stock” or “Out of Stock”. However, when dealing with configurable products that require user selection from multiple options, these two statuses may not be sufficient. In this post, we’ll explore how to add additional stock status options in your Magento 1.6.2 installation without resorting to paid extensions.
Understanding the Current Setup
By default, Magento treats “Out of Stock” as a flag that hides all product options from view on the frontend. This is because it assumes that if an item is out of stock, no options should be presented to customers.
For products with long lead times or special order requirements, this behavior presents a problem - you want to display the available options for customer selection even though the item isn’t physically in stock at the moment of ordering.
The Goal: Add Custom Stock Statuses
We aim to create new stock status options like “On Backorder” or “Special Order”, which will allow us to keep our product options visible on the frontend while providing accurate stock information.
Modifying the Database
The first step is to add a new row in the catalog_product_entity_int table. This table stores attribute values for each product, including the stock status:
INSERT INTO catalog_product_entity_int (entity_id, attribute_id, value)
VALUES (
<product_id>, -- Replace with your product ID
(SELECT entity_id FROM eav_attribute WHERE attribute_code = 'stock_status'), -- Stock Status attribute ID
'On Backorder' -- New stock status value
);
Updating the Admin Interface
To make this change visible in the Magento admin interface, you need to modify the status dropdown menu in the product edit form. This is located in:
app/design/adminhtml/default/default/template/catalog/product/edit.phtml
Find the line that begins with <select name="product[stock_status]" id="stock_status">. After the existing options (<option value="in_stock">...</option> and <option value="out_of_stock">...), add your new option:
<option value="on_backorder"><?php echo $this->__('On Backorder') ?></option>
This will create a new selection in the “Stock Status” dropdown menu.
Modifying the Stock Status Display Logic
The core problem lies in how Magento displays product options based on stock status. By default, it hides all options if any parent item is out of stock. We need to override this behavior for our custom status.
Create an observer file at:
app/code/local/YourCompany/Magento-StockStatus/etc/config.xml
Add the following XML configuration:
<config>
<modules>
<YourCompany_Magento-StockStatus>
<version>0.1.0</version>
</YourCompany_Magento-StockStatus>
</modules>
<global>
<events>
<catalog_product_type_prepare_save>
<observers>
<yourcompany_stockstatus_observer>
<type>singleton</type>
<class>YourCompany_MagentoStockStatus_Model_Observer</class>
<method>prepareProductOptionsVisibility</method>
</yourcompany_stockstatus_observer>
</observers>
</catalog_product_type_prepare_save>
</events>
</global>
</config>
Then, create the observer file:
app/code/local/YourCompany/Magento-StockStatus/Model/Observer.php
In this file, override the stock status visibility logic to allow options for your custom statuses (like “On Backorder”):
public function prepareProductOptionsVisibility($observer)
{
$event = $observer->getEvent();
$product = $event->getProduct();
if ($product->getStockStatus() == 'on_backorder') {
foreach ($product->getTypeInstance()->getConfigurableAttributesAsArray($product) as $attr) {
$visibility = $attr['is_required'];
$optionIds = array_keys($attr['options']);
$optionCollection = Mage::getModel('catalog/product')
->getCollection()
->addIdFilter($optionIds)
->addAttributeToSelect('status');
foreach ($optionCollection as $optionProduct) {
if ((int)$optionProduct->getStatus() === 1) {
$visibility = true;
}
}
Mage::app()->getRequest()->setParam('product', $product);
$product->setRequiredOptions($visibility);
}
}
return $this;
}
This observer will override the default behavior for products with your custom stock status, ensuring that all options remain visible on the frontend regardless of physical inventory levels.
Conclusion
Adding additional stock status options to Magento isn’t a built-in feature, but it’s certainly achievable through direct database manipulation and custom coding. By following this guide, you’ve successfully extended your store’s stock management capabilities without resorting to paid extensions or significant core modifications.
Remember to thoroughly test your changes on a staging environment before deploying them to your live site. Magento is a complex system, and while these steps are designed to be safe, there may be edge cases specific to your configuration that require further adjustments.
For more advanced customizations and best practices in Magento development, consider exploring the Magento Development Guide on Laravel Company.