我浏览了一些与排序相关的帖子,但没有提出所需的解决方案。
我目前正在使用以下代码对类别视图字段中的产品进行排序,以覆盖默认选项并按toolbar.phtml 中的属性进行排序。
<option value="<?php echo $this->getOrderUrl('name', 'asc') ?>"<?php if($this->isOrderCurrent('name')): ?> selected="selected"<?php endif; ?>>
NAME
</option>
<option value="<?php echo $this->getOrderUrl('short_description', 'asc') ?>"<?php if($this->isOrderCurrent('short_description')): ?> selected="selected"<?php endif; ?>>
FRAGRANCE
</option>
<option value="<?php echo $this->getOrderUrl('price', 'asc') ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
PRICE (Low to High)
</option>
<option value="<?php echo $this->getOrderUrl('price', 'desc') ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
PRICE (High to Low)
</option>
(我错误地使用了 short_description 属性而不是添加自定义香味属性)
现在,我需要的功能是,当使用其中的每一个时,例如按价格排序,我希望它按价格排序,它已经这样做了,然后再按另一个自定义属性“范围”排序。因此,如果它显示所有 3 英镑的产品,它会显示每个范围内的它们聚集在一起,而不是目前看起来随机的东西。
这是我上线的最后一个主要绊脚石,所以任何帮助都将不胜感激。
我已经使用toolbar.php中的以下行设法通过了一些道路
if ($this->getCurrentOrder()) {
$this->_collection->setOrder(array($this->getCurrentOrder(), 'range'), $this->getCurrentDirection());
}
唯一的问题是它似乎首先按范围排序,而不是按价格排序,即所有范围 1 按价格排序,然后范围 2 按价格排序。在哪里我需要它按价格排序,范围是价格的子排序