Skip to main content
138 votes
Accepted

Magento 2 How to unlock reindex process

You can reset the indexer through command line with indexer:reset command. This will give the list of indexes name: php bin/magento indexer:info Output: design_config_grid ...
Mukesh Chapagain's user avatar
26 votes

How to get stock quantity of each product in Magento 2

Like some comments have mentioned, you want to use dependency injection. Do not use the object manager; in other words, do not do what any of the other responses state. The following technique can be ...
danemacmillan's user avatar
18 votes
Accepted

Magento 2: Set product stock programmatically

Can you please try below code? It will save inventory data. $product->setStockData(['qty' => $stockData, 'is_in_stock' => $stockData]); $product->setQuantityAndStockStatus(['qty' => $...
Suresh Chikani's user avatar
17 votes

Magento 2 How to unlock reindex process

When I faced this kind of situation I had to run the following SQL query directly into the database: UPDATE indexer_state SET status = 'valid'; I was not able to to find any option to force ...
Aurélien FOUCRET's user avatar
13 votes

Showing Salable QTY in frontend Magento 2.3

The definition of salable quantity includes the quantity minQty. Nowadays MSI is the approach. So no other methods, shortcuts, objectmanagers or M1 flashback code. It all has to be an MSI approach ...
Mavis Bacon's user avatar
12 votes

How to get stock quantity of each product in Magento 2

How to get stock quantity of each product in Magento 2 for controller or block inject \Magento\CatalogInventory\Api\StockStateInterface public function __construct( \Magento\CatalogInventory\...
Surendra Kumar Ahir's user avatar
11 votes
Accepted

Differences between some stock methods

isSaleable() is just an alias of isSalable() : /** * Alias for isSalable() * * @return bool */ public function isSaleable() { return $this->isSalable(); } The isSalable() method looks ...
Raphael at Digital Pianism's user avatar
10 votes
Accepted

Downloadable product on Magento 2.3.1 out of stock issue

In our case the issue was related to a migration from Magento 1 to Magento 2 via migration data tool. The problem is that default value for the attribute 'links_exist' is 0 in Magento 1. However in ...
mbernt - mediarox's user avatar
9 votes

Magento 2 How to unlock reindex process

On MySQL run: SET SQL_SAFE_UPDATES = 0; update indexer_state set status = 'invalid' where status != 'valid'; Then on your terminal run: php bin/magento indexer:reindex It normally happens when ...
Jackson's user avatar
  • 9,939
9 votes
Accepted

How to get salable qty in magento 2.3.3?

<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $StockState = $objectManager->get('\Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku'); $qty = $...
Haerriz's user avatar
  • 681
8 votes
Accepted

magento 2 event cataloginventory_stock_item_save_after

This is a bug. Basically those events are dispatched dynamically in Magento\Framework\Model\AbstractModel in the afterSave() method: public function afterSave() { $this->cleanModelCache(); ...
Raphael at Digital Pianism's user avatar
7 votes

Why are there 3 identical tables in Magento2?

the cataloginventory_stock_status is the one that is used for reading in the frontend. In order to not interfere with the table reads, when the stock index is running it is writing in the _tmp and/or ...
Marius's user avatar
  • 198k
7 votes

How to get stock quantity of each product in Magento 2

The below script will be helpful to get the product stock qty, min qty and stock details in magento2. $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productStockObj = $...
Tapas Ranjan's user avatar
7 votes

Get product stock quantity in magento

Adding stock information to product collections can be done with a single line: /* Mage_Catalog_Model_Resource_Product_Collection */ $products->setFlag('require_stock_items', true); This flag is ...
sv3n's user avatar
  • 11.7k
7 votes
Accepted

Get only the in stock simple products of a configurable product

You can use Model StockRegistry Magento\CatalogInventory\Model\StockRegistry $stockRegistry Register a Block or Helper. My code example use Helper. class Data { protected $catalogProduct; ...
HoangHieu's user avatar
  • 1,358
7 votes
Accepted

How to get all simple product's quantity and SKU with SQL Query

Use following query : "SELECT cpe.sku, csi.qty FROM catalog_product_entity cpe RIGHT JOIN cataloginventory_stock_item csi ON cpe.entity_id = csi.item_id GROUP BY cpe.sku ORDER BY cpe.sku ASC&...
Sunil Verma's user avatar
7 votes

IN STOCK FILTER FOR Magento 2 Product collection

You can also try below code $pCollection = $this->getObjectManager()->create('Magento\Catalog\Model\ResourceModel\Product\Collection'); $pCollection->setStoreId($storeId); $...
Hardik Patel's user avatar
7 votes

Magento 2 : We cant place the order : SQLSTATE[HY000]: General error: 1449 The user specified as a definer your_db_user@% does not exist

After migrating the site I got the above error on placing the order. The user that was trying to access the DB is an old server DB user which didn't exist in the new server. I searched for the user in ...
Mrugesh Mistry's user avatar
7 votes
Accepted

Magento 2.4.4 - Unable to place order: There are no source items with the in stock status

Whenever we will upgrade Magento 2.3.X version to Magento 2.4.3 at that time Multi-Source Inventory Issue happens. To solve that issue need to follow the below steps. Step #1 First Disable all MSI ...
Darshan modi's user avatar
  • 1,071
6 votes
Accepted

Magento 2.1 Update Product Stock in Cron Job

I'm not sure about your data array which contains the SKU product and Stock value. So, I will use simple data. We can update product stock via API: vendor/magento/module-catalog-inventory/Model/...
Khoa TruongDinh's user avatar
6 votes

Get stock for a product in Magento 2

It mainly depends on the file where you want to display it. First you need to find out the block where you want to display that info. Then you'll have to setup a preference for that block in a ...
Raphael at Digital Pianism's user avatar
6 votes

Differences between some stock methods

These all are methods which checked the product availability with different parameters . isInStock() - Its just check the product is in stock or not. And for this its check the product attribute ...
Ashish Jagnani's user avatar
6 votes
Accepted

How to set qty to product on MSI Magento 2.3

Here you go! /** * @var Magento\InventoryApi\Api\SourceItemsSaveInterface */ protected $sourceItemsSave; /** * @var Magento\InventoryApi\Api\Data\SourceItemInterfaceFactory */ protected $...
Sondre's user avatar
  • 353
6 votes
Accepted

Magento 2: Rest API add "stock_item" in to the list of the products

Magento2 does not suggest to add stock info to listing Api a MSI add to 2.3 version. But if you want don't use MSI to your system then you can below solution 1.Create di.xml at your app/code/...
Amit Bera's user avatar
  • 77.6k
6 votes

Magento 2.4 get stock qty after the product is saved in plugin

Intro MSI stock works differently from the previous CatalogInventory stock. To explain how to get the stock properly i first need to explain how MSI works. However i will state this beforehand, it is ...
Gohil Rajesh's user avatar
  • 2,955
5 votes

How to display stock information on product page?

you can check product is in stock via below code $stockItem = $product->getStockItem(); if ($stockItem->getIsInStock()) { //in stock! } else { //not in stock! }
Murtuza Zabuawala's user avatar
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

Magento 2 : We cant place the order : SQLSTATE[HY000]: General error: 1449 The user specified as a definer your_db_user@% does not exist

As far as I'm aware they've created only one view table If you use mysqldump you end up with this CREATE ALGORITHM=UNDEFINED DEFINER=`dbusername`@`localhost` SQL SECURITY INVOKER VIEW `...
Dominic Pixie's user avatar
5 votes
Accepted

Proper way to update stock in >= 2.4?

In order to use the new API to update stock, add this to the constructor: public function __construct( \Magento\InventoryApi\Api\SourceItemsSaveInterface $sourceItemsSaveInterface, \Magento\...
Sergey Uskov's user avatar
4 votes

Magento2 cannot add stock data via StockItemInterface

Just to simplify this answer further without the need for 'Magento\CatalogInventory\Model\ResourceModel\Stock\Item' and provide a full example with dependency injection, which is the "Magento way" of ...
Lance's user avatar
  • 281

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