Magento Custom Sort Option

Anuj Sharma

How do I add custom sort option in Magento. I want to add Best Sellers, Top rated and exclusive in addition to sort by Price. Please help

liyakat

For Best Sellers

haneged in code/local/Mage/Catalog/Block/Product/List/Toolbar.php method setCollection to

public function setCollection($collection) {
    parent::setCollection($collection);
    if ($this->getCurrentOrder()) {
        if($this->getCurrentOrder() == 'saleability') {
            $this->getCollection()->getSelect()
                 ->joinLeft('sales_flat_order_item AS sfoi', 'e.entity_id = sfoi.product_id', 'SUM(sfoi.qty_ordered) AS ordered_qty')
                 ->group('e.entity_id')->order('ordered_qty' . $this->getCurrentDirectionReverse());
        } else {
            $this->getCollection()
                 ->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
        }
    }

    return $this;
}

After setCollection I added this method:

public function getCurrentDirectionReverse() {
    if ($this->getCurrentDirection() == 'asc') {
        return 'desc';
    } elseif ($this->getCurrentDirection() == 'desc') {
        return 'asc';
    } else {
        return $this->getCurrentDirection();
    }
}

And finally I changed mehod setDefaultOrder to

public function setDefaultOrder($field) {
    if (isset($this->_availableOrder[$field])) {
        $this->_availableOrder = array(
            'name'        => $this->__('Name'),
            'price'       => $this->__('Price'),
            'position'    => $this->__('Position'),
            'saleability' => $this->__('Saleability'),
        );
        $this->_orderField = $field;
    }

    return $this;
}

for Top rated

http://www.fontis.com.au/blog/magento/sort-products-rating

try above code.

for date added

Magento - Sort by Date Added

i am not associate with any of the above link for any work or concern it is just for knowledge purpose and to solve your issue.

hope this will sure help you.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Magento Custom Sort Option

From Dev

Magento trigger shipping by custom option

From Dev

Magento trigger shipping by custom option

From Dev

how to change custom option price by query in magento?

From Dev

how to change custom option price by query in magento?

From Dev

Magento custom option with radio buttons on the same row

From Dev

MAGENTO Catalog-Product-Custom Options Adding a custom option

From Dev

MAGENTO Catalog-Product-Custom Options Adding a custom option

From Dev

Magento: Custom attributes option's new value field

From Dev

How to delete product custom option value programmatically in Magento?

From Dev

Magento - custom product option don't show in order

From Dev

magento 1.9.2.2 add to cart with custom option image not working

From Dev

Show Product custom option in reorder using observer in Magento

From Dev

Magento: Remove Dash from between sku and custom option sku

From Dev

Any way to create the custom option for all simple products in Magento 2?

From Dev

magento - sort product collection by using addAttributeToSort for custom attribute - not working

From Dev

Delete option not working in Magento

From Dev

Magento Cart Get Custom Option (Text Field) Value in Model/Quote/Item.php

From Dev

How to Change the price before adding to cart in magento with custom option selection price?

From Dev

Changing 'Sort By Products' in Magento

From Dev

Magento - set custom sort by and order direction with Layout Updates for just one category

From Dev

Magento - set custom sort by and order direction with Layout Updates for just one category

From Dev

custom sort of `by=`

From Dev

Magento Get Option Label by Option Code

From Dev

Magento Custom options - custom dropdown

From Dev

Add option to Magento system admin

From Dev

Magento - Delete Product Type Option

From Dev

Magento Get Option Label or Title

From Dev

Magento - Delete Product Type Option

Related Related

  1. 1

    Magento Custom Sort Option

  2. 2

    Magento trigger shipping by custom option

  3. 3

    Magento trigger shipping by custom option

  4. 4

    how to change custom option price by query in magento?

  5. 5

    how to change custom option price by query in magento?

  6. 6

    Magento custom option with radio buttons on the same row

  7. 7

    MAGENTO Catalog-Product-Custom Options Adding a custom option

  8. 8

    MAGENTO Catalog-Product-Custom Options Adding a custom option

  9. 9

    Magento: Custom attributes option's new value field

  10. 10

    How to delete product custom option value programmatically in Magento?

  11. 11

    Magento - custom product option don't show in order

  12. 12

    magento 1.9.2.2 add to cart with custom option image not working

  13. 13

    Show Product custom option in reorder using observer in Magento

  14. 14

    Magento: Remove Dash from between sku and custom option sku

  15. 15

    Any way to create the custom option for all simple products in Magento 2?

  16. 16

    magento - sort product collection by using addAttributeToSort for custom attribute - not working

  17. 17

    Delete option not working in Magento

  18. 18

    Magento Cart Get Custom Option (Text Field) Value in Model/Quote/Item.php

  19. 19

    How to Change the price before adding to cart in magento with custom option selection price?

  20. 20

    Changing 'Sort By Products' in Magento

  21. 21

    Magento - set custom sort by and order direction with Layout Updates for just one category

  22. 22

    Magento - set custom sort by and order direction with Layout Updates for just one category

  23. 23

    custom sort of `by=`

  24. 24

    Magento Get Option Label by Option Code

  25. 25

    Magento Custom options - custom dropdown

  26. 26

    Add option to Magento system admin

  27. 27

    Magento - Delete Product Type Option

  28. 28

    Magento Get Option Label or Title

  29. 29

    Magento - Delete Product Type Option

HotTag

Archive