0

I am new to Magento 2.

I want to show comments added by Admin User against a particular order placed. I want to display this comments in table grid of My order section for customer login.

1 Answer 1

0

Step -1

Go to the \vendor\magento\module-sales\view\frontend\templates\order\History.phtml and override this file into your theme.

Step -2 Please add the below code into overridden History.phtml.

.................................................
<?php foreach ($_orders as $_order) : ?>
                    <?php 
        $history = [];
        foreach ($_order->getAllStatusHistory() as $orderComment) {
            $history[] = [
                'title' =>$orderComment->getStatusLabel(),
                'notified' =>$orderComment->getIsCustomerNotified(),
                'created_at' =>$this->getOrderAdminDate($orderComment->getCreatedAt()),
                'comment' =>$orderComment->getComment()
            ];
        }

        foreach ($_order->getCreditmemosCollection() as $_memo) {
            $history[] = [
                'title' =>__('Credit memo #%1 created', $_memo->getIncrementId()),
                'notified' =>$_memo->getEmailSent(),
                'created_at' =>$this->getOrderAdminDate($_memo->getCreatedAt()),
                'comment' => ''
            ];

            foreach ($_memo->getCommentsCollection() as $_comment) {
                $history[] = [
                   'title' => __('Credit memo #%1 comment added', $_memo->getIncrementId()),
                    'notified' =>$_comment->getIsCustomerNotified(),
                    'created_at' =>$this->getOrderAdminDate($_comment->getCreatedAt()),
                    'comment' =>$_comment->getComment()
                ];
            }
        }

        foreach ($_order->getShipmentsCollection() as $_shipment) {
            $history[] = [
                'title' =>__('Shipment #%1 created', $_shipment->getIncrementId()),
                'notified' =>$_shipment->getEmailSent(),
                'created_at' =>$this->getOrderAdminDate($_shipment->getCreatedAt()),
                'comment' => ''
            ];

            foreach ($_shipment->getCommentsCollection() as $_comment) {
                $history[] = [
                    'title' =>__('Shipment #%1 comment added', $_shipment->getIncrementId()),
                    'notified' =>$_comment->getIsCustomerNotified(),
                    'created_at' =>$this->getOrderAdminDate($_comment->getCreatedAt()),
                    'comment' =>$_comment->getComment()
                ];
            }
        }

        foreach ($_order->getInvoiceCollection() as $_invoice) {
            $history[] = [
                'title' =>__('Invoice #%1 created', $_invoice->getIncrementId()),
                'notified' =>$_invoice->getEmailSent(),
                'created_at' =>$this->getOrderAdminDate($_invoice->getCreatedAt()),
                'comment' => ''
            ];

            foreach ($_invoice->getCommentsCollection() as $_comment) {
                $history[] = [
                    'title' =>__('Invoice #%1 comment added', $_invoice->getIncrementId()),
                    'notified' =>$_comment->getIsCustomerNotified(),
                    'created_at' =>$this->getOrderAdminDate($_comment->getCreatedAt()),
                    'comment' =>$_comment->getComment()
                ];
            }
        }

        foreach ($_order->getTracksCollection() as $_track) {
            $history[] = [
                'title' =>__('Tracking number %1 for %2 assigned', $_track->getNumber(), $_track->getTitle()),
                false,
                'created_at' =>$this->getOrderAdminDate($_track->getCreatedAt())
            ];
        }
        echo "<pre>";
        print_r($history);
        die();
        .....................................
 <?php endforeach; ?>

You can get all the history comments. you can implement based form this $history array.

I hope this is helpful to you!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.