【问题标题】:Multiselection in Layered navigation In MagentoMagento中分层导航中的多选
【发布时间】:2013-02-05 06:00:47
【问题描述】:

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

-提前致谢。

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

【问题讨论】:

    标签: magento multi-select layered-navigation


    【解决方案1】:

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

    【讨论】:

    • 谢谢您的快速回复。我之前做过,但没有成功,如果您能简要解释一下,那就太棒了。
    • 我在数组中传递参数,因此我修改了应用方法。
    • 你能展示你修改后的应用方法吗?更新您的问题。
    • 所以,您目前直接将过滤器应用于集合,但这正是 Magento Core 正在做的事情。您必须使用自己的 where 条件更新集合,其中所有可能的值都由 OR 而不是 AND 进行检查
    • 你能在你选择的对象上调用一个 assemble 来看看他在那里真正建造了什么吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-06
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 2012-09-15
    • 1970-01-01
    • 2011-11-27
    相关资源
    最近更新 更多