Skip to content

Instantly share code, notes, and snippets.

@groggu
Last active August 29, 2015 14:08
Show Gist options
  • Save groggu/ab42c04bc4b6b2b202b2 to your computer and use it in GitHub Desktop.
Save groggu/ab42c04bc4b6b2b202b2 to your computer and use it in GitHub Desktop.
Magento - Get configurable product's total stock qty and is_in_stock status using one child's product ID
SELECT
count(product_id),
sum(cataloginventory_stock_item.qty) as child_qty,
sum(cataloginventory_stock_item.is_in_stock) > 0 as some_child_in_stock
FROM cataloginventory_stock_item
WHERE product_id in (
SELECT
parent.product_id
FROM
catalog_product_super_link as parent
WHERE
parent.parent_id=(
SELECT
parent.parent_id
FROM
catalog_product_super_link as parent
WHERE
parent.product_id=1076131))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment