Magento1:移除 sort by 中的position選項

Magento官方已宣布,將於2020年6月份全面停止支援Magento1的安全更新與修正服務,有需升級至Magento2的店家們敬請與歐斯瑞聯繫
相關資訊請參閱:Magento 1 升級 Magento 2
那麼仍使用Magento1的店家們,若想在前台的「Sort By」下拉式選單中移除「Position」的選項,請依照以下步驟執行:
首先請先開啟toolbar.phtml
app/design/frontend/<package>/<theme>/template/catalog/product/list/toolbar.phtml

在 <?php foreach($this->getAvailableOrders() as $_key=>$_order): ?> 底下加上 一個 IF 判斷。

修改之後的code像這樣:
<div class="sort-by">
<label><?php echo $this->__('Sort By') ?></label>
<select onchange="setLocation(this.value)" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Sort By')) ?>">
<?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
<?php if ($_order != 'Position') : // Remove "Position" from the sort option list ?>
<option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
<?php echo $this->__($_order) ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
<?php if($this->getCurrentDirection() == 'desc'): ?>
<a href="<?php echo $this->getOrderUrl(null, 'asc') ?>" class="sort-by-switcher sort-by-switcher--desc" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Set Ascending Direction')) ?>"><?php echo $this->__('Set Ascending Direction') ?></a>
<?php else: ?>
<a href="<?php echo $this->getOrderUrl(null, 'desc') ?>" class="sort-by-switcher sort-by-switcher--asc" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Set Descending Direction')) ?>"><?php echo $this->__('Set Descending Direction') ?></a>
<?php endif; ?>
</div>
如此一來即可只列出非「Position」的選項。
我要留言