18

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 .

11
  • try to allow out of stock backorder and check if the products will be displayed. This is not a fix but at least to check wether the exact problem is the salable qty.
    – fmsthird
    Commented Jan 8, 2019 at 3:42
  • have you fixed it?
    – fmsthird
    Commented Jan 9, 2019 at 4:17
  • yes actually there was a permission problem in our server Commented Jan 9, 2019 at 4:52
  • Hi, Have you found out the issue?
    – Octopus
    Commented Feb 6, 2019 at 9:33
  • 1
    @Octopus,yes reindex worked always but there was permission in server then it is resolved Commented Feb 6, 2019 at 9:46

8 Answers 8

22

In DataBase, There was two type,

  1. Tables

  2. Views

The issue is possibly caused when Import/Export DataBase Views was not created in Magento 2.3. So create Views and inventory_stock_1 table in DataBase.

See Attached Image:

enter image description here

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`))) ;
4
  • 1
    Thank you so much. After spending 2 hours I got the solutions from your answer. Thanks again. Commented Jun 29, 2019 at 15:33
  • @Savan its already created at my end. but still facing same issue Commented Aug 15, 2019 at 6:50
  • @insoftservice I am facing the same issue, did you get any idea? Commented Oct 8, 2019 at 10:07
  • @HardikVisa do you have this view at your end. If yes just try to execute it manually at my end it was given permission issue which got resolved by granting full permission. Commented Oct 8, 2019 at 12:12
18

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
3
  • This did the trick for me. I was struggling to remove negative salable quantity. Commented Jun 24, 2020 at 2:07
  • What will happen if there are current orders in production. Will re-indexing reduce the default stock for other items in orders after truncating the table?
    – hablema
    Commented Apr 5, 2021 at 8:10
  • In my case, I just run indexer command and QTY started showing perfectly!!! Thanks +1 , made my day :) Commented Aug 26, 2021 at 6:34
11

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`))) ;

Because the View was not created in the live server enter image description here

0
4

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.

2

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/

0

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`))
   ) ;
0

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.

-10

I just changed to STORE -> CATELOG -> INVENTORY -> PRODUCTS STOCK OPTIONS -> BACKORDERS -> Allow Qty Below 0

and the issue solved

1
  • That's not what back order meant to be used for.
    – Korbin
    Commented May 11, 2023 at 13:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.