如何从Magento产品集合中获取库存状态

3

这是我的产品集合,有人能帮我从产品集合中获取库存状态吗?

$collection = Mage::getModel('catalog/category')
                ->load($categoryId)
                ->getProductCollection()
                ->addAttributeToSelect('*')
                ->addAttributeToFilter('visibility', array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG));
return $collection;
2个回答

6

3
$collection = Mage::getModel('catalog/category')
                ->load($categoryId)
                ->getProductCollection()
                ->addAttributeToSelect('*')
                ->joinField('qty','cataloginventory/stock_item','qty','product_id=entity_id','{{table}}.stock_id=1','left')        
                ->addAttributeToFilter('visibility', array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG));
    return $collection;

您可以像这样操作:

您需要为库存项目添加join字段 ->joinField('qty','cataloginventory/stock_item','qty','product_id=entity_id','{{table}}.is_in_stock=1','left')


让我检查一下。 - Manish Raghani
1
非常感谢您的帮助,先生。它正常工作了。 :) - Manish Raghani

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接