开发者

Magento Custom Module database query

开发者 https://www.devze.com 2023-01-22 01:30 出处:网络
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 fat

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('offerin开发者_运维知识库gs_id', 'DESC')
            ->setPageSize(5)
            ->setPage(1, 5);

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


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.


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

Magento get a product collection in an arbitrary order

0

精彩评论

暂无评论...
验证码 换一张
取 消