【问题标题】:Magento Filter Products By Attributes AND TagMagento 按属性和标签过滤产品
【发布时间】:2013-10-07 06:03:43
【问题描述】:

我正在尝试根据 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


    【解决方案1】:

    试试这个:

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 我已经尝试过了,它失败了消息:未捕获的异常'Mage_Eav_Exception',消息'无效的属性名称:e.entity_id AND relation.tag_id' =/
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-02
      相关资源
      最近更新 更多