Magento 2.3 inventory index gives The product that was requested doesn't exist. Verify the product and try again

magento.stackexchange https://magento.stackexchange.com/questions/334808

Question

The inventory index doesn't get re-indexed, it gives this message:

The product that was requested doesn't exist. Verify the product and try again.

In other questions I found that there could be products without SKU, but there aren't any in my database.

I have read here that the re-indexation process generates a table with virtual stock based (among others) on quantity from assigned stocks. Now I found that there are SKU's in my inventory source (default source) for items I deleted, so products with these SKU's do not exist. Could this cause this issue?

If this causes the issue, what should I delete/update? I do not know in what table this inventory is stored. Or if there are any other sources/tables that need these items deleted.

Was it helpful?

Solution

Recently we experienced this very issue too. Solution in our case was making sure the inventory_source_item MySQL table does not contain any defunct SKU's. To lookup corrupted records in said table, try next MySQL query:

SELECT isi.* FROM inventory_source_item isi LEFT JOIN catalog_product_entity cpe ON isi.sku = cpe.sku WHERE cpe.sku IS NULL;

Removing the resulting rows had the inventory indexer working again.

Seems like a foreign key on the SKU (within the inventory_source_item table, pointing to catalog_product_entity) is lacking. Not sure if such key is missing on purpose, but adding one with ON DELETE CASCADE should prevent the error message from occurring again. Although it is advised to have this confirmed by Magento over a GitHub issue / report. Could not find any related tickets at the moment, so this is still to be reported.

OTHER TIPS

For me the cataloginventory_stock_item & quote_item tables were the offending ones here. Somehow customers with old carts were able to checkout with products that didn't exist. Something to do with their old Magento 1 migration to Magento 2 I think. I tweaked the above query from @Ward like so:

cataloginventory_stock_item

DELETE FROM cataloginventory_stock_item WHERE product_id IN(
        SELECT * FROM (
                SELECT isi.product_id FROM cataloginventory_stock_item isi
                LEFT JOIN catalog_product_entity cpe ON isi.product_id = cpe.entity_id
                WHERE cpe.entity_id IS NULL
       ) AS p
);

quote_item

DELETE FROM quote_item WHERE product_id IN(
        SELECT * FROM (
                SELECT isi.product_id FROM quote_item isi
                LEFT JOIN catalog_product_entity cpe ON isi.product_id = cpe.entity_id
                WHERE cpe.entity_id IS NULL
        ) AS p
);
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top