I'm trying to edit how my products are ordered in the Magento products list once a user has selected the price drop-down to display the cheapest first. This shows the prices with 0 on the top when listed, shown as:

```
Product 4 £0
Product 5 £0
Product 1 £50
Product 2 £65
Product 3 £80

```

At the moment it would show as this:

```
Product 1 £50
Product 2 £65
Product 3 £80
Product 4 £0
Product 5 £0

```

I have managed to edit the `_getProductCollection()` method inside the file `/app/code/core/Mage/Catalog/Block/Product/List.php` (don't worry I've copied to local) and added these few lines:

```
$orderFilterType = $this->getRequest()->getParam('order');
$dirFilterType = $this->getRequest()->getParam('dir');

if( isset( $orderFilterType ) && $orderFilterType == 'price' && isset( $dirFilterType ) && $dirFilterType == 'asc' ) {

$this->_productCollection = $layer->getProductCollection();

$order_field = 'new_price_for_sort';

$this->_productCollection->getSelect()->joinLeft( array('a' => 'catalog_product_entity_price'), 'a.product_id=e.entity_id AND a.attibute_id=PRICE or SPECIAL PRICE ATTRIBUTE ID', array('new_price_for_sort' => new Zend_Db_Expr('IF(a.value > 0,1, 0)') ) );

$this->_productCollection->getSelect()->reset(Zend_Db_Select::ORDER);

$dir = 'DESC'; 

if ( !$this->_productCollection->isEnabledFlat() ) { 

$this->_productCollection->setOrder($order_field, $dir); 

} else {

$this->_productCollection->getSelect()->order($order_field . ' ' . $dir); 

}

$this->_productCollection->setOrder('price', $dir);

} else { $this->_productCollection = $layer->getProductCollection(); }

```

This means that anytime somebody selects the price, asc filter from the drop-down then it adds the price sort using `addAttributeToSort` which works fine but I can't work out how to get the 0 priced products to go to the bottom using this.

In SQL I'd usually use a CASE statement such as:

```
SELECT * FROM table ORDER BY CASE price WHEN 0 then 1 ELSE 0 END, price

```

However I have no idea how I would implement something like this in my code above.