Answers:
app / code / NameSpace / ModuleName / etc / module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="NameSpace_ModuleName" setup_version="0.0.1" active="true">
<sequence>
<module name="Magento_Checkout"/>
</sequence>
</module>
</config>
应用程序/代码/名称空间/模块名称/视图/前端/布局/checkout_index_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shippingAddress" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shippingAdditional" xsi:type="array">
<item name="component" xsi:type="string">uiComponent</item>
<item name="displayArea" xsi:type="string">shippingAdditional</item>
<item name="children" xsi:type="array">
<item name="additional_block" xsi:type="array">
<item name="component" xsi:type="string">NameSpace_ModuleName/js/view/checkout/shipping/additional-block</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
Magento 2结帐使用JavaScript(带有Knockout)进行管理。因此,您需要创建一个自定义JS组件。它将在结帐UI组件和自定义HTML模板之间创建链接。
app / code / NameSpace / ModuleName / view / frontend / web / js / view / checkout / shipping / additional-block.js
限定([ 'uiComponent' ],功能(组件){ “使用严格”; 返回Component.extend({ 默认值:{ 模板:“ NameSpace_ModuleName /结帐/运输/附加块” } }); });
然后创建HTML模板,以便在结帐时显示。
app / code / NameSpace / ModuleName / view / frontend / web / template / checkout / shipping / additional-block.html
<div class="checkout-block" id="block-custom">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
<p>Cum sociis natoque penatibus et magnis dis parturient montes.</p>
</div>
最后运行以下命令:
php bin/magento cache:clean
php bin/magento setup:upgrade
chmod -R 777 var/*
从此处下载完整的示例演示模块
Broken reference: No element found with ID 'checkout.header.wrapper'. [] [] Class SR\AdditionalShippingBlock\Model\CustomBlockConfigProvider does not exist [] [] [2016-04-13 10:15:06] main.CRITICAL: Invalid block type: Magento\Checkout\Block\Onepage [] []
app/code/SR/AdditionalShippingBlock
,而不是app/code/Magento/AdditionalShippingBlock
。
在显示的文件“ checkout_index_index.xml”中,有一个小错误。一定是
<?xml version="1.0"?>
不
<xml version="1.0"?>
想念第一个字符'?'