AI Reports

Guides › Stock

How to find out-of-stock products that are still selling

Short answer: combine two lists, products that are out of stock and products that sold recently. In the admin that means two screens and a spreadsheet; the query below gives you one restock list, sorted by how many sold.

In the admin

  1. Go to Catalog › Products, open Filters, and set Quantity from 0 to 0. Add the Salable Quantity column if you use several sources.
  2. Go to Reports › Products › Ordered and choose the last 30 days.
  3. Match the two lists by product name or SKU in a spreadsheet.

With one query

Products that are out of stock now and sold in the last 30 days (canceled and refunded orders left out), most sold first. For configurable products it lists the exact variant that sold, such as a size and colour, because that's what you restock. The same query works on Open Source and Adobe Commerce.

These queries only read data. Run them on a copy of your database if you can, or ask your developer to. If your tables have a prefix (set in app/etc/env.php), add it to each table name.

SELECT
  i.sku,
  MAX(i.name)          AS name,
  si.qty               AS stock_qty,
  SUM(i.qty_ordered)   AS sold_last_30_days
FROM sales_order_item i
JOIN sales_order o ON o.entity_id = i.order_id AND o.state NOT IN ('canceled', 'closed')
JOIN cataloginventory_stock_item si ON si.product_id = i.product_id AND si.stock_id = 1
WHERE o.created_at >= NOW() - INTERVAL 30 DAY
  AND i.product_type IN ('simple', 'virtual')
  AND si.is_in_stock = 0
GROUP BY i.sku, si.qty
ORDER BY sold_last_30_days DESC;

It reads the default stock. If you use several stock sources (Multi-Source Inventory), check each source's quantity under the product's Sources section before you reorder.

More guides

Gaurav Harsh

Gaurav Harsh is a Magento developer who works on large Adobe Commerce stores and builds AI Reports, a Magento extension for asking your store's data questions in plain English. LinkedIn