簡體   English   中英

Magento中分層導航中的多選

[英]Multiselection in Layered navigation In Magento

在分層導航中,當我選擇特定屬性時,它會從左側選擇面板中消失,因此我希望我可以選擇多個。 如果我知道它來自什么收藏品,那將是有幫助的。

-提前致謝。

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;
}

我做過類似的事情,您必須重寫Mage_Catalog_Model_Layer_Filter_Attribute類,該類使用apply()方法過濾結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM