这里我举个例子来展示自定义块上方的结帐方式
1)创建di.xml在
应用程序/代码/供应商/模块/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)创建ConfigProvider.php以将您的静态块定义为windows.checkoutConfig
应用/代码/供应商/模块/模型/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)在您的模块中覆盖checkout_index_index.xml并定义您自己的运输组件
应用/代码/供应商/模块/视图/前端/布局/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)现在创建shipping.js并定义您自己的运输模板文件
应用/代码/供应商/模块/视图/前端/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)从以下位置复制shipping.html
供应商/magento/module-checkout/view/frontend/web/template/shipping.html
到您的模块
app / code / Vendor / Module / view / frontend / web / template / shipping.html
现在,将window.checkoutConfig.my_block_content添加到shipping.html中要显示静态块的位置
<div data-bind="html: window.checkoutConfig.my_block_content"></div>
在这里,我在静态块中添加了新产品小部件
输出: