【问题标题】:How to get product collection with multiple category?如何获得具有多个类别的产品集合?
【发布时间】:2015-10-30 13:32:16
【问题描述】:

在我的自定义模块中,我正在获取类别 ID。 有时是单一类别,有时是多个类别

我的代码是:

$exist_prdcat_id="4,5"; //multiple category
$collection = Mage::getModel('catalog/product')->getCollection();
        $collection->joinField(
            'category_id', 'catalog/category_product', 'category_id', 
            'product_id = entity_id', null, 'left'
        )
        ->addAttributeToSelect('*')
        ->addAttributeToFilter('type_id', array('eq' => 'simple'))
        ->addAttributeToFilter('category_id', array(
                array('finset' => array($exist_prdcat_id)),
        ));

现在使用此代码我没有得到产品,所以当它的单个或多个类别 id 时我如何获得产品

【问题讨论】:

    标签: magento collections


    【解决方案1】:

    试试下面 -

    $exist_prdcat_id=array(4,5); //multiple category
    $collection = Mage::getModel('catalog/product')->getCollection();
            $collection->joinField(
                'category_id', 'catalog/category_product', 'category_id', 
                'product_id = entity_id', null, 'left'
            )
            ->addAttributeToSelect('*')
            ->addAttributeToFilter('type_id', array('eq' => 'simple'))
            ->addAttributeToFilter('category_id', array(
                    array('finset' => $exist_prdcat_id),
            ));
    

    将您的类别 ID 放入数组中。

    参考:Filter product collection on two categories Magento 1.7

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-13
      • 2021-04-29
      • 1970-01-01
      • 1970-01-01
      • 2021-08-12
      • 2011-12-08
      相关资源
      最近更新 更多