lundi 29 juin 2015

Magento search results in wrong order


I'm working on a Magento 1.9.1.0 project and the search results aren't being displayed in the correct order. I've modified a function to fetch the results in order of position (which almost works), but it appears to be looping through each category first, listing the products from that category in order of position and name and then moving on to the next category - for example, if I search "a":

Anti-Slip Bath Mat, Bath Safety Strips, Square Shower Mat, Walking Frame, (here the order breaks, because it's entered a new category) Alarm Clock, Amplified Phone.

I'd have liked it to have returned:

Alarm Clock, Amplified Phone, Bath Safety Strips, Square Shower Mat, Walking Frame, Anti-Slip Bath Mat

(Anti-Slip Bath Mat would be last, because the position of everything else is 0 where as this product has a position of 10).

Is there a way I can amend this search just display all products without ordering them in category order? The function I'd written to achieve what I have so far is:

public function setListOrders()
{
    $category = Mage::getSingleton('catalog/layer')
        ->getCurrentCategory();
    /* @var $category Mage_Catalog_Model_Category */
    $availableOrders = $category->getAvailableSortByOptions();
    unset($availableOrders['position']);
    $availableOrders = array_merge(array(
        'relevance' => $this->__('Relevance'),
        'name' => $this->__('Name'),
        'position' => $this->__('Position')
    ), $availableOrders);

    $this->getListBlock()
        ->setAvailableOrders($availableOrders)
        ->setDefaultDirection('asc')
        ->setSortBy('position');
    return $this;

}

and...

protected function _getProductCollection()
{
    if (is_null($this->_productCollection)) {
        $this->_productCollection = $this->getListBlock()->getLoadedProductCollection();
    }

return $this->_productCollection->addAttributeToSort('position')->addAttributeToSort('name');

}


Aucun commentaire:

Enregistrer un commentaire