0

我正在使用 magento connect 的“分层导航 SEO”。它工作完美。

但我希望始终显示过滤器(带有结果)。我的要求与此处发现的其他问题不同。

例如...

在计算机类别中(使用示例数据)有 4 个品牌和三种颜色(黑色、棕色和银色)我选择“Apple”作为品牌可用的颜色将是银色,但我想像以前一样显示所有 3 种颜色(记住......不是所有的颜色,如粉红色、洋红色等)如果我选择过滤器(无结果),所有颜色(如白色、洋红色、粉红色等)都会显示,这是我不想要的

我只想要最初与类别相关的过滤器。我是 magento 编码的新手

有什么帮助吗?

如果需要更清晰,我将能够提供...

4

1 回答 1

1

在 app\code\local\Catalin\SEO\Model\Catalog\Resource\Layer\Filter\Attribute.php

编辑公共函数 getCount($filter)

转到最后一行

更改返回 $connection->fetchPairs($select); 到...

$pairCarry = $connection->fetchPairs($select);
$pairCarryfin = $this->checkTheAttributes($pairCarry, $tableAlias, $attribute); 
 return $pairCarryfin;

然后在它下面添加函数...

public function checkTheAttributes($pairCarry, $tableAlias, $attribute){
    $category = Mage::registry('current_category');
    if($category){
        $query = "SELECT DISTINCT `$tableAlias`.`value`, COUNT($tableAlias.entity_id) AS `count` FROM `catalog_product_entity` AS `e`
         INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=".$category->getStoreId()." AND cat_index.visibility IN(2, 4) AND cat_index.category_id='".$category->getId()."'
         INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0
         INNER JOIN `catalog_product_index_eav` AS `$tableAlias` ON $tableAlias.entity_id = e.entity_id AND $tableAlias.attribute_id = '".$attribute->getAttributeId()."' AND $tableAlias.store_id = '".$category->getStoreId()."' GROUP BY `$tableAlias`.`value`";
    }
    else{
        $query = "SELECT DISTINCT `$tableAlias`.`value`, COUNT($tableAlias.entity_id) AS `count` FROM `catalog_product_entity` AS `e`
         INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.visibility IN(2, 4)
         INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0
         INNER JOIN `catalog_product_index_eav` AS `$tableAlias` ON $tableAlias.entity_id = e.entity_id AND $tableAlias.attribute_id = '".$attribute->getAttributeId()."' AND $tableAlias.store_id = 1 GROUP BY `$tableAlias`.`value`";
    }
    $connection = $this->_getReadAdapter();
    $pairCarry_inter = $connection->fetchPairs($query);

    if(!empty($pairCarry)){
        $odd = array_diff_key($pairCarry_inter, $pairCarry);
        if(!empty($odd)){
            foreach($odd as $k=>$v){
                $odd[$k] = 0;
            }
        $pairCarry_inter = $pairCarry + $odd;
        }
    }

    else{
        foreach($pairCarry_inter as $k => $v){
            $pairCarry_inter[$k] = 0;
        }
    }

    $pairCarry_complete = $pairCarry_inter;

    return $pairCarry_complete;
}
于 2013-04-30T11:51:23.907 回答