Magento 2:如何在结帐成功页面上显示客户电子邮件?

时间:2019-02-22 08:01:01

标签: block checkout magento-2.3

我的代码如下

app / code / custom / checkout / block / success.php

 class Success extends \Magento\Checkout\Block\Onepage\Success
  {
    public function getOrder()
    {        
       $order = $this->_checkoutSession->getLastRealOrder();
       return $order;
     }

app / design / frontend / vendor / themename / Magento_Checkout / layout / checkout_onepage_success.xml

 <referenceContainer name="content">
        <block class="Custom\Checkout\Block\Success" name="checkout.success" template="Magento_Checkout::success.phtml" cacheable="false">
            <container name="order.success.additional.info" label="Order Success Additional Info"/>
        </block>
    </referenceContainer>

app / design / frontend / vendor / themename / Magento_Checkout / templates / success.phtml

 <?php if($block->getOrderId):?>
      <div class="success-title" data-bind="i18n: 'Thank you for your purchase!'" data-role="title">
     <h2><?= __('Thank you for your purchase!');?></h2>
    </div>
    <p><?= __('Your payment has been received. A confirmation of your order has been sent to ');?><?php echo '"'.$block->getOrder()->getCustomerEmail().'"'?></p>
    <?php if ($block->getCanViewOrder()) :?>
        <p class="successmessge"><?= __('Your order number is: %1.', sprintf('<a href="%s" class="order-number"><strong>%s</strong></a>', $block->escapeHtml($block->getViewOrderUrl()), $block->escapeHtml($block->getOrderId()))) ?></p>
    <?php  else :?>
        <p class="successmessge"><?= __('Your order number is: <span>%1</span>.', $block->escapeHtml($block->getOrderId())) ?></p>
    <?php endif;?>
        <p><?= /* @escapeNotVerified */ __('Check your inbox for estimated delivery time') ?></p>
        <p><?= /* @escapeNotVerified */ __('If you have any questions regarding your order , please contact our customer service department on contact@cii.co.uk or +44(0)12 3456 7891') ?></p>
<?php endif;?>

$ block-> getOrder()-> getCustomerEmail();

这将返回错误:调用非成员函数为空

app / code / Custom / Checkout / etc / frontend / di.xml

 <preference for="Custom\Checkout\Block\Success" type="Magento\Checkout\Block\Onepage\Success" />

一切正常。

只有我无法将块函数添加到成功页面

请帮助我我的代码有什么问题?

0 个答案:

没有答案