This will be a short post about an error I ran into when messing around with the Magento “Toolbar” that is displayed for search results and on category pages. I decided that i needed to extend the toolbar block in-order to achieve some custom functionality that a client needed. Then I noticed that when I sorted by price I got the following error “You cannot define a correlation name ‘_price_order_table’ more than once“.  In my case I had extended the setCollection function.

My problem(Error) began because I was calling the parent method then was setting the order on the collection again, and Magento did not like it.

     public function setCollection($collection)
    {
        parent::setCollection($collection);
        //The next three lines were what were causing the problem.
        //Because setOrder was called in the parent function it threw the error when it was called again.
        #if ($this->getCurrentOrder()) {
        #    $this->getCollection()->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
        #}
        //Custom code went here
        return $this;
    }