0

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?
}
0

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

  • thank you for your answer! In this solution would also be able to display the image of the products? – R.Park Aug 5 '19 at 14:26
  • NO! it's default as order view page for that you have to override order/items.phtml and order\items\renderer\default.phtml or extend it to current module from default module-sales – Ketan Borada Aug 6 '19 at 6:38
0

Please try with below code :

like : pass $block->getOrderId() in $block->getMethodShipping($block->getOrderId())

public function getMethodShipping($orderid)
{
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); //if it's working than please use via construct  
    $order = $objectManager->create('Magento\Sales\Model\Order')->load($orderid);
    return $order->getShippingMethod();
}

same process do with getProductItem()

I hope its working

  • I change the start of the succes.phtml container? <?php if ($block->getOrderId()):?> to $block->getMethodShipping($block->getOrderId()) is this ? – R.Park Aug 1 '19 at 14:29
  • If you want to add this code in phtml than directly use $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); //if it's working than please use via construct $order = $objectManager->create('Magento\Sales\Model\Order')->load($block->getOrderId()); print_r( $order->getShippingMethod()); – Anas Mansuri Aug 1 '19 at 18:47
0

Please try with below code :

1) Override order success block

app/code/CompanyName/ModuleName/etc/di.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Checkout\Block\Onepage\Success"
     type="CompanyName\ModuleName\Block\Onepage\Success"/>
</config>

2) order success block

<?php

    namespace CompanyName\ModuleName\Block\Onepage;

    class Success extends \Magento\Checkout\Block\Onepage\Success 
    {

        protected $_orderDetail;

        protected $_order;

        protected $_item;

        protected $_renderer;

        protected $_priceHelper;

        protected $_customerSession;

        /**
         * @param \Magento\Framework\View\Element\Template\Context $context
         * @param \Magento\Checkout\Model\Session $checkoutSession
         * @param \Magento\Sales\Model\Order\Config $orderConfig
         * @param \Magento\Framework\App\Http\Context $httpContext
         * @param array $data
         */
        public function __construct(
            \Magento\Framework\View\Element\Template\Context $context,
            \Magento\Checkout\Model\Session $checkoutSession,
            \Magento\Sales\Model\Order\Config $orderConfig,
            \Magento\Framework\App\Http\Context $httpContext,
            \Magento\Sales\Model\Order $orderDetails,
            \Magento\Catalog\Model\ProductRepository $item,
            \Magento\Sales\Model\Order\Address\Renderer $renderer,
            \Magento\Framework\Pricing\Helper\Data $priceHelper,
            \Magento\Catalog\Block\Product\ListProduct $listProduct,
            \Magento\Store\Model\StoreManagerInterface $storeManager,
            \Magento\Customer\Model\Session $customerSession,
            array $data = []
        ) {

            $this->_orderDetail = $orderDetails;
            $this->_renderer = $renderer;
            $this->_item = $item;
            $this->_priceHelper = $priceHelper;
            $this->_listProduct = $listProduct;
            $this->_storeManager = $storeManager;
            $this->_customerSession = $customerSession;
            $this->_order = null;
            parent::__construct(
                    $context, $checkoutSession, $orderConfig, $httpContext, $data
            );
        }

        public function getOrder($id) {
            $this->_order = $this->_orderDetail->loadByIncrementId($id);
            return $this->_order;
        }

        public function getItem($itemId) {
            return $this->_item->getById($itemId);
        }

        public function getFormatedAddress($address) {
            return $this->_renderer->format($address, 'html');
        }

        public function getPaymentMethodtitle($order) {
            $payment = $order->getPayment();
            $method = $payment->getMethodInstance();
            return $method->getTitle();
        }

        /**
         * Get Formated Price
         * @param fload price 
         * @return boolean
        */
        public function getFormatedPrice($price='')
        {
            return $this->_priceHelper->currency($price, true, false);
        }

        public function getMediaUrl()
        {
            $currentStore = $this->_storeManager->getStore();
            return $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
        }    

}

Override order success.phtml and Add html from Override success.html file

CompanyName/ModuleName/view/frontend/templates/success.phtml

3) Get Shipping Method

 <?php $order = $this->getOrder($this->getOrderId()); ?> 

    <?php if(!empty($order->getShippingDescription())):?>
        <div class="shipping-method">
            <strong class="box-title">
                <span class="box-des"><?php /* @escapeNotVerified */ echo __('Shipping Method'); ?></span>
            </strong>
            <div class="box-content">
                <?php echo $order->getShippingDescription(); ?>                                
            </div>
        </div>
    <?php endif;?>

4) Get Product Details

 <?php $order = $this->getOrder($this->getOrderId()); ?>
    <div class="order-detail">
        <table>
            <thead>
                <tr>
                    <th colspan="3"><?php /* @escapeNotVerified */ echo __('Product Name'); ?></th>
                    <th class="table-number"><?php /* @escapeNotVerified */ echo __('Price'); ?></th>
                    <th class="table-number"><?php /* @escapeNotVerified */ echo __('Qty'); ?></th>
                    <th class="table-number"><?php /* @escapeNotVerified */ echo __('Subtotal'); ?></th>
                </tr>
            </thead>
            <tbody>
                <?php
                foreach ($order->getAllVisibleItems() as $item) {
                    $product = $this->getItem($item->getProductId());

                    $options = $item->getProductOptions();
                    $imageBlock = $block->getLayout()->createBlock('Magento\Catalog\Block\Product\ListProduct');
                    $productImage = $imageBlock->getImage($product, 'category_page_list');
                    ?>
                    <tr class="data-item">
                        <td colspan="3">
                            <div class="product-image">
                                <a href="<?php echo $product->getProductUrl(); ?>"><?php echo $productImage->toHtml(); ?></a>
                            </div>
                            <div class="product-name-sku">
                                <div class="product-name">
                                    <span><?php echo $item->getName(); ?></span>
                                </div>
                                <div class="product-name">
                                    <h5><?php /* @escapeNotVerified */ echo __('SKU'); ?></h5>
                                    <span><?php echo $item->getSku(); ?></span>
                                </div>
                            </div>
                        </td>
                        <td class="table-number"><?php echo $this->getFormatedPrice($item->getPrice()); ?></td> 
                        <td class="table-number"><?php echo $item->getQtyOrdered(); ?></td> 
                        <td class="table-number"><?php echo $this->getFormatedPrice($item->getBaseRowTotal()); ?></td>
                    </tr>
                    <?php
                }
                ?>

            </tbody>
            <tfoot>
                <tr class="subtotal">
                    <th colspan="5" class="table-method" scope="row">
                        <?php /* @escapeNotVerified */ echo __('Subtotal'); ?>
                    </th>
                    <td class="number" data-th="<?php /* @escapeNotVerified */ echo __('Subtotal'); ?>">
                        <span class="price"><?php echo $this->getFormatedPrice($order->getSubtotal()); ?></span>                    
                    </td>
                </tr>
                <tr class="shipping">
                    <th colspan="5" class="table-method" scope="row">
                        <?php /* @escapeNotVerified */ echo __('Shipping &amp; Handling'); ?>
                    </th>
                    <td class="number" data-th="<?php /* @escapeNotVerified */ echo __('Shipping &amp; Handling'); ?>">
                        <span class="price"><?php echo $this->getFormatedPrice($order->getShippingAmount()); ?></span>                    
                    </td>
                </tr>
                <tr class="grand_total">
                    <th colspan="5" class="table-method" scope="row">
                        <strong><?php /* @escapeNotVerified */ echo __('Grand Total'); ?></strong>
                    </th>
                    <td class="number" data-th="<?php /* @escapeNotVerified */ echo __('Grand Total'); ?>">
                        <strong><span class="price"><?php echo $this->getFormatedPrice($order->getGrandTotal()); ?></span></strong>
                    </td>
                </tr>
            </tfoot>
        </table>
    </div>

It's working

  • Oi @LimbaniHimanshu Thanks for your response. Could you help me understand it? Because in my case it gave error. Get Shipping Method and Get Product Details are inserted into success.phtml? And what would the method of returning them look like? – R.Park Aug 1 '19 at 15:17
  • sorry i have add half answer. can you please try with modify answer. – Limbani Himanshu Aug 2 '19 at 5:09
  • Hello @LimbaniHimanshu, tks for answer! Do I replace all the di.xml content with just this one? in htdocs/vendor/magento/module-checkout/etc this is ? – R.Park Aug 5 '19 at 15:48
  • I followed your example but unfortunately I was unsuccessful, could you help me? – R.Park Aug 5 '19 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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