2012-11-28 46 views
0

我已經與該塊起到了位toolbar.phtml:如何更改Magento Enterprise「按價格排序」降序?

<div class="sort-by"> 
     <label><?php echo $this->__('Sort By') ?></label> 
     <select onchange="setLocation(this.value)"> 
     <?php foreach($this->getAvailableOrders() as $_key=>$_order): ?> 
      <option value="<?php echo $this->getOrderUrl($_key, 'desc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>> 
       <?php echo $this->__($_order) ?> 
      </option> 
     <?php endforeach; ?> 
     </select> 
      **<?php if($this->getCurrentDirection() == 'desc'): ?>** 
      <a class="category-desc v-middle" href="<?php echo $this->getOrderUrl(null, 'asc') ?>" title="<?php echo $this->__('Set Ascending Direction') ?>"><?php echo $this->__('Set Ascending Direction') ?></a> 
     <?php else: ?> 
      <a class="category-asc v-middle" href="<?php echo $this->getOrderUrl(null, 'desc') ?>" title="<?php echo $this->__('Set Descending Direction') ?>"><?php echo $this->__('Set Descending Direction') ?></a> 
     <?php endif; ?> 
    </div> 

我改變遞增到遞減,但它似乎並不奏效。

+0

你想改變默認的排序順序?修改工具欄不會更改默認的排序順序。只有當用戶與其交互時設置排序順序的機制纔是。 – Axel

+0

public function setDefaultOrder($ field) if(isset($ this - > _ availableOrder [$ field])){ $ this - > _ orderField = $ field; } return $ this; }我試着玩這個功能 – bwright

+0

id理想情況下,只是在全球範圍內改變各種默認 - >價格 - >降 – bwright

回答

2

Magento目前不允許您從後端配置中定義排序順序。然而,他們讓你選擇你可以排序的東西。要更改默認的排序順序,你必須做到以下幾點:

  1. 複製app/code/core/Mage/Catalog/Block/Product/List/Toolbar.phpapp/code/local/Mage/Catalog/Block/Product/List/Toolbar.php

  2. 打開app/code/local/Mage/Catalog/Product/Block/List/Toolbar.php

  3. 查找protected $_direction = 'asc';

  4. 更改爲protected $_direction = 'desc';

  5. 保存文件,清除緩存。

要排序更改默認價格,請執行下列操作:

  1. 在Magento管理,轉到System > Configuration > Catalog

  2. 變化產品列表排序價格

  3. 點擊保存配置

+0

嘿謝謝這個人的作品。但它的app/code/local/mage/catalog/block/product/list/toolbar.php – bwright

+0

你應該創建一個自定義模塊(在'app/code/local'),擴展'Mage_Catalog_Block_Product_List_Toolbar'類, '$ _direction'屬性,而不是覆蓋整個文件。 – user3409662

0

在catalog.xml中添加值:

<action method="setDefaultDirection"><dir>desc</dir></action> 

例如:

<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml"> 
    <block type="page/html_pager" name="product_list_toolbar_pager"/> 
     <!-- The following code shows how to set your own pager increments --> 
    <!-- .... --> 
    <action method="setDefaultDirection"><dir>desc</dir></action> 
    </block>