2
votes

I have had to make some changes to the catalog page (list.phtml) in Magento, everything is fine except for the 'Sort By' name, position etc...

Here is my code:

$_productCollection= Mage::getModel('catalog/product')->getCollection()
                     ->addAttributeToSelect('*')
                     ->addStoreFilter()
                     ->setPage(Mage::getBlockSingleton('page/html_pager')->getCurrentPage(), $limit)
                     ->setPageSize( $limit )
                     ->setOrder($this->getCurrentOrder(), $this->getCurrentDirection())
                     ->load();

There is something wrong here clearly as nothing happens when trying to sort the results bu name, position etc!

Obviously there is something wrong with this line:

->setOrder($this->getCurrentOrder(), $this->getCurrentDirection())

I am also having a problem with Simple products that are set to not show individually are showing! I have missed something from there also.

If someone could steer me towards the correct functions/syntax that would be great!

1
Mage::log($this->getCurrentOrder()); Mage::log($this->getCurrentDirection()); - what does it tell you? - benmarks

1 Answers

6
votes

I solved the ordering issue!

->setOrder(Mage::getBlockSingleton('catalog/product_list_toolbar')->getCurrentOrder(), Mage::getBlockSingleton('catalog/product_list_toolbar')->getCurrentDirection())

And products set to not show individually:

->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds())

So the full code for anyone else:

if( $this->getMode()!='grid' ) {
    $limit = Mage::getStoreConfig('catalog/frontend/list_per_page'); 
}
else {
    $limit = Mage::getStoreConfig('catalog/frontend/grid_per_page');
}   
  $_productCollection= Mage::getModel('catalog/product')->getCollection()
                        ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
                         ->addAttributeToSelect('sku_base')
                         ->addStoreFilter(Mage::app()->getStore()->getId())
                         ->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds())
                         ->setPage(Mage::getBlockSingleton('page/html_pager')->getCurrentPage(), $limit)
                         ->setPageSize( $limit )
                         ->setOrder(Mage::getBlockSingleton('catalog/product_list_toolbar')->getCurrentOrder(), Mage::getBlockSingleton('catalog/product_list_toolbar')->getCurrentDirection())
                         ->load();