Magento – Adding order comments to invoices

invoicemagento-1.7orders

When I print a pdf of a particular invoice, I'd like it to include order comments as well. I have no idea what files I need to edit to make this happen.

I tried following the instructions here to no avail.

Best Answer

The last post used the getVisibleStatusHistory method of the order object, but the first comment entered on an order is never visible. There are several methods for grabbing the status history and setting it in the order object.

That being said we might want to list all of the comments that are marked as visible on front-ed and the first comment entered when the order is created. I've substitued your formatting with a "p" tag.

<?php $_history = $order->getAllStatusHistory(); ?>
<?php $_buffer = array(); ?>
<?php $_i=1; ?>

<?php foreach ($_history as $_historyItem): ?>
<?php // Ignore the visibility for the first comment ?>
<?php if ( $_historyItem->getData('is_visible_on_front') == 1 || $_i == count($_history) ): ?>
    <?php $_buffer[] = $_historyItem->getData('comment'); ?>
<?php endif; ?>
<?php $_i++; ?>
<?php endforeach; ?>

<?php if ( count($_buffer) > 0 ): ?>
   <p><?php echo implode( $_buffer, '</p><p>' ); ?></p>
<?php endif ?>