Magento 2 - 在成功页面上获得订单预览 [英] Magento 2 - get order preview on success page
问题描述
订购后有没有方法在成功页面上显示订单信息?成功phtml目前只显示订单号码信息。结构:
?>
<?php / ** @var $ block \Magento\Checkout\Block\Onepage\Success * /?>
< div class =checkout-success>
<?php if($ block-> getOrderId()):?>
<?php if($ block-> getCanViewOrder()):?>
< p><?php echo __('您的订单号是:%1。',sprintf('< a href =%sclass =order-number>< strong> ;%s< / strong>< / a>',$ block-> escapeHtml($ block-> getViewOrderUrl()),$ block-> escapeHtml($ block-> getOrderId())))? >< / p为H.
<?php else:?>
< p><?php echo __('Your order#is:< span>%1< / span> ;.',$ block-> escapeHtml($ block-> getOrderId()) )?>< / p>
<?php endif;?>
< p><?php / * @escapeNotVerified * / echo __('我们会通过电子邮件向您发送包含详细信息和跟踪信息的订单确认。')>< / p>
<?php endif;?>
<?php echo $ block-> getAdditionalInfoHtml()?>
< div class =actions-toolbar>
< div class =primary>
< a class =action primary continuehref =<?php / * @escapeNotVerified * / echo $ block-> getUrl()?>>< span><?php / * @escapeNotVerified * / echo __('继续购物')?>< / span>< / a>
< / div>
< / div>
< / div>
我试着调用 getOrder()?>
销售模块的功能: Module_Sales / view / frontend / templates / order / view.phtml
但它不起作用。
解决方案
覆盖区块
创建文件 app / code / Vendor / Module / etc / di.xml
并添加以下内容:
<?xml version =1.0?>
< config xmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexsi:noNamespaceSchemaLocation =../../../../../ vendor /的magento /框架/的ObjectManager的/ etc / config.xsd>
< preference for =Magento \Checkout\Block\Onepage\Successtype =Vendor \Module\Block\Success/>
< / config>
创建文件 app / code / Vendor / Module / Block / Success。 php
并添加以下内容:
<?php
命名空间Vendor\Module\Block;
类成功扩展\Magento\Checkout\Block\Onepage\Success {
public function getOrder(){
return $ this-> ; _checkoutSession-> getLastRealOrder();
}
}
覆盖模板 创建文件 创建文件 就是这样,希望我能有任何帮助。 您可能想要刷新您的结帐/成功页面,因此要解决该问题,请转至 至 这样,当您打开页面时,您的报价不会被清除。 Is there a way to show order information on success page after placing an order? The success phtml currently displays only order number information. The structure: I tried with calling the I'm about to do exactly the same thing, so I'll just document every step. Override block Create the file Create the file Override template Create the file Create the file That's about it, hope I could be of any help. You probably want to refresh your checkout/success page a lot, so to tackle that problem, go to file to This way, your quote won't get cleared when you open the page. 这篇关于Magento 2 - 在成功页面上获得订单预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b app / code / Vendor / Module / view / frontend / layout / checkout_onepage_success.xml
并添加以下内容:
<?xml version =1.0?>
< referenceBlock name =checkout.successtemplate =Your_Module :: checkout / success.phtml/>
< / body>
< / page>
app / code / Vendor / Module / view / frontend / templates / checkout / success.phtml
并添加以下内容:
<?php / ** @var $ block \Vendor\Module\Block\Success * /?>
< div class =checkout-success>
<?php if($ block-> getOrderId()):?>
<?php if($ block-> getCanViewOrder()):?>
< p><?php echo __('您的订单号是:%1。',sprintf('< a href =%sclass =order-number>< strong> ;%s< / strong>< / a>',$ block-> escapeHtml($ block-> getViewOrderUrl()),$ block-> escapeHtml($ block-> getOrderId())))? >< / p为H.
<?php else:?>
< p><?php echo __('Your order#is:< span>%1< / span> ;.',$ block-> escapeHtml($ block-> getOrderId()) )?>< / p>
<?php endif; ?>
<! - BEGIN VENDOR_MODULE CUSTOM - >
< p><?php echo __('您订购了%1个商品。',(int)$ block-> getOrder() - > getTotalQtyOrdered())?>< / p>
<! - END VENDOR_MODULE CUSTOM - >
< p><?php / * @escapeNotVerified * / echo __('我们'会通过电子邮件向您发送包含详细信息和跟踪信息的订单确认信息。')>< p为H.
<?php endif; ?>
<?php echo $ block-> getAdditionalInfoHtml()?>
< div class =actions-toolbar>
< div class =primary>
< a class =action primary continuehref =<?php / * @escapeNotVerified * / echo $ block-> getUrl()?>>< span><?php / * @escapeNotVerified * / echo __('继续购物')?>< / span>< / a>
< / div>
< / div>
< / div>
编辑
app / code / Magento / Checkout / Controller / Onepage / Success.phtml
并更改
$ session - > clearQuote();
// $ session-> clearQuote();
?>
<?php /** @var $block \Magento\Checkout\Block\Onepage\Success */ ?>
<div class="checkout-success">
<?php if ($block->getOrderId()):?>
<?php if ($block->getCanViewOrder()) :?>
<p><?php echo __('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><?php echo __('Your order # is: <span>%1</span>.', $block->escapeHtml($block->getOrderId())) ?></p>
<?php endif;?>
<p><?php /* @escapeNotVerified */ echo __('We\'ll email you an order confirmation with details and tracking info.') ?></p>
<?php endif;?>
<?php echo $block->getAdditionalInfoHtml() ?>
<div class="actions-toolbar">
<div class="primary">
<a class="action primary continue" href="<?php /* @escapeNotVerified */ echo $block->getUrl() ?>"><span><?php /* @escapeNotVerified */ echo __('Continue Shopping') ?></span></a>
</div>
</div>
</div>
getOrder() ?>
function from sales module: Module_Sales/view/frontend/templates/order/view.phtml
but it doesn't work.app/code/Vendor/Module/etc/di.xml
and add the following:<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../vendor/magento/framework/ObjectManager/etc/config.xsd">
<preference for="Magento\Checkout\Block\Onepage\Success" type="Vendor\Module\Block\Success"/>
</config>
app/code/Vendor/Module/Block/Success.php
and add the following:<?php
namespace Vendor\Module\Block;
class Success extends \Magento\Checkout\Block\Onepage\Success {
public function getOrder() {
return $this->_checkoutSession->getLastRealOrder();
}
}
app/code/Vendor/Module/view/frontend/layout/checkout_onepage_success.xml
and add the following: <?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">
<body>
<referenceBlock name="checkout.success" template="Your_Module::checkout/success.phtml"/>
</body>
</page>
app/code/Vendor/Module/view/frontend/templates/checkout/success.phtml
and add the following:<?php /** @var $block \Vendor\Module\Block\Success */ ?>
<div class="checkout-success">
<?php if ($block->getOrderId()):?>
<?php if ($block->getCanViewOrder()) :?>
<p><?php echo __('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><?php echo __('Your order # is: <span>%1</span>.', $block->escapeHtml($block->getOrderId())) ?></p>
<?php endif; ?>
<!-- BEGIN VENDOR_MODULE CUSTOM -->
<p><?php echo __('You ordered %1 items.', (int) $block->getOrder()->getTotalQtyOrdered()) ?></p>
<!-- END VENDOR_MODULE CUSTOM -->
<p><?php /* @escapeNotVerified */ echo __('We\'ll email you an order confirmation with details and tracking info.') ?></p>
<?php endif; ?>
<?php echo $block->getAdditionalInfoHtml() ?>
<div class="actions-toolbar">
<div class="primary">
<a class="action primary continue" href="<?php /* @escapeNotVerified */ echo $block->getUrl() ?>"><span><?php /* @escapeNotVerified */ echo __('Continue Shopping') ?></span></a>
</div>
</div>
</div>
Edit
app/code/Magento/Checkout/Controller/Onepage/Success.phtml
and change$session->clearQuote();
// $session->clearQuote();