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

  • Home
  • SEARCH
  • 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 9233441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:33:16+00:00 2026-06-18T06:33:16+00:00

I have a code below (simplified) to add a comment to current order in

  • 0

I have a code below (simplified) to add a comment to current order in customer’s account -> orders -> view (order detail).

The code is working fine. The only thing is, that after processing the comment sent by form and calling getVisibleStatusHistory(), all comments are sorted by date/time (descending) correctly except the comment recently added by customer. That comment is added as the last one in the result – which doesn’t correspond to the descending sorting of the getVisibleStatusHistory() result. After reloading the page it’s correctly sorted.

All code is in customized view.phtml

I have a form sending comment:

<form action="" method="post">
  <textarea name="ordercomment" maxlength="1000"></textarea>
  <input type="submit" value="Send" />
</form>

it is processed by the view.phtml as well:

$ordcomment = $_POST['ordercomment'];
$_order->addStatusHistoryComment($ordcomment)->setIsVisibleOnFront(1);
$_order->save();

and after that script to print all visible comments:

<?php $_history = $this->getOrder()->getVisibleStatusHistory() ?>
<?php if (count($_history)): ?>
<div class="order-additional order-comments">
    <h2 class="sub-title"><?php echo $this->__('About Your Order') ?></h2>
    <dl class="order-about">        
        <?php foreach ($_history as $_historyItem): ?>
            <dt><?php echo $this->formatDate($_historyItem->getCreatedAtStoreDate(), 'medium', true) ?></dt>
           <dd><?php echo $this->escapeHtml($_historyItem->getComment()) ?></dd>
        <?php endforeach; ?>
    </dl>
</div>
<?php endif; ?>

Does anyone know what is the reason, why last added comment is not sorted properly among the others?

  • 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-18T06:33:17+00:00Added an answer on June 18, 2026 at 6:33 am

    The reason of this strange sorting is that when you add a new history item to the order’s status history collection, the order loads the existing collection (sorted) and adds the new item to its end.

    To output the collection correctly, you can reload the order object and with that the history collection will be fetched in a proper order:

    <?php 
    $orderNew = Mage::getModel('sales/order')->load($this->getOrder()->getId());
    $_history = $orderNew->getVisibleStatusHistory() ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to use a recursive function in python, code below is a simplified
Consider the code below (which has been simplified). I have a service class that
I have a class ComponentItem which i simplified (pseudo code) below public class ComponentItem
I have the below (simplified) code, which uses the following source: <html> <p>line 1</p>
I have a list of divs similar to the simplified code below, which I've
I have code below: <select id=testSelect> <option value=1>One</option> <option value=2>Two</option> </select> <asp:Button ID=btnTest runat=server
I have code that looks more or less like the code below but it
I have code as below: var s : String = hello world var xml
I have the code below. It looks long and complicated and now I have
I have the code below. void *timer1_function(void * eit); pthread_t timer1; int thread_check1 =

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.