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 ...
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 ...
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 ...
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(...
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' => $...
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 ...
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\...
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 ...
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 ...
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(...
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 ...
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 = $...
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 ...
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 ...
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();
...
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 = $...
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 ...
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 ...
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;
...
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&...
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 ...
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 ...
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/...
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 ...
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 ...
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);
$...
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 $...
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/...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
stock × 507magento2 × 164
product × 84
inventory × 84
magento-1.9 × 79
out-of-stock × 52
quantity × 44
stock-status × 43
configurable-product × 38
event-observer × 22
magento2.3 × 19
manage-stock × 18
magento-1.7 × 17
cataloginventory × 17
magento-2.1 × 14
magento-1.8 × 12
orders × 12
collection × 11
products × 11
msi × 11
php × 10
database × 9
magento-1 × 9
import × 9
catalog × 9