bwright
bwright

Reputation: 33

How to change Magento Enterprise "sort by price" to descending?

I've played with this block a bit in toolbar.phtml:

<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>

I changed asc to desc, but it doesn't appear to be working.

Upvotes: 0

Views: 6016

Answers (2)

Martin
Martin

Reputation: 2673

In catalog.xml add value:

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

example:

<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>

Upvotes: 0

Axel
Axel

Reputation: 10772

Magento currently doesn't let you define the sort order from the backend configuration. They let you choose what you can sort by, however. To change the default sort order, you must do the following:

  1. Copy app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php to app/code/local/Mage/Catalog/Block/Product/List/Toolbar.php

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

  3. Look for protected $_direction = 'asc';

  4. Change to protected $_direction = 'desc';

  5. Save the file, clear caches.

To change the default sort by to Price, do the following:

  1. In the Magento Admin, Go to System > Configuration > Catalog

  2. Change Product Listing Sort by to Price

  3. Click Save Config

Upvotes: 2

Related Questions