如何通过M2中的类别ID sql查询所有库存产品?

正如标题所述,我希望在Magento 2中按类别ID查询所有库存产品。如果简单有库存,则可能仅获得父(配置)ID,不确定我是否有意义?

SELECT p.entity_id as product_id,p.sku,c.is_in_stock 
FROM catalog_product_entity as p
INNER JOIN cataloginventory_stock_item as c 
ON p.entity_id = c.product_id
anhuihaidong 回答:如何通过M2中的类别ID sql查询所有库存产品?

要获取所有具有类别ID的库存产品:

SELECT product.entity_id as product_id,product.sku,stock_item.is_in_stock FROM catalog_product_entity as product
    INNER JOIN cataloginventory_stock_item as stock_item ON product.entity_id = stock_item.product_id
    INNER JOIN catalog_category_product as cat_prod on product.entity_id = cat_prod.product_id
    WHERE cat_prod.category_id=XXX and stock_item.is_in_stock=1;

如果只需要可配置的,只需添加条件即可:and product.type_id='configurable'

本文链接:https://www.f2er.com/3104091.html

大家都在问