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

标签 magento

我有一个可配置产品以及与其关联的简单产品。前任。鞋的属性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

最佳答案

您必须通过将其复制到 local/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)));
    }

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

关于使用简单可配置的 Magento 分层导航过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31568532/

相关文章:

magento - 禁用购物车/结帐/运输

javascript - 添加增量到表单输入获取 TypeError : qty_el is null

.htaccess - 通过在 .htaccess 中启用 gzip 来提高 magento 速度

configuration - Magento:禁用任何特定商店的模块

magento - 如何修改Magento中抽象类的代码?

magento - line1389 上的 fatal error :Call to a member function getSource()on a non-object in\app\cose\core\Mage\Catalog\Model\Product. php

xml - 使用 local.xml 更改或重新排列 Magento 登录和注销(顶部链接)位置

magento - 无法获取 magento 设置脚本中的所有网站

pagination - Magento 1.7 : Remove pagination from top and keep pagination at bottom

python - 通过 SOAP v2 创建 Magento 产品