Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento中分层导航中的多重选择_Magento_Multi Select_Layered Navigation - Fatal编程技术网

Magento中分层导航中的多重选择

Magento中分层导航中的多重选择,magento,multi-select,layered-navigation,Magento,Multi Select,Layered Navigation,在分层导航中,当我选择特定属性时,它会从左侧的选择面板中消失,所以我希望我能够选择多次。 如果我能从什么样的收藏品中得知,那将是很有帮助的 -提前谢谢 public function apply(Zend_Controller_Request_Abstract $request, $filterBlock) { $filter = $request->getParam($this->_requestVar); if (is_array($filter)) {

在分层导航中,当我选择特定属性时,它会从左侧的选择面板中消失,所以我希望我能够选择多次。 如果我能从什么样的收藏品中得知,那将是很有帮助的

-提前谢谢

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\u Catalog\u Model\u Layer\u Filter\u属性类,它使用方法apply()来过滤结果。

Thnx供您快速回复。我之前做过,但没有成功,如果你能简单地解释一下,那就太棒了。我正在数组中传递参数,所以我修改了应用方法。你能展示一下修改后的应用方法吗?更新您的问题。因此,您当前正在直接将筛选器应用于集合,但这正是Magento Core所做的。您必须使用自己的where条件更新集合,其中所有可能的值都由OR和not检查,您可以调用select对象上的集合来查看它在那里真正构建的内容吗?