【问题标题】:category and sub categories product collection base on custom attributes基于自定义属性的类别和子类别产品集合
【发布时间】:2013-12-02 05:43:17
【问题描述】:

您好,我想根据自定义属性值获取类别及其子类别产品集合。

like 3 是父类,31,32,33,34,35 都是它的子类

然后我想要 3、31、32、33、34、35 类别中颜色为“红色”的所有产品。

【问题讨论】:

    标签: magento magento-1.6


    【解决方案1】:

    下面的集合肯定适合你。

    $_productCollection = Mage::getResourceModel('catalog/product_collection')->joinField('category_id','catalog/category_product','category_id','product_id=entity_id',null,'left')
        ->addAttributeToFilter('category_id', array('in' => $catID)) // may be Use finset instead of eq
         ->addAttributeToFilter('your_attribute',
             array('eq' => Mage::getResourceModel('catalog/product')
                ->getAttribute('your_attribute')
                ->getSource()
                ->getOptionId($your_attribute_value)
            )
        )
        ->addAttributeToSelect('*');
        $_productCollection->load();
    
        foreach($_productCollection as $_product){ 
            echo $this->htmlEscape($_product->getName())."<br/>"; 
        };
    

    希望这能解决您的问题

    【讨论】:

    • 谢谢我的朋友你有我的时间
    • @darshan.dodiya,很高兴为您提供帮助。请您投票支持我的帖子,以便有人可以信任并使用它以供将来参考。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-30
    相关资源
    最近更新 更多