7
votes

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

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

1
I think I have the answer to this. How is the product visibility configured for the configurable and simple? Are they both visible in the catalog / search or just the configurable product?obsirdian
just the configurable.David
It doesn't look like this can be done easily without modifying the indexing or seriously hurting the performance. In app/code/core/Mage/Catalog/Model/Resource/Layer/Filter/Attribute.php::getCount the layered navigation links being retrieved uses the index tables, which don't include the products that aren't visible individually. So you would have to add a few additional queries to get the associated simple products and check if the combination of two (or more) attributes exists. This is where the performance would get killed, especially if you have a lot of attributes / values.obsirdian
The relevant tables in the DB are catalog_product_entity, catalog_product_index_eav If you take a look at yours, you'll see the data just isn't there. Maybe if you ask a sql wizard how you could join those tables with the relevant data. Add this before the return statement in getCount() to log the query: Mage::log((string) $select);obsirdian
Well that's terrible news seems like magento community just doesn't care about this weird.David

1 Answers

-1
votes

You have to customize the core file by copying it in the local/Mage directory.

Suppose that you have to variations size & color.

Open the file 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..!!