Magento 产品集合仅获取某些类别的产品
我正在尝试获取仅在某些类别中具有销售价格的产品列表。现在我正在尝试使用产品集合来获取这些数据。我不确定如何仅限制特定类别的集合。这是我到目前为止所拥有的:
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('status', 1)
->addAttributeToFilter('visibility', 4)
->addAttributeToFilter('special_price', array('neq' => ""))
->addAttributeToFilter('discontinued', array('neq' => 1))
->setPageSize(10)
->setOrder('price', 'ASC')
;
已停产属性是我们使用的自定义属性,这样产品既不会显示,也不会出现 404。
有没有办法使用产品模型并限制到某些类别?
I am trying to get a list of products that have a sale price that are only in certain categories. Right now I am trying to use a product collection to get this data. I am not sure how I would go about restricting the collection for particular categories only. Here is what I have so far:
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('status', 1)
->addAttributeToFilter('visibility', 4)
->addAttributeToFilter('special_price', array('neq' => ""))
->addAttributeToFilter('discontinued', array('neq' => 1))
->setPageSize(10)
->setOrder('price', 'ASC')
;
The discontinued attribute is a custom attribute that we use so that products don't display but also don't 404.
Is there a way to use the product model and restrict to certain categories?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想通了。您从类别开始,从类别中获取产品集合,然后从那里对其进行细化。在代码中它看起来像这样:
Figured it out. You start with the category and get the product collection from the category and then refine it down from there. In code it looks like this: