【问题标题】:Get products which exists in two categories获取存在于两个类别中的产品
【发布时间】:2013-12-07 01:12:46
【问题描述】:

我需要找到存在于类别 93 和 97 中的产品。到目前为止,我能够获得存在于类别 93 或 97 中的产品,但使用 AND 却没有运气。

我现在真的一无所知,现在已经做了很多谷歌搜索。

感谢您的帮助!

到目前为止的代码:

$collection = Mage::getModel('catalog/product')->getCollection(); 
        $collection->distinct(true); 
        $collection->joinField('category_id', 
        'catalog/category_product', 
        'category_id', 
        'product_id=entity_id', 
        null, 
        'left'); 
        $collection->addAttributeToFilter('category_id', array( 'in' =>
        array('finset'=> '93'),
        array('finset'=> '97')));

Magento 企业版 1.13.0.0

【问题讨论】:

    标签: php magento magento-1.13


    【解决方案1】:

    看看@How to get products that are found in 2 or more categories

    $collection = Mage::getModel('catalog/product')->getCollection(); 
    ....
    $cat_ids = array(93,97);  
    $collection->addAttributeToFilter('category_id', array('in' => array('finset' => $cat_ids)))
    

    【讨论】:

    • 您先生,是救生员!我怎么没找到那个问题?找了好久:b
    【解决方案2】:

    认为语法可能是问题所在。 试试

    $collection->addAttributeToFilter('category_id', array( 'in' => array(93,97))),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-07
      • 1970-01-01
      • 1970-01-01
      • 2019-12-22
      • 2012-07-27
      • 1970-01-01
      • 2010-11-24
      • 1970-01-01
      相关资源
      最近更新 更多