如何获得“库存"货品的集合. Magento中通过“资源模型"开发产品 [英] How to get the collection of "instock" products through Resource Model in Magento

查看:44
本文介绍了如何获得“库存"货品的集合. Magento中通过“资源模型"开发产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能通过在Magento?

Is it possible to fetch the collection of "in stock" products through resource model in Magento ?

我已经尝试过此代码

$collection = Mage::getResourceModel('catalog/product_collection')
        ->addAttributeToSelect('*');
$collection->addAttributeToFilter('is_in_stock', 0);

但这会引发致命错误

推荐答案

尝试下面的代码

$productCollection = Mage::getResourceModel('catalog/product_collection');
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection);
echo "<pre>";print_r($productCollection->getData());

//使用addInStockFilterToCollection()

// use addInStockFilterToCollection()

这篇关于如何获得“库存"货品的集合. Magento中通过“资源模型"开发产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆