【问题标题】:Magento Layered Navigation Filters using Simple Configurable使用简单可配置的 Magento 分层导航过滤器
【发布时间】:2015-10-12 15:32:01
【问题描述】:

我有一个可配置的产品,其中包含与之相关的简单产品。前任。鞋子的属性 Size 和 Width 就简单了。

  1. 当我按宽度和尺寸过滤时,它显示可配置,即使不存在具有该尺寸和宽度的简单产品。

我之前在这里以多种形式看到过这个问题,但没有解决方案。有谁知道如何修复此功能?我很惊讶这不是开箱即用的。

https://magento.stackexchange.com/questions/18001/shop-by-layered-navigation-configurable-products-not-filtering-correctly

Magento - Layered navigation, configurable products, multiple filters active issue

【问题讨论】:

  • 我想我有这个答案。产品可见性如何配置为可配置和简单?它们是在目录/搜索中可见还是仅在可配置产品中可见?
  • 只是可配置的。
  • 在不修改索引或严重损害性能的情况下,这看起来并不容易。在app/code/core/Mage/Catalog/Model/Resource/Layer/Filter/Attribute.php::getCount 中,正在检索的分层导航链接使用索引表,其中不包括单独不可见的产品。因此,您必须添加一些额外的查询来获取相关的简单产品并检查两个(或更多)属性的组合是否存在。这就是性能会被扼杀的地方,特别是如果你有很多属性/值。
  • 数据库中的相关表是catalog_product_entity, catalog_product_index_eav 如果你看看你的,你会发现数据不存在。也许如果您询问 sql 向导如何将这些表与相关数据连接起来。在 getCount() 中的 return 语句之前添加这个来记录查询:Mage::log((string) $select);
  • 好吧,这是个可怕的消息,好像 magento 社区根本不关心这个奇怪的事情。

标签: magento


【解决方案1】:

您必须通过将其复制到本地/Mage 目录中来自定义核心文件。

假设您必须改变尺寸和颜色。

打开文件app\code\core\Mage\Catalog\Model\Layer.php

以下代码后:-

$collection
  ->addAttributeToSelect(
    Mage::getSingleton('catalog/config')->getProductAttributes()
  )
  ->addMinimalPrice()
  ->addFinalPrice()
  ->addTaxPercents()
  ->addUrlRewrite($this->getCurrentCategory()->getId());

您必须为所选属性自定义它:-

例如:-

if(isset($_GET['size']))
    {
        $query = 'SELECT value FROM aw_layerednavigation_filter_option_eav WHERE name="title" AND option_id IN ( '.$_GET['size'].' )';
        $results = $readConnection->fetchAll($query);
        $sizeLabels = array();
        foreach($results as $_r){
            $size_labels[] = $_r['value'];
        }

        $query = 'SELECT parent_id FROM advance_filter WHERE size IN ( '.implode(",",$size_labels).' ) AND qty > 0';

        $results = $readConnection->fetchAll($query);
        foreach($results as $_r){
            $size_prod_Ids[] = $_r['parent_id'];
        }   
    }
    $color_prod_Ids = array();
    if(isset($_GET['color']))
    {
        $query = 'SELECT value FROM aw_layerednavigation_filter_option_eav WHERE name="title" AND option_id IN ( '.$_GET['color'].' )';
        $results = $readConnection->fetchAll($query);
        $color_labels = array();
        foreach($results as $_r){
            $color_labels[] = strtoupper($_r['value']);
        }

        $query = 'SELECT parent_id FROM advance_filter WHERE color IN ( "'.implode(",",$color_labels).'" ) AND qty > 0';

        $results = $readConnection->fetchAll($query);
        foreach($results as $_r){
            $color_prod_Ids[] = $_r['parent_id'];
        }
    }
    $productIds = array_merge($size_prod_Ids,$color_prod_Ids);
    if(count($productIds) > 0){
        $collection->addAttributeToFilter('entity_id', array('in' => array_unique($productIds)));
    }

希望这会有所帮助..!!

【讨论】:

  • 您从哪里获得查询中的这些表?
  • @David 这些表是扩展的,但您可以用 Magento 核心表替换它们。这只是为了解决您的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多