Di sini saya memberikan contoh untuk menunjukkan blok khusus di atas metode pengiriman checkout
1) Buat di.xml di
app / code / Vendor / Module / etc / frontend / di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Checkout\Model\CompositeConfigProvider">
<arguments>
<argument name="configProviders" xsi:type="array">
<item name="cms_block_config_provider" xsi:type="object">Vendor\Module\Model\ConfigProvider</item>
</argument>
</arguments>
</type>
</config>
2) Buat ConfigProvider.php untuk menentukan blok statis Anda ke windows.checkoutConfig
app / code / Vendor / Module / Model / ConfigProvider.php
<?php
namespace Vendor\Module\Model;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\View\LayoutInterface;
class ConfigProvider implements ConfigProviderInterface
{
/** @var LayoutInterface */
protected $_layout;
public function __construct(LayoutInterface $layout)
{
$this->_layout = $layout;
}
public function getConfig()
{
$myBlockId = "my_static_block"; // CMS Block Identifier
//$myBlockId = 20; // CMS Block ID
return [
'my_block_content' => $this->_layout->createBlock('Magento\Cms\Block\Block')->setBlockId($myBlockId)->toHtml()
];
}
}
3) Override checkout_index_index.xml dalam modul Anda dan tentukan komponen pengiriman Anda sendiri
app / code / Vendor / Module / view / frontend / layout / checkout_index_index.xml
<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.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="component" xsi:type="string">Vendor_Module/js/view/shipping</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
4) Sekarang buat shipping.js dan tentukan file template pengiriman Anda sendiri
app / code / Vendor / Module / view / frontend / web / js / view / shipping.js
define(
[
'jquery',
'ko',
'Magento_Checkout/js/view/shipping'
],
function(
$,
ko,
Component
) {
'use strict';
return Component.extend({
defaults: {
template: 'Vendor_Module/shipping'
},
initialize: function () {
var self = this;
this._super();
}
});
}
);
5) Salin shipping.html dari
vendor / magento / module-checkout / view / frontend / web / template / shipping.html
Ke modul Anda
app / code / Vendor / Module / view / frontend / web / template / shipping.html
Sekarang tambahkan window.checkoutConfig.my_block_content ke shipping.html di mana Anda ingin menunjukkan blok statis Anda
<div data-bind="html: window.checkoutConfig.my_block_content"></div>
Di sini saya menambahkan widget produk baru di blok statis saya
KELUARAN: