donglian2106 2013-02-25 19:48
浏览 26

Magento Collections(按特定顺序按类型ID获取产品

I want to get a collection of products from magento in a specific order.

  1. Simple Products
  2. Configurable Products
  3. Grouped Products

How would I add a filter that will retrieve the products in that order

  • 写回答

1条回答 默认 最新

  • dpe77294 2013-02-26 10:09
    关注

    It's not possible directly. I have 2 solutions:

    1. Get your products in 3 different collections using addAttributeToFilter where attribute name is type_id. For the condition you can use Mage_Catalog_Model_Product_Type::TYPE_SIMPLE, Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE and Mage_Catalog_Model_Product_Type::TYPE_GROUPED.

    Example:

    $simple_products = $model->getCollection()
            ->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id', Mage_Catalog_Model_Product_Type::TYPE_SIMPLE);
    

    2. Add custom attribute from the admin panel (e.g. 1 for simple, 2 for configurable, 3 for grouped products etc.) and use it with addAttributeToSort.

    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应