按属性和标记的Magento过滤器产品

问题描述 投票:0回答:2

我正在尝试基于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'

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

magento magento-1.7
2个回答
0
投票

请尝试:

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

0
投票

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

$Products->joinTable
(
    array( 'relation'=>'tag/relation' ),
    "relation.product_id = e.entity_id AND relation.tag_id = '82'",
    array('*') //all fields
);
© www.soinside.com 2019 - 2024. All rights reserved.