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 8812739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:40:23+00:00 2026-06-14T03:40:23+00:00

I am not sure why this loop is not working. $orders = Mage::getSingleton(‘sales/order’)->getCollection() ->addAttributeToSelect(‘*’)

  • 0

I am not sure why this loop is not working.

    $orders = Mage::getSingleton('sales/order')->getCollection()  
        ->addAttributeToSelect('*')  
        ->addFieldToFilter('created_at', array('from'=>$from, 'to'=>$to)) 
        ->addAttributeToSort('increment_id', 'ASC')
        ;

    foreach ($orders as $item) { 
        $order_id = $item->increment_id;
        if (is_numeric($order_id)) $order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
        if (is_object($order)) {
            echo "> O: ". $order_id ."<BR>";
            $items = $order->getAllItems();
            echo ">> O: ". $order_id ."<BR>";
        } else
            die("DIE ". var_dump($order));  
    }
die("<BR> DONE");

The output:

...
...
>> O: 100021819
> O: 100021820
>> O: 100021820
> O: 100021821

The loop never finishes nor does it stop at the same order_id.?

It always fails at $order->getAllItems()

These orders are either pending, processing or complete.

Is there something I should be checking for with $order->getAllItems(), since that’s were it’s failing.

Thanks.

  • 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-06-14T03:40:24+00:00Added an answer on June 14, 2026 at 3:40 am

    Jon, I assume the problem you’re talking about is your script ending un expectedly. i.e., you see the output with a single >

    > O: 100021821
    

    but not the output with the double >>.

    Because Magento is so customizable, it’s impossible to accurately diagnose your problem with the information given. Something is happening in your system, (a PHP error, an uncaught exception, etc.), that results in your script stopping. Turn on developer mode and set the PHP ini display_errors to 1 (ini_set('display_errors', 1);) and check your error log. One you (or we) have the PHP error, it’ll be a lot easier to help you.

    My guess is you’re running into a memory problem. The way PHP has implemented objects can lead to small memory leaks — objects don’t clean up after themselves correctly. This means each time you go through the loop you’re slowly consuming the total amount of memory that’s allowed for a PHP request. For a system with a significant number of orders, I’d be surprised if the above code could get through everything before running out of memory.

    If your problem is a memory problem, there’s information on manually cleaning up after PHP’s objects in this PDF. You should also consider splitting your actions into multiple requests. i.e. The first request handles orders 1 – 100, the next 101 – 200, etc.

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

Sidebar

Related Questions

Not sure the title explains the problem well; this is what I'm working with,
I am not sure if this is possible, I am working on a website
I'm working on some beginning Java logic, and I'm not sure why this is
This does not seem to be working I am not sure how to get
I'm not sure why this isn't working... HTML <table> <tr> <th>Name</th> <th>Options</th> </tr> <?php
Not sure this is a known issue. I’m using VS2012 RC (Ultimate), and Win8
Not sure this is possible, but looking to write a script that would return
Disclaimer: not sure this is WordPress related or not. I'm following a simple tutorial
I'm not sure this is the right forum if it's not please feel free
I'm not sure this is even possible but I know if it is, the

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.