How to Add a Custom Inventory Attribute Programmatically

Continuing our posts dedicated to Magento inventory, in this post we will see how you can add a custom inventory attribute programmatically. Let's do it.

In our previous post we had a short introduction about Magento Multi-Source Inventory (MSI). When more than one source is created in your store then a new section on product edit page in admin is shown. There you can assign sources to the product and define quantity source item status per each source. Except from these two options, you can also define globally some more product inventory options by clicking on "Advanced Inventory" button. The configuration there is global defined and not per source. If you want to create another option / inventory attribute you will need to add it firstly in the database and more specific to the cataloginventory_stock_item table.

Afterwards to show that new attribute to the Advanced Inventory are in admin, you will need to adjust the form layout like below.

The "Advanced Inventory" product area in admin will look like below.

Furthermore, to see how you can set a value to that new attribute, we have created for our post a StockManagement class with an update called function to set a value to the coming_soon attribute.

The full example as extension can be found here.

Feel free to share this post and ask your questions in the comments below.

Till next time!

DigitalOcean Referral Badge