Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6899747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:27:38+00:00 2026-05-27T07:27:38+00:00

i have this method on which i retrieve first a Varien_Data_Collection and then I

  • 0

i have this method on which i retrieve first a Varien_Data_Collection and then I add items one by one from another Varien_Data_Collection by addItem():

    protected function _prepareCollection(){

    $productId = $this->getRequest()->getParam('id');
    $websiteId = 0;
    if ($store = $this->getRequest()->getParam('store')) {
        $websiteId = Mage::app()->getStore($store)->getWebsiteId();

        $collection = Mage::getModel('productalert/stock')
                ->getCustomerCollection()
                ->join($productId, $websiteId); 

        foreach ($collection as $item) {
            $item->setData('is_customer', 'Sì');
        }


        $guestCollection = Mage::getModel('productsalert/gueststock')->getCollection()
                ->addFieldToFilter("product_id", $productId)
                ->addFieldToFilter("website_id", $websiteId);


        foreach ($guestCollection as $guestItem) {
            $obj = new Mage_Customer_Model_Customer();
            $obj->setData($guestItem->getData());
            $obj->setData('alert_stock_id', ($guestItem->getData('alert_stock_id')+100000000));
            $obj->setData('email', $guestItem->getData('guest_email'));
            $obj->setData('is_customer', 'No');
            $collection->addItem($obj);
        }
        $collection = $collection->setOrder('add_date','ASC');
        $this->_sortCollectionDescByDate($collection);
        $this->setCollection($collection);
    }
    else{
        $this->setCollection(new Varien_Data_Collection());
    }




    return parent::_prepareCollection();

}   

So when i have the final collection i want to set the order since items in it have one attribute in common (‘add_date’), so i set the setOrder methos, but it doesn’t work (soemone on IRC told me that setOrder modify the query). so I can do it manually but it seems strange to me that there’s not to order a collection after adding items. i took a look on Varien_Data_Collection API but I don’t see anything that could help me. I’ve also tried to change the collection class to Varien_Data_Collection_Db and setting the addOrder() method but nothing has changed.

any idea?

thanks!

Luke

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:27:39+00:00Added an answer on May 27, 2026 at 7:27 am

    You can call

    $collection->clear();
    $collection->....//here you add some logic for ordering;
    $collection->load();//here collection with new filters will be loaded. 
    

    OR

    You can have some kind of sorting function like specified here in the last message.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: s(x => x.Open()); s is a method which calls one
Example: I have a selector like this, which I give to another method as
I have this recursive method which deletes empty folders: private void DeleteEmpty(DirectoryInfo directory) {
I have this method Verify_X which is called during databind for a listbox selected
I have a method which runs this: Track* track = [[Track alloc] init:[obj objectForKey:@PersistentID]
I have a method, which uses random samples to approximate a calculation. This method
I have an interface called Dictionary which has a method insert() . This interface
I have a Jtable on which I called the method table1.setAutoCreateRowSorter(true); . So this
I am trying to retrieve data from a page which first requires to log
I'm working on a Symfony project (my first) where I have to retrieve, from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.