SwiftD
SwiftD

Reputation: 6069

magento bestsellers not working - seeking fix or workaround

I'm working on a magento site (Magento ver. 1.5.1.0) - Plese note in answering I am new to Magento. I am trying to get an option to sort by bestsellers I have managed to do this by adding local files to override the core files as follows:

httpdocs/app/code/local/Mage/Catalog/Block/Product/List/Toolbar.php:

 public function getAvailableOrders()
{
    //return $this->_availableOrder;
    //Custom Order list Edit
    $this->_availableOrder = array(
        'qty_ordered' => $this->__('Best Sellers'),
        'entity_id' => $this->__('Latest arrivals'),
        'name' => $this->__('Name'),
        'price' => $this->__('Price')
    );
    //Custom Available Order -Edit finish
    return $this->_availableOrder;
}

And httpdocs/app/design/frontend/default/localsite/template/catalog/product/list/toolbar.phmtl:

<fieldset class="sort-by">
    <label><?php echo $this->__('Sort by') ?></label>
    <select onchange="setLocation(this.value)">
        <option value="<?php echo $this->getOrderUrl('entity_id', 'desc') ?>"<?php if($this->isOrderCurrent('entity_id') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
            Newest Products
        </option>
        <option value="<?php echo $this->getOrderUrl('qty_ordered', 'desc') ?>"<?php if($this->isOrderCurrent('qty_ordered') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
            Best Sellers
        </option>
        <option value="<?php echo $this->getOrderUrl('price', 'asc') ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
            Lowest Price
        </option>
        <option value="<?php echo $this->getOrderUrl('price', 'desc') ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
            Highest Price
        </option>
        <option value="<?php echo $this->getOrderUrl('name', 'asc') ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'asc'): ?> selected="selected"<?php endif; ?>>
            Name A-Z
        </option>
        <option value="<?php echo $this->getOrderUrl('name', 'desc') ?>"<?php if($this->isOrderCurrent('name') && $this->getCurrentDirection() == 'desc'): ?> selected="selected"<?php endif; ?>>
            Name Z-A
        </option>
    </select>
</fieldset>

This works in the sense that I now have a bestsellers sort option which sorts in the same way as the bestsellers on the dashboard. Unfortunately the bestsellers section of the dashboard and consequently my sort list is entirely wrong.

Does anyone know how to fix this or failing that does anyone know another attribute I can sort by to achieve the same result - if I go to Dashboard>reports>products>Products Ordered I can get the order I want with a wide date range - any way to recreate this in the sort options.

Is there a list of available sort options out there somewhere?

******************UPDATE*******************

I have now noticed that the products listed in the bestsellers are all older products. The last 100 or so products which have been added are not included in the bestsellers list. These same products are also listed seperately if I sort by a to Z either in the dashboard or using the above sort option so that they go new products A to Z followed by older products A to Z. Any ideas what could be causing this?

Any tips, advice, help much appreciated.

Upvotes: 2

Views: 2249

Answers (1)

wierdo
wierdo

Reputation: 426

Since catalog products don't have an attribute called qty_ordered, you'll not have much luck that way. Whatever ordering you're seeing happen is either a secondary sorting column in action or the natural order coming from the database.

The backend uses the Mage_Reports module for view counts and the like. The most obvious way of getting to your goal seems to be adding a custom attribute to your products and writing an event observer to update it when sales are made. If you make sure to set "Used for Sorting in Product Listing" it should be available for sorting automagically without having to override any core classes.

Other than that, the only things I can think of involve a lot of complicated class overrides that would very likely break something on upgrade.

Upvotes: 1

Related Questions