سؤال

How would I go about modifying layered navigation to only look at attributes on the parent configurable product, and not the child?

Child and parent products both have the attribute set and it is used in other places. For example, products all have a color, including the parent. The parent's color isn't always the same as the child's, but it is indicative of the default color. When we filter to a specific color we only want to show items where the parent is set to that default color. Configurable products are visible and simple (child) products are hidden. There are some individual simple products which are not children and are visible which must also remain functional.

هل كانت مفيدة؟

المحلول

With the caveat that layered navigation changes are always more complicated than they seem, the product collection for the layered navigation is instantiated in

#File: app/code/core/Mage/Catalog/Model/Layer.php
public function getProductCollection()
{
    if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {
        $collection = $this->_productCollections[$this->getCurrentCategory()->getId()];
    } else {
        $collection = $this->getCurrentCategory()->getProductCollection();
        $this->prepareProductCollection($collection);
        $this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;
    }
    return $collection;
}

It also has its default filters added in

#File: app/code/core/Mage/Catalog/Model/Layer.php
public function prepareProductCollection($collection)
{
    $collection
        ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
        ->addMinimalPrice()
        ->addFinalPrice()
        ->addTaxPercents()
        ->addUrlRewrite($this->getCurrentCategory()->getId());

    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

    return $this;
}

And an intriguingly named getFilterableAttributes

#File: app/code/core/Mage/Catalog/Model/Layer.php
public function getFilterableAttributes()
{
    $setIds = $this->_getSetIds();
    if (!$setIds) {
        return array();
    }
    /** @var $collection Mage_Catalog_Model_Resource_Product_Attribute_Collection */
    $collection = Mage::getResourceModel('catalog/product_attribute_collection');
    $collection
        ->setItemObjectClass('catalog/resource_eav_attribute')
        ->setAttributeSetFilter($setIds)
        ->addStoreLabel(Mage::app()->getStore()->getId())
        ->setOrder('position', 'ASC');
    $collection = $this->_prepareAttributeCollection($collection);
    $collection->load();

    return $collection;
}

A rewrite of any one of those methods would be a good place to start (adding an type=configurable filter, restricting the filterable attributes, etc.)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top