1. Nyatakan ketergantungan checkout modul
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>
2. Timpa tata letak checkout
app / code / NameSpace / ModuleName / view / frontend / layout / 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>
3. Buat Komponen UI JavaScript
Checkout Magento 2 dikelola dalam JavaScript (dengan Knockout). Jadi, Anda perlu membuat compnent JS khusus. Ini akan membuat tautan antara komponen UI checkout dan templat HTML khusus Anda.
app / code / NameSpace / ModuleName / view / frontend / web / js / view / checkout / pengiriman / additional-block.js
menetapkan([
'uiKomponen'
], function (Component) {
'gunakan yang ketat';
return Component.extend ({
default: {
templat: 'NameSpace_ModuleName / checkout / pengiriman / blok tambahan'
}
});
});
4. Buat template HTML
Kemudian buat templat HTML yang akan ditampilkan di checkout.
app / code / NameSpace / ModuleName / view / frontend / web / template / checkout / pengiriman / 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>
5. Bersihkan cache
Terakhir jalankan perintah berikut:
php bin/magento cache:clean
php bin/magento setup:upgrade
chmod -R 777 var/*
Unduh modul contoh demo lengkap dari sini