как изменить положение фильтра категорий в многоуровневой навигации magento 2?
Мне нужно переместить фильтр категорий после моего пользовательского фильтра атрибутов, но я не могу его переместить, пожалуйста, помогите мне изменить положение. Я хочу переместить фильтр категорий в последнюю позицию.
2
2 answers
Фильтры в многоуровневой навигации создаются в этом файле:
Vendor/magento/module-catalog/Model/Layer/FilterList.php
/**
* Retrieve list of filters
*
* @param \Magento\Catalog\Model\Layer $layer
* @return array|Filter\AbstractFilter[]
*/
public function getFilters(\Magento\Catalog\Model\Layer $layer)
{
if (!count($this->filters)) {
$this->filters = [
$this->objectManager->create($this->filterTypes[self::CATEGORY_FILTER], ['layer' => $layer]),
];
foreach ($this->filterableAttributes->getList() as $attribute) {
$this->filters[] = $this->createAttributeFilter($attribute, $layer);
}
}
return $this->filters;
}
Результат $this->filters
будет выглядеть как
$this->filters[0] = Magento\CatalogSearch\Model\Layer\Filter\Category
$this->filters[1] = Magento\CatalogSearch\Model\Layer\Filter\Attribute
$this->filters[2] = Magento\CatalogSearch\Model\Layer\Filter\Attribute
$this->filters[3] = Magento\CatalogSearch\Model\Layer\Filter\Attribute
$this->filters[4] = Magento\CatalogSearch\Model\Layer\Filter\Attribute
С помощью пользовательского плагина afterGetFilters
вы должны иметь возможность проверить, является ли первый элемент в массиве экземпляром Magento\CatalogSearch\Model\Layer\Filter\Category
. Если это так, поместите его в конец массива, прежде чем возвращать результат.
1
Author: haroldclaus, 2018-09-21 08:39:17
Работай на меня
public function getFilters(\Magento\Catalog\Model\Layer $layer)
{
if (!count($this->filters)) {
$this->filters = [
$this->objectManager->create($this->filterTypes[self::CATEGORY_FILTER], ['layer' => $layer]),
];
foreach ($this->filterableAttributes->getList() as $attribute) {
$this->filters[] = $this->createAttributeFilter($attribute, $layer);
}
}
$data = array_shift($this->filters);
$this->filters[]= $data;
return $this->filters;
}
0
Author: Devidas, 2018-09-21 10:49:23