Hot answers tagged

137 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
63 votes
Accepted

How to get stock quantity of each product in Magento 2

Solution:1 Create Helper file Stock.php in your module <?php namespace {VendorName}\{ModuleName}\Helper; class Stock extends \Magento\Framework\App\Helper\AbstractHelper { /** * @var ...
Abdul's user avatar
  • 9,692
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
19 votes

Get product stock quantity in magento

It's working for me. $products = Mage::getModel('catalog/product')->getCollection(); foreach ($products as $_product) { $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct(...
Ajay Patel's user avatar
  • 1,513
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
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
11 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
10 votes
Accepted

Get product stock quantity in magento

You will need to join the table to get qty. See below code: $products = Mage::getModel('catalog/product') ->getCollection() //->addAttributeToSelect('*') ->addAttributeToSelect(...
Adarsh Khatri'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
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 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 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,849
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

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.6k
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
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,348
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

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
6 votes
Accepted

Product with different sub qty levels

Magento does have composite products (bundles and configurables), but does not do what you want out of the box, at least not in a way that would then make sense to the customer. You're actually ...
benmarks's user avatar
  • 16.7k
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

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
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
  • 343
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.2k
6 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,031
5 votes
Accepted

Low stock on category page

You have to get the stock qty from your product. The product model does not contain a stock qty so you have to get the right model (cataloginventory/stock_item) to get the stock qty. You can get the ...
Wouter Steenmeijer's user avatar

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