Allowing Back Orders in Magento on Out of Stock Products
Date: 17 Jul 2017
You want to be able to take orders for products that are "out of stock" in Magento, but it just isn't playing ball. What do you do now?
Back orders allow you order products that are out-of-stock, so even if they are out of stock in your warehouse, but your supplier has it in stock, you can still get it in time for the customer and make that sale.
Back Orders in Magento on Out of Stock Products
A part of Magento’s native behaviour is to allow you to take back orders on specified products after the item’s quantity has dropped below zero.
In order to achieve this, though, you have to tell Magento in the Admin:
(System -> Configuration -> [Catalog tab] Inventory -> Product Stock Options).
This works great, until you realise that you want this in place only after you’ve uploaded 15,000 products.
Then you find that this setting only kicks in on products created after those changes have been made.
So the products you already have in your store, unlike new products created after your settings have changed, continue to go “Out of Stock” when they hit a zero quantity, which in turn prevents back orders being taken.
Talk about complicated!
We Solved It
The solution turned out to be relatively simple.
Magento’s `cataloginventory_stock_item` table in the database has a row for every product for each store (obviously if you only have a single store then the ratio of records in here is one row for every one product).
We looked into the different between two products, one created before the settings change and one created after, and noticed the following;
- is_in_stock was set to zero
- manage_stock was set to one
- use_config_manage_stock was set to zero
Changing these field values to their binary opposite did exactly what we needed so, on the basis that we only needed to do so for the simple products in the site, we ran the following;
SET `is_in_stock` = 1, `manage_stock` = 0, `use_config_manage_stock` = 1
WHERE `item_id` IN (SELECT `entity_id` FROM `catalog_product_entity` WHERE `catalog_product_entity`.`type_id` = "simple")
AND `stock_id` = 1
The `stock_id` value can be found in `cataloginventory_stock` where, as mentioned, if you’re running a single store then you’ll only have one entry in any case.
If you want to run this command across all stores then you can remove the last line of the SQL statement above completely.