有没有办法在下订单后在成功页面上显示订单信息?成功phtml目前仅显示订单号信息。结构:
?>
<?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() ?>
调用Module_Sales/view/frontend/templates/order/view.phtml
函数,但它不起作用。
答案 0 :(得分:4)
我即将做同样的事情,所以我只记录每一步。
覆盖阻止
创建文件app/code/Vendor/Module/etc/di.xml
并添加以下内容:
<?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
并添加以下内容:
<?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
并添加以下内容:
<?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
并添加以下内容:
<?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>
关于它,希望我可以提供任何帮助。
您可能想要大量刷新结帐/成功页面,因此要解决该问题,请转到app/code/Magento/Checkout/Controller/Onepage/Success.phtml
并更改
$session->clearQuote();
到
// $session->clearQuote();
这样,当您打开页面时,您的报价不会被清除。