Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

AJuda Ordenação
 
Michel Brito
Jr. Member
 
Total Posts:  2
Joined:  2009-07-20
 

eu gostaria de ordenar por produtos mais vendidos
e na ordenação de preço ele gera uma sql de ordenação, mas não fica totalmente correto

exemplo do resultado:
1.20
2.40
32.00
4.67
71.99
88.00

segue o codigo abaixo:

public function _getProductCollection() {
        
if (is_null($this->_productCollection)) {
            $layer 
Mage::getSingleton('catalog/layer');
            if (
$this->getShowRootCategory()) {
                $this
->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
            
}

            
if (Mage::registry('product')) {
                $categories 
Mage::registry('product')->getCategoryCollection()
                    ->
setPage(11)
                    ->
load();
                if (
$categories->count()) {
                    $this
->setCategoryId(current($categories->getIterator()));
                
}
            }

            $origCategory 
null;
            if (
$this->getCategoryId()) {
                $category 
Mage::getModel('catalog/category')->load($this->getCategoryId());
                if (
$category->getId()) {
                    $origCategory 
$layer->getCurrentCategory();
                    
$layer->setCurrentCategory($category);
                
}
            }

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

            
$this->_productCollection->addAttributeToSelect'*' );

            if( isset( 
$_GET['filter_by') ) {
                $this
->_productCollection->addAttributeToFilter$_GET['filter_by']true );
                
$this->_productCollection->addAttributeToSort$_GET['filter_by');
            
}

            
if( isset( $_GET['order_by') ) {
                    $this
->_productCollection->addAttributeToSort$_GET['order_by'], !isset( $_GET[ 'order' ) ? 'asc' $_GET[ 'order' );
            
}else{
                $this
->_productCollection->addAttributeToSort('created_at''desc');
            
}

            
if ($sortField $this->getSortBy()) {
                $sortOrder 
'asc';
                if (
strtolower($this->getSortOrder()) == 'desc'{
                    $sortOrder 
'desc';
                
}
            }

            
if ($origCategory{
                $layer
->setCurrentCategory($origCategory);
            
}

            $this
->_productCollection->addAttributeToSelect('marca''left'); //addAttributeToSort( 'marca', 'desc' );
            
$this->_productCollection->groupByAttribute('marca');

            
//echo $this->_productCollection->getSelectSql();exit;

        
}
        
return $this->_productCollection;
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top