1

In my website, sorting is in asc for all sorting option but if I select "Sort By Date" (created_at) I want it go sort on desc order. How do I do it? Also I have a theme installed. Below is the code used at present

                    <option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
                        <?php echo $this->__($_order) ?>
                    </option>
1

You can add a check for the key and change the sort direction on toolbar.

Something like this on the template file

template/catalog/product/list/toolbar.phtml

<select onchange="setLocation(this.value)" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Sort By: ')) ?>">
<?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
        <?php if($_key == 'created_at'): ?>
            <option value="<?php echo $this->getOrderUrl($_key, 'desc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
                <?php echo $this->__($_order) ?>
            </option>
        <?php else: ?>
            <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; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.