still display attributes in layer

piaoling  2012-07-31 16:04:43
app/code/core/Mage/Catalog/Model/Layer/Filter/Attribute.php

 

public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
    {
        $filter = $request->getParam($this->_requestVar);
        if (is_array($filter)) {
            return $this;
        }
        $text = $this->_getOptionText($filter);
        if ($filter && $text) {
            $this->_getResource()->applyFilterToCollection($this, $filter);
            $this->getLayer()->getState()->addFilter($this->_createItem($text, $filter));

//注释掉下面这行
           // $this->_items = array();
        }
        return $this;
    }

 

 

 

app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Layer/Filter/Attribute.php

 

/**
     * Apply attribute filter to product collection
     *
     * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
     * @param int $value
     * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Layer_Filter_Attribute
     */
    public function applyFilterToCollection($filter, $value)
    {
        $collection = $filter->getLayer()->getProductCollection();
        $attribute  = $filter->getAttributeModel();
        $connection = $this->_getReadAdapter();


        //将$tableAlias = $attribute->getAttributeCode() . '_idx';改为

$tableAlias = $attribute->getAttributeCode() . '_fidx';
        $conditions = array(
            "{$tableAlias}.entity_id = e.entity_id",
            $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()),
            $connection->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId()),
            $connection->quoteInto("{$tableAlias}.value = ?", $value)
        );

        $collection->getSelect()->join(
            array($tableAlias => $this->getMainTable()),
            join(' AND ', $conditions),
            array()
        );

        return $this;
    }

 

效果图:

类别 :  magento(258)  |  浏览(4540)  |  评论(0)
发表评论(评论将通过邮件发给作者):

Email: