Magento 2 – Show Products and Shipping Method on Order Success Page

magento2order-success-pageshipping-methods

enter image description here

htdocs/vendor/magento/module-checkout/view/frontend/templates/success.phtml

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php /** @var $block \Magento\Checkout\Block\Onepage\Success */ ?>
<div class="checkout-success">
    <?php if ($block->getOrderId()):?>
        <?php if ($block->getCanViewOrder()) :?>
            <p style=" font-size: 19px; font-weight: 700;color: #4F91D0;" ><?= __('Your order number is: %1.', sprintf('<a href="%s" class="order-number" ><strong style="font-weight: 600; color: white; background-color: #4F91D0; font-size: 30px;" >%s</strong></a>', $block->escapeHtml($block->getViewOrderUrl()), $block->escapeHtml($block->getOrderId()))) ?></p>
        <?php  else :?>
            <p><?= __('Your order # is: <span>%1</span>.', $block->escapeHtml($block->getOrderId())) ?></p>
        <?php endif;?>
           <!-- <p><?= /* @escapeNotVerified */ __('We\'ll email you an order confirmation with details and tracking info.') ?></p>-->
    <p>
        Enviaremos para você um e-mail de confirmação do seu pedido com detalhes e informações de rastreamento.
        Adicione o e-mail <a href="mailto:suporte@suporte.com.br"> suporte@suporte.com.br</a> a no seu livro de endereços e verifique  sua pasta de spam caso não receba o  e-mail de confirmação do pedido.<br>
        Agora é só aguardar a confirmação do seu pagamento. Você receberá um e-mail assim que o seu pagamento for confirmado.<br>
        Em caso de dúvidas, entre em contato com o e-mail informado acima ou ligue-nos no <a href="tel:40201702">0000-0000</a> (custo de ligação local).
    </p>
    <br>
    <h2>Status do Pedido</h2>
    <!-- <p class="status">&nbsp;</p> -->
    <div id="status_bar">
        <img class="status" src="https://d2fqgw7smz4ag9.cloudfront.net/pub/media/wysiwyg/status-1.gif" />
    </div>

    <h2>Suas Compras</h2>

    <?= $block->getProductItem() ?> //This is where I want you to display the purchase you made

    <h2>Dados do Envio</h2>  

    <?= $block->getMethodShipping() ?> //This is where I want you to display the delivery method selected by the user.


 <?php endif;?>

    <?= $block->getAdditionalInfoHtml() ?>

    <div class="actions-toolbar">
        <div class="primary">
            <a class="action primary continue" href="<?= /* @escapeNotVerified */ $block->getContinueUrl() ?>"><span><?= /* @escapeNotVerified */ __('Continue Shopping') ?></span></a>
        </div>
    </div>
</div>

htdocs/vendor/magento/module-checkout/Block/Onepage

/* Methods for displaying purchased products and selected shipping method */

public function getProductItem()
{
    return 'View my purchase'; //What would the method of displaying a purchase look like?
}

public function getMethodShipping()
{
    return 'Selected Shipping Type'; //What would be the method for displaying the selected shipping type?
}

Best Answer

Create module for that don't make changes in core files.

Download Module

  • You can show all order details by following steps.

    Remove from xml which you dont want to display.

create app\code\Ketan\Module\view\frontend\layout\checkout_onepage_success.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="sales_order_item_renderers"/>
    <update handle="sales_order_item_price"/>
    <body>
        <referenceBlock name="checkout.success" remove="true"/>
        <referenceContainer name="content">
            <block class="Magento\Checkout\Block\Onepage\Success" name="ketan.checkout.success" template="Ketan_Module::onepage/success.phtml" cacheable="false">
                <block class="Ketan\Module\Block\Onepage\Success\Details" name="ketan.checkout.success.details" as="details" template="Ketan_Module::onepage/details.phtml" cacheable="false">
                    <block class="Magento\Sales\Block\Order\Info" as="info" name="sales.order.info" />
                    <block class="Magento\Sales\Block\Order\View" name="sales.order.view" cacheable="false" as="order_view" template="Ketan_Module::onepage/details/order/view.phtml">
                        <block class="Magento\Sales\Block\Order\Items" name="order_items" template="order/items.phtml">
                            <block class="Magento\Framework\View\Element\RendererList" name="sales.order.items.renderers" as="renderer.list"/>
                            <block class="Magento\Sales\Block\Order\Totals" name="order_totals" template="order/totals.phtml">
                                <arguments>
                                    <argument name="label_properties" xsi:type="string">colspan="4" class="mark"</argument>
                                    <argument name="value_properties" xsi:type="string">class="amount"</argument>
                                </arguments>
                                <block class="Magento\Tax\Block\Sales\Order\Tax" name="tax" template="order/tax.phtml"/>
                            </block>
                        </block>
                    </block>
                </block>
                <container name="order.success.additional.info" label="Order Success Additional Info"/>
            </block>
        </referenceContainer>
    </body>
</page>

create Block file for template app\code\Ketan\Module\Block\Onepage\Success\Details.php

<?php

namespace Ketan\Module\Block\Onepage\Success;

use Magento\Framework\View\Element\Template;

class Details extends Template
{
    /**
     * @var \Magento\Framework\Registry
     */
    protected $registry;
    /**
     * @var \Magento\Checkout\Model\Session
     */
    protected $session;

    public function __construct(
        Template\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Checkout\Model\Session $session,
        array $data = []
    ) {
        parent::__construct($context, $data);
        $this->registry = $registry;
        $this->session = $session;
    }

    protected function _prepareLayout()
    {
        if (!$this->registry->registry('current_order')) {
            $this->registry->register('current_order', $this->getOrder());
        }

        return parent::_prepareLayout();
    }

    /**
     * Retrieve current order model instance
     *
     * @return \Magento\Sales\Model\Order
     */
    public function getOrder()
    {
        return $this->session->getLastRealOrder();
    }
}

Create view files which are override from xml files

  1. app\code\Ketan\Module\view\frontend\templates\onepage\details.phtml

https://pastebin.com/b0LDaHYu

  1. app\code\Ketan\Module\view\frontend\templates\onepage\success.phtml

https://pastebin.com/dL6vCXGQ

  1. app\code\Ketan\Module\view\frontend\templates\onepage\details\order\view.phtml

https://pastebin.com/9edArjFL

enter image description here

Related Topic