0

在分层导航中,当我选择特定属性时,它会从左侧选择面板中消失,所以我希望我应该能够多次选择。如果我知道它来自哪个系列,那将很有帮助。

-提前致谢。

public function apply(Zend_Controller_Request_Abstract $request, $filterBlock) {
    $filter = $request->getParam($this->_requestVar);
    if (is_array($filter)) {
        $text = array();
        foreach ($filter as $f)
            array_push ($text, $this->_getOptionText($f));
            if ($filter && $text) {
            $this->_getResource()->applyFilterToCollection($this, $filter);
            $this->getLayer()->getState()->addFilter($this->_createItem($text, $filter));
            $this->_items = array();
        }
        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;
}


public function applyFilterToCollection($filter, $value)
{
    $collection = $filter->getLayer()->getProductCollection();
    $attribute  = $filter->getAttributeModel();
    $connection = $this->_getReadAdapter();
    $tableAlias = $attribute->getAttributeCode() . '_idx';
     if (!is_array($value)) {
        $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)
    );
     }else{

         $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 in (?)",$value)
    );
     }

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

    //echo $collection->getSelect();

    return $this;
}
4

1 回答 1

0

我做过类似的事情,你必须重写 Mage_Catalog_Model_Layer_Filter_Attribute 类,它使用方法 apply() 来过滤结果。

于 2013-02-05T16:24:37.017 回答