Skip to main content
Share Your Experience: Take the 2024 Developer Survey
40 votes

Magento 2: Programmatically Updating Inventory

This works for me: $item = ['qty' => 11]; // For example $product->setStockData(['qty' => $item['qty'], 'is_in_stock' => $item['qty'] > 0]); $product->save(); Edit: This is no ...
Giel Berkers's user avatar
  • 12.3k
31 votes

inventory_stock_1 doest exist on Magento 2.3

You need elevated permissions to use the CREATE ALGORITHM bit This can and will stop an import in it's tracks. Instead use this statement to create the view CREATE OR REPLACE VIEW `...
Dominic Pixie's user avatar
22 votes

Magento 2: Programmatically Updating Inventory

If you are using the @giel-berkers solution, you may need to set isInStock also, because it will not be automatically sets. So, the following code was useful for me: public function __construct( \...
spiilmusic's user avatar
15 votes
Accepted

inventory_stock_1 doest exist on Magento 2.3

I got the solution for this, you need to create a view table inventory_stock_1 for your catalog in database. Here is the command you need to run in your DB SQL. Make sure to update 3 things in below ...
Pankaj Sharma's user avatar
10 votes

How to get product stock status on the listing page in Magento 2?

You can try the following code public function __construct( \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry ) { $this->stockRegistry = $stockRegistry; } // you can pass $...
Mohit Rane's user avatar
  • 1,965
9 votes

How to get product stock status on the listing page in Magento 2?

If you are using the only simple products in your system then using the Stock Status field check then Product status is Ok. But when you have a configurable or bundle or group product then it is not ...
Amit Bera's user avatar
  • 77.5k
8 votes
Accepted

Magento 1: Relationship Between `qty` in Stock Item, and Stock Status Tables

It looks to me like qty in cataloginventory_stock_item is the source of truth, and qty in cataloginventory_stock_status is the cached/indexed value. Rebuilding the Stock Status index appears to ...
Zeke Farwell's user avatar
8 votes

Magento 2: Programmatically Updating Inventory

I struggled with this same issue. While debugging I found that the product data has a quantity_and_stock_status array, so I tried setting it with: $product->setQuantityAndStockStatus(['qty' => ...
Kevin Chavez's user avatar
8 votes

Magento 2: Programmatically Updating Inventory

One thing the other answers missed is that if you setQty($qty), it will apply the exact value you provide. But if a sale was made for that product a moment before your save, the original qty could ...
cyk's user avatar
  • 293
7 votes
Accepted

Magento 2 stock inventory is not being updated

Check below settings. Admin > Store > Configuration > Catalog > Inventory > Stock option > Decrease Stock When Order is Placed Set it to yes. If you have a multi-website or multi-store then change ...
Chirag Patel's user avatar
  • 6,136
7 votes
Accepted

Magento 2.3 Saleable stock qty does not equal Global Attribute Qty

Check inventory_reservation: https://github.com/magento-engcom/msi/wiki/Salable-Quantity-Calculation-and-Mechanism-of-Reservations If you don't want to use MSI (and stick to CatalogInventory_* from 2....
dudzio's user avatar
  • 620
7 votes
Accepted

Magento 2.3 inventory index gives The product that was requested doesn't exist. Verify the product and try again

Recently we experienced this very issue too. Solution in our case was making sure the inventory_source_item MySQL table does not contain any defunct SKU's. To lookup corrupted records in said table, ...
Ward's user avatar
  • 96
6 votes

Magento 2 stock inventory is not being updated

check your stock setting in admin panel Advance Inventory->manage stock set to yes if you want to reduce quantity
Tirth Patel's user avatar
  • 1,039
6 votes
Accepted

"Only 0 Left" message has suddenly appeared after 2.4.2 upgrade

This is a bug affecting configurable products introduced by the new Magento_InventoryConfigurableProductFrontendUi module in Magento 2.4.2. You can read more about the issue here: https://github.com/...
paj's user avatar
  • 5,874
5 votes
Accepted

How is the qty loaded from database?

$products = Mage::getModel('catalog/product') ->getCollection() //->addAttributeToSelect('*') ->addAttributeToSelect(array('name', 'thumbnail', 'weight' ,'price','description')) ...
Ledian Hymetllari's user avatar
5 votes
Accepted

Magento-2 get all products having product qty less than 5 only

Try this: use Magento\Framework\App\Bootstrap; require DIR . '/../app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $obj = $bootstrap->getObjectManager(); $state = $obj->get(...
kunj's user avatar
  • 3,699
5 votes

Can we clear inventory_reservation table. Magento2.3.1

In Magento 2, main quantity which you see in the qty field of the product might be different than salable quantity. Customers can buy buy products according to salable quantity only. Salable quantity ...
amitshree's user avatar
  • 7,036
5 votes

Magento Inventory Reservation Compensation command not working

This command is waiting for you to tell it what compensation to create. See https://devdocs.magento.com/guides/v2.3/inventory/inventory-cli-reference.html for more detail, but generally, what you want ...
jay's user avatar
  • 443
4 votes

Magento 2: Programmatically Updating Inventory

$objectManager = $bootstrap->getObjectManager(); $stockRegistry = $objectManager->create('Magento\CatalogInventory\Api\StockRegistryInterface'); $stockItem = $stockRegistry->...
MHK Developer's user avatar
4 votes
Accepted

How can I get all email which are all under condition back in stock email alert?

When a customer clicks on Sign up to get notified when this product is back in stock, the customer id is saved in the product_alert_stock table. You can get the customer id using this model: $model =...
Vaibhav Ahalpara's user avatar
4 votes

Magento 2: Low Stock Notification Email to Admin

In magento direct email not sending to the admin. Magento show low stock report at Reports > Product > Low stock For Magento 2.2.x Admin Low Stock Notification email Free extension available in ...
Bharat Patel's user avatar
4 votes
Accepted

Show available inventory on configurable product magento 2

Finally I found a way to show awailable QTY: Override configurable.js: vendor/magento/module-configurable-product/view/frontend/web/js/configurable.js Add : jQuery('.myli').css('display','none')...
Ram Pratap Singh Gour's user avatar
4 votes

How to Track Inventory for Bulk Product

Potatoes sold as 5lb, 25lb or 100lb packages. Like you said set the actual product will be the one with the lowest weight. **(Potatoes 5lb)** This is qty = 1(or you can consider 1 qty = 1lb and ...
Aditya Shah's user avatar
  • 7,617
4 votes

Store level Inventory for individual product Magento 2.2.0

Untill magento 2.2.6 you can not assign / allocate inventory on store level or website level basis. inventory is managed globaly so you will have single inventory across all stores / websites. ...
Naveed Asim's user avatar
  • 3,637
4 votes
Accepted

Magento 2 how to get Multi source inventory names website wise?

I did below as a solution: use Magento\Inventory\Model\ResourceModel\Source\Collection as InventoryCollection; use Magento\Framework\Api\SortOrderBuilder; use Magento\InventoryApi\Api\...
Utsav Gupta's user avatar
  • 1,243
4 votes

Disable stock check / decrease when shipping an order in Magento 2.3.1

~Update ~ Crim is correct. The solution is to disable Magento MSI completely. This is what I ended up doing in my case and works. You're not the only retailer with this issue. After spending some ...
MetalMonkey's user avatar
4 votes

How to get product stock status on the listing page in Magento 2?

Inject \Magento\CatalogInventory\Model\Stock\StockItemRepository $stockItemRepository, in constructor e.g: protected $_stockItemRepository; public function __construct( \Magento\...
Sameer Bhayani's user avatar
4 votes
Accepted

Salable quantity of 0 but still showing in stock?

I was facing the same issue in one of my projects recently. In my case the client wanted to display stock availability label (i.e. Instock/Outofstock) on category pages as well. That is not available ...
Pratik Navapara's user avatar
3 votes
Accepted

How Magento\CatalogInventory\Model\Stock\Item can be replaced in Constructor (DI)

protected $stockItemFactory; public function __construct( ... \Magento\CatalogInventory\Model\Stock\ItemFactory $stockItemFactory, .... ) { .... $this->stockItemFactory = $...
Marius's user avatar
  • 198k
3 votes

Magento 2 - How to get stock of a product?

Look at vendor/magento/module-catalog-inventory/Model/ResourceModel/Stock/Item.php. As we can see, we can use an alternative method loadByProductId(). Navigate to vendor/magento/magento2-base/dev/...
Khoa TruongDinh's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible