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

Order by price, mysql error
 
WillSeeds
Jr. Member
 
Avatar
Total Posts:  2
Joined:  2009-02-17
 

Hello,

In a custom block i run the following code:

$this->category Mage::registry('current_category');
$products $this->category->getProductCollection();
$products->getSelect()->order('price''desc');

But that gives a error:

There has been an error processing your request.
SELECT `e`.*, `cat_index`.`position` FROM `catalog_product_entity` AS `e`
INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=’1’ AND cat_index.category_id=’3’ AND cat_index.is_parent=1 ORDER BY `price` ASC

if i copy past the query given by the error into MySql query browser it gives me this error:
Unknown column ‘price’ in order clause

Now the weird thing, if i change the query in (different quotes):

SELECT `e`.*, `cat_index`.`position` FROM `catalog_product_entity` AS `e`
INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=’1’ AND cat_index.category_id=’3’ AND cat_index.is_parent=1 ORDER BY price ASC

it works?!

Does anyone know the solution to this problem?

 
Magento Community Magento Community
Magento Community
Magento Community
 
WillSeeds
Jr. Member
 
Avatar
Total Posts:  2
Joined:  2009-02-17
 

Solved:

$this->category = Mage::registry(’current_category’);
$products = $this->category->getProductCollection();
$products->addAttributeToSort(’price’, ‘desc’);

works

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top