需求:-在产品列表magento2.2.5中按价格从低到高和从高到低排序
我们遵循此Tuto,但不起作用 Sort by price low to high and high to low in product listing magento2
有人帮我吗?
答案 0 :(得分:0)
正如您提到的,我遵循的示例与您发现的示例相同,但对我不起作用,我对roundingSetCollection函数做了很小的改动,如下所示:
public function aroundSetCollection(
\Magento\Catalog\Block\Product\ProductList\Toolbar $subject,
\Closure $proceed,
$collection
) {
$currentOrder = $subject->getCurrentOrder();
$result = $proceed($collection);
if($currentOrder) {
if($currentOrder == 'high_to_low') {
$collection->setOrder('price', 'desc');
} else if($currentOrder == 'low_to_high') {
$collection->setOrder('price', 'asc');
} else if ($currentOrder == 'created_at') {
$collection->setOrder('created_at', 'desc');
}
}
return $collection;
}