Hot answers tagged

135 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 ...
user avatar
61 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 ...
user avatar
  • 9,552
23 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 ...
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(...
user avatar
  • 1,473
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' => $...
user avatar
15 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 ...
user avatar
12 votes
Accepted

Magento easy way to show out of stock in configurable product (greyed out)

Warning, using setSkipSaleableCheck(true) appears to have an additional effect of showing disabled products in the dropdown. The function which is affected by this setting is in ...
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\...
user avatar
11 votes
Accepted

Why does Magento have a stock index?

The indexing process writes the values at first in the _idx table so it won't interfere with the read actions on the main table while its running. When all the values are inserted in the _idx table ...
user avatar
  • 196k
10 votes
Accepted

Cron job template block not being translated, but testObserver is

Well, this is a bug indeed, but I came up with a fix! The problem is that Mage_Core_Model_Translate translator isn't initialized by cron.php, since this script doesn't load() translate application ...
user avatar
  • 812
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(...
user avatar
10 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 ...
user avatar
10 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 ...
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 ...
user avatar
9 votes
Accepted

How to allow orders for out-of-stock products?

By changing the settings in System > Config > Inventory will only affect the defaults when you create new products, you still need to enable each product to allow backorders. Easiest way to do ...
user avatar
9 votes
Accepted

Handling multiple stock locations or warehouses

There are at least two ways to implement a multi warehouse in Magento; we discussed about this topic during a Magento U course. The first is that of exploiting the fact that Magento is virtually ...
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 = $...
user avatar
  • 671
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 ...
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 ...
user avatar
  • 9,513
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(); ...
user avatar
7 votes
Accepted

Get stock values for bundled product in product grid

Here is an example how to access the is salable state or the stock quantity of all associated child products. this first method is simply to fetch the child product ids from the bundled product. ...
user avatar
  • 14.4k
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 ...
user avatar
  • 196k
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; ...
user avatar
  • 1,210
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&...
user avatar
6 votes
Accepted

Table "Only X Left" on product page doesn't show product names (only Qty) in Magento 1.9.1.0

It seems that they changed getUsedProducts method in Mage_Catalog_Model_Product_Type_Configurable class. Magento 1.9.0.1 $collection = $this->getUsedProductCollection($product) ->...
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 ...
user avatar
  • 16.6k
6 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 = $...
user avatar
6 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 ...
user avatar
  • 11.5k
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/...
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 ...
user avatar

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