Magento Layered Navigation “You cannot define a correlation name 'mycustomattribute' more than once ”

后端 未结 7 537
广开言路
广开言路 2021-01-17 10:27

I\'m using Magento\'s layered navigation with my custom attributes and price. If I filter by price it works; but when filtering by my custom attributes it shows:

7条回答
  •  遥遥无期
    2021-01-17 11:12

    This causes the same problem. -adding the same attribute to the sort twice when building a collection:

    ...
        ->addAttributeToSort('color', 'asc')
        ->addAttributeToSort('color', 'asc');
    

    NOTE: calling setCollection($this->getMyCollection); on the template caused my error, because 'color' was already added to the sort order as the default sort order.

    SOLUTION:a quick way to fix this is to remove the default sort order from the request after obtain the value:

    $this->getRequest()->setParam('order','');
    

    otherwise extend the Block and override the setCollection() method for your particular needs.

提交回复
热议问题