Magento 产品集合仅获取某些类别的产品

发布于 2024-10-16 14:33:19 字数 584 浏览 2 评论 0原文

我正在尝试获取仅在某些类别中具有销售价格的产品列表。现在我正在尝试使用产品集合来获取这些数据。我不确定如何仅限制特定类别的集合。这是我到目前为止所拥有的:

$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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

输什么也不输骨气 2024-10-23 14:33:19

想通了。您从类别开始,从类别中获取产品集合,然后从那里对其进行细化。在代码中它看起来像这样:

$products = Mage::getModel('catalog/category')->load(410)
    ->getProductCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('status', 1)
    ->addAttributeToFilter('visibility', 4)
    ->addAttributeToFilter('special_price', array('neq' => ""))
    ->addAttributeToFilter('discontinued', array('neq' => 1))
    ->setOrder('price', 'ASC')
    ;

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:

$products = Mage::getModel('catalog/category')->load(410)
    ->getProductCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('status', 1)
    ->addAttributeToFilter('visibility', 4)
    ->addAttributeToFilter('special_price', array('neq' => ""))
    ->addAttributeToFilter('discontinued', array('neq' => 1))
    ->setOrder('price', 'ASC')
    ;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文