Salable Quantity is showing zero in product grid magento 2?
-
13-02-2021 - |
Domanda
Actually in my case Salable Quantity is showing zero in product grid Magento 2.3.
Due to this issue, products are not showing in frontend. If anyone has any idea then please tell me.
For this re-indexing is also done but still Salable Quantity is showing zero(0).
Add and update Quantity programmatic but Salable Quantity is showing zero .
Altri suggerimenti
I skipped this line of query, due to Previllages error and my add to cart was not working on live server, in local server this line was not skipped and add to cart was working fine.
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY INVOKER VIEW `inventory_stock_1` AS select distinct `legacy_stock_status`.`product_id` AS `product_id`,`legacy_stock_status`.`website_id` AS `website_id`,`legacy_stock_status`.`stock_id` AS `stock_id`,`legacy_stock_status`.`qty` AS `quantity`,`legacy_stock_status`.`stock_status` AS `is_salable`,`product`.`sku` AS `sku` from (`cataloginventory_stock_status` `legacy_stock_status` join `catalog_product_entity` `product` on((`legacy_stock_status`.`product_id` = `product`.`entity_id`))) ;
I'm gonna share my experience related to this issue, I hope it could help someone who would have been in the same situation.
We were working on a staged instance, all was ready to go to production. So we duplicated everything on the prod env and launched some SQL truncates in order to delete every dummy orders, reviews, etc.. you get the idea.
After some final tests, we realized that our products "stock qty" were far different from product "salable qty". The SQL View seemed to work fine, so we investigated deeper. Turns out we missed a SQL table in our truncate instructions :
TRUNCATE TABLE `inventory_reservation`;
This bad girl was containing each "not shipped but reserved products" from past orders.
Of course don't forget to reindex stuff :
bin/magento indexer:reindex;
I had to remove the DEFINER=
root@
localhost from @Thakur answer so here is what I used:
CREATE ALGORITHM=UNDEFINED SQL SECURITY INVOKER VIEW `inventory_stock_1` AS
select distinct `legacy_stock_status`.`product_id` AS `product_id`,
`legacy_stock_status`.`website_id` AS `website_id`,
`legacy_stock_status`.`stock_id` AS `stock_id`,
`legacy_stock_status`.`qty` AS `quantity`,
`legacy_stock_status`.`stock_status` AS `is_salable`,
`product`.`sku` AS `sku`
from (`cataloginventory_stock_status` `legacy_stock_status`
join `catalog_product_entity` `product`
on((`legacy_stock_status`.`product_id` = `product`.`entity_id`))) ;
Failure to remove it caused a privilege error.
Please try the below steps:
Admin -> Stores -> Inventory -> Stock -> Edit Default Stock -> Sales Channels -> select Main Website
It worked fine.
OR find the below link
https://webkul.com/blog/get-salable-quantity-in-magento-2-3/
I was facing the same issue, after creating the view by executing the below query my problem has been resolved.
CREATE ALGORITHM=UNDEFINED DEFINER=`{database_user_name}`@`localhost` SQL SECURITY INVOKER VIEW `inventory_stock_1` AS
SELECT distinct `legacy_stock_status`.`product_id` AS `product_id`,
`legacy_stock_status`.`website_id` AS `website_id`,
`legacy_stock_status`.`stock_id` AS `stock_id`,
`legacy_stock_status`.`qty` AS `quantity`,
`legacy_stock_status`.`stock_status` AS `is_salable`,
`product`.`sku` AS `sku`
FROM
(
`cataloginventory_stock_status` `legacy_stock_status`
join `catalog_product_entity` `product`
on ((`legacy_stock_status`.`product_id` = `product`.`entity_id`))
) ;
Another method to fix this would be to remove the patch from the patch_list
and re-run the setup:upgrade
to re-invoke the command.
The code responsible for creating the SQL SECURITY INVOKER
can be found in
Magento\InventoryCatalog\Setup\Patch\Schema\CreateLegacyStockStatusView.
You can remove the data patch from the patch list by searching running
select * from patch_list where patch_name = 'Magento\InventoryCatalog\Setup\Patch\Schema\CreateLegacyStockStatusView
Delete the record.
Re-run
setup:upgrade
setup:di:compile
setup:static-content:deploy
Re-save the products with ZERO Salable Quantity either one by one or mass action via admin.
I just changed to STORE -> CATELOG -> INVENTORY -> PRODUCTS STOCK OPTIONS -> BACKORDERS -> Allow Qty Below 0
and the issue solved