0

我正在尝试根据 2 个自定义属性和一个标签过滤一组产品,我可以通过以下自定义属性轻松过滤:

$Products   = Mage::getModel('catalog/product')->getCollection();

$Products->addAttributeToSelect('name');
$Products->addAttributeToFilter('custom_attribute1' , 50);
$Products->addAttributeToFilter('custom_attribute2' , 20);

但是,当我尝试使用标签扩展过滤器时:

$Products->joinTable
        (
            array( 'relation'=>'tag/relation' ),
                "relation.product_id = e.entity_id AND relation.tag_id = '82'"
        );

我收到以下消息:

PHP 致命错误:未捕获的异常“Mage_Eav_Exception”和消息“无效的联合字段”

如何获得所有符合所有条件(自定义属性和标签)的产品?

4

2 回答 2

0

您需要为该joinTable方法指定第三个参数。它应该包含要从连接表中选择的字段。像这样的东西:

$Products->joinTable
(
    array( 'relation'=>'tag/relation' ),
    "relation.product_id = e.entity_id AND relation.tag_id = '82'",
    array('*') //all fields
);
于 2013-10-07T06:36:03.817 回答
0

尝试这个:

$Products->getSelect()->join(
    array('relation' => $Products->getTable('tag/relation')),
    "relation.product_id = e.entity_id AND relation.tag_id = '82'"
);
于 2013-10-07T08:24:20.847 回答