0

I am using Magento 2.1 . I want to display purchase order number in customer dashboard.

enter image description here

1
  • did you figure out from which file its calling? Jan 7, 2019 at 21:53

1 Answer 1

1

You need to override recent.phtml template files in Magento_Sales module.
To fetch the purchase order number in the recent.phtml you can use the following code

$_order->getPayment()->getPoNumber()

You can try following code and modify it according to your requirement.

app/code/Anshu/Custom/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Anshu_Custom" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Sales"/>
        </sequence>
    </module>
</config>

app/code/Anshu/Custom/registration.php

<?php

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
    ComponentRegistrar::MODULE,
    'Anshu_Custom',
    __DIR__
);

app/code/Anshu/Custom/view/frontend/layout/customer_account_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Magento\Sales\Block\Order\Recent" name="customer_account_dashboard_top" template="Anshu_Custom::recent.phtml"/>
        </referenceContainer>
    </body>
</page>

app/code/Anshu/Custom/view/frontend/templates/recent.phtml

<div class="block block-dashboard-orders">
    <?php
    $_orders = $block->getOrders();
    $count = count($_orders);
    ?>
    <div class="block-title order">
        <strong><?= /* @escapeNotVerified */ __('Recent Orders') ?></strong>
        <?php if ($count > 0): ?>
            <a class="action view" href="<?= /* @escapeNotVerified */ $block->getUrl('sales/order/history') ?>">
                <span><?= /* @escapeNotVerified */ __('View All') ?></span>
            </a>
        <?php endif; ?>
    </div>
    <div class="block-content">
        <?= $block->getChildHtml() ?>
        <?php if ($count > 0): ?>
            <div class="table-wrapper orders-recent">
                <table class="data table table-order-items recent" id="my-orders-table">
                    <caption class="table-caption"><?= /* @escapeNotVerified */ __('Recent Orders') ?></caption>
                    <thead>
                    <tr>
                        <th scope="col" class="col id"><?= /* @escapeNotVerified */ __('Order #') ?></th>
                        <th scope="col" class="col po"><?= /* @escapeNotVerified */ __('Purchase Order #') ?></th>
                        <th scope="col" class="col date"><?= /* @escapeNotVerified */ __('Date') ?></th>
                        <th scope="col" class="col shipping"><?= /* @escapeNotVerified */ __('Ship To') ?></th>
                        <th scope="col" class="col total"><?= /* @escapeNotVerified */ __('Order Total') ?></th>
                        <th scope="col" class="col status"><?= /* @escapeNotVerified */ __('Status') ?></th>
                        <th scope="col" class="col actions"><?= /* @escapeNotVerified */ __('Action') ?></th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($_orders as $_order): ?>
                        <tr>
                            <td data-th="<?= $block->escapeHtml(__('Order #')) ?>" class="col id"><?= /* @escapeNotVerified */ $_order->getRealOrderId() ?></td>
                            <td data-th="<?= $block->escapeHtml(__('Purchase Order #')) ?>" class="col purchaseorder"><?= /* @escapeNotVerified */ $_order->getPayment()->getPoNumber() ?></td>
                            <td data-th="<?= $block->escapeHtml(__('Date')) ?>" class="col date"><?= /* @escapeNotVerified */ $block->formatDate($_order->getCreatedAt()) ?></td>
                            <td data-th="<?= $block->escapeHtml(__('Ship To')) ?>" class="col shipping"><?= $_order->getShippingAddress() ? $block->escapeHtml($_order->getShippingAddress()->getName()) : '&nbsp;' ?></td>
                            <td data-th="<?= $block->escapeHtml(__('Order Total')) ?>" class="col total"><?= /* @escapeNotVerified */ $_order->formatPrice($_order->getGrandTotal()) ?></td>
                            <td data-th="<?= $block->escapeHtml(__('Status')) ?>" class="col status"><?= /* @escapeNotVerified */ $_order->getStatusLabel() ?></td>
                            <td data-th="<?= $block->escapeHtml(__('Actions')) ?>" class="col actions">
                                <a href="<?= /* @escapeNotVerified */ $block->getViewUrl($_order) ?>" class="action view">
                                    <span><?= /* @escapeNotVerified */ __('View Order') ?></span>
                                </a>
                                <?php if ($this->helper('Magento\Sales\Helper\Reorder')->canReorder($_order->getEntityId())) : ?>
                                    <a href="#" data-post='<?php /* @escapeNotVerified */ echo
                                    $this->helper(\Magento\Framework\Data\Helper\PostHelper::class)
                                        ->getPostData($block->getReorderUrl($_order))
                                    ?>' class="action order">
                                        <span><?= /* @escapeNotVerified */ __('Reorder') ?></span>
                                    </a>
                                <?php endif ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        <?php else: ?>
            <div class="message info empty"><span><?= /* @escapeNotVerified */ __('You have placed no orders.') ?></span></div>
        <?php endif; ?>
    </div>
</div>
2
  • Thanks for you response. without overriding the recent.phtml template, can we change only recent.phtml file
    – kiran
    Jan 8, 2019 at 13:52
  • @kiran if you don't want to override using module than you override it in your custom theme. But anyway you have to override it as doing change directly in core file is a bad coding practice. Jan 8, 2019 at 15:22

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.