Magento sort by special price (disounted product) on product list page dropdown (toolbar.phtml)

magento.stackexchange https://magento.stackexchange.com/questions/5500

سؤال

I want to extend sort by drop down for special price or discounted product from toolbar.phtml

<div class="sort-by" style="float:left">
    <fieldset class="sort-by">
      <label><?php echo $this->__('Sort by') ?></label>
        <select onchange="setLocation(this.value)">
          <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>
          <option value="<?php echo $this->getOrderUrl('name', 'asc') ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>> Name - A to Z </option>
          <option value="<?php echo $this->getOrderUrl('name', 'desc') ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>> Name - Z to A </option>
         <option value="<?php echo $this->getOrderUrl('update_at', 'desc') ?>"<?php if($this->isOrderCurrent('update_at') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>Newest First</option>
        </select>
  </fieldset>
</div>

How I can add one more option for discount so products will sort by special price ASC?

هل كانت مفيدة؟

المحلول

You should only need to insert the sort order, and the collection should already have the special price - add this to your <select>:

<option value="<?php echo $this->getOrderUrl('special_price', 'asc') ?>"<?php if($this->isOrderCurrent('special_price') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>Special Price</option>

The only flaw in this method is that it won't filter items from the collection that are not currently on sale, though it will sort them.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top