【问题标题】:2 or more category filter for products in magento 1.5magento 1.5中产品的2个或更多类别过滤器
【发布时间】:2013-10-14 02:40:41
【问题描述】:

我有 Magento 版本。 1.5.0.1,我需要在产品中添加过滤器。就像我有 2 个类别“A”和“B”,只有当产品同时存在(“A”和“B”)类别时才应该显示结果。我用过这个代码但没有成功

$_productCollection = Mage::getModel('catalog/product') ->getCollection() ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') ->addAttributeToSelect('*') ->addAttributeToFilter('category_id', array(array('finset' => '4'),array('finset' =>'5'))) ->addAttributeToSort('created_at', 'desc');

我们将不胜感激任何帮助

谢谢

【问题讨论】:

    标签: magento


    【解决方案1】:

    希望对你有帮助

    $collection = Mage::getModel('catalog/product')->getCollection()
                 ->addAttributeToSelect('*')
                 ->addFieldToFilter('is_saleable',1)
                 ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
                 ->addAttributeToFilter('category_id', array(
                     array('finset' => '4'),
                     array('finset' => '8'))
                   )
                 ->addAttributeToSort('created_at', 'desc');
    

    4 & 8 是类别 ID

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-02
      • 1970-01-01
      • 2018-02-26
      • 1970-01-01
      相关资源
      最近更新 更多