简体   繁体   English

使用简单可配置的Magento分层导航过滤器

[英]Magento Layered Navigation Filters using Simple Configurable

I have a configurable product with simple products associated with it. 我有一个可配置的产品,其中包含与之相关的简单产品。 Ex. 防爆。 Shoe with attributes Size and Width on the simple. 鞋子的属性大小和宽度简单。

  1. When I filter by width and size, it shows a configurable even though a simple product with that size and width don't exist. 当我按宽度和大小进行过滤时,它显示可配置,即使不存在具有该大小和宽度的简单产品。

I've seen this asked before here in numerous forms with no solutions. 我在此之前已经看到过这种问题,有许多形式没有解决方案。 Does anyone know how to fix this functionality? 有谁知道如何修复此功能? I'm amazed how this is not built out of the box. 我很惊讶这不是开箱即用的。

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

Magento - Layered navigation, configurable products, multiple filters active issue Magento - 分层导航,可配置产品,多个过滤器活动问题

You have to customize the core file by copying it in the local/Mage directory. 您必须通过在core / Mage目录中复制核心文件来自定义核心文件。

Suppose that you have to variations size & color. 假设您必须改变尺寸和颜色。

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

After the following code:- 在以下代码之后: -

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

You have to customize it for the selected attribute:- 您必须为所选属性自定义它: -

For example :- 例如 :-

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)));
    }

hope this will help..!! 希望这会有所帮助.. !!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM