tags:

views:

29

answers:

3

Hi,

I have written a module to add my own events, and in the home page i would like to show only latest events. So in that case i have to add order by to query but i couldnot do that, it always throws fatal error.

This is what i have done.

$_offers = Mage::getSingleton('offerings/offerings')->getCollection();  

This returns all the records, here i could able to set filter options but i could not add sort order like this

$_offers = Mage::getModel('offerings/offerings')->getCollection()
            ->addAttributeToSort('offerings_id', 'DESC')
            ->setPageSize(5)
            ->setPage(1, 5);

or even using Mage::getSingleton. Whats the problem here am facing. Please help me

A: 

Include an error message and people can start helping you.

My guess if you've used Module Creator to create your module, which gives you a default non-eav model and collection. The addAttributeToSort method only exists for EAV collections.

There's more information on your various sorting options here

http://stackoverflow.com/questions/3990266/magento-get-a-product-collection-in-an-arbitrary-order/3990800#3990800

Alan Storm
exactly, you are right. Used Module creator and it doesnot extend the EAV classes, so how could i use the query to sort it out. thanks
Ela
A: 

I haven't put in the time to test but I suspect you need to do something like this:

$_offers = Mage::getModel('offerings/offerings')->getCollection()
            ->setOrder('offerings_id', 'DESC')
            ->setPageSize(5);

As pointed out the EAV method addAttributeToSort() won't work here. Nor will setPage() but setPageSize() is just as good.

There are plenty of tutorials and guides around to learn this stuff from. Alan's knowledgebase articles are the authoritative resource on the subject, you would do well to read and practice it all.

clockworkgeek
A: 

I dont know why the people marking minus grade to my questions. Its reducing my reputation 110 to 5 . Was there something wrong with asking questions and am participating my answers too. I want to see the reason why the people marking minus grades. Thanks

Ela