magento2 - 需要在 magento 2 的结帐页面上编写自定义消息
问题描述
我正在尝试在客户输入结帐详细信息的结帐页面上显示一条消息。我想在表格的开头显示消息。
解决方案
编辑结帐并不是那么容易。这是我在结帐时在运输方式选择顶部添加消息的操作:
1/ 创建一个模块
app/code/MyModule/Shipping/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'MyModule_Shipping',
__DIR__
);
app/code/MyModule/Shipping/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="MyModule_Shipping" setup_version="0.1.0"/>
</config>
2/ 使用布局覆盖结帐 html 文件
app/code/MyModule/Shipping/view/frontend/layout/checkout_index_index.xml
<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="config" xsi:type="array">
<item name="shippingMethodListTemplate" xsi:type="string">MyModule_Shipping/shipping-method-list-template</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
3/ 最后,编辑你的 html 文件
复制vendor/magento/module-checkout/view/frontend/web/template/shipping-address/shipping-method-list.html
到app/code/MyModule/Shipping/view/frontend/web/template/shipping-method-item-template.html
.
您现在可以编辑结帐文件。
当心:它是使用 javascript 的 html 文件(这里没有 PHP)。如果您需要添加数据库信息,您还必须使用文件重写一些 javascriptrequirejs-config.js
文件。
推荐阅读
- visual-studio-code - 使用 Active Directory 身份验证在 Visual Studio Code 中连接到 Azure Sql 数据库
- ionic-framework - 传单 - 平移后的灰色条纹
- google-maps - 谷歌地球到谷歌地图
- c# - 数据网格不会清除
- python - 使用字典作为映射器创建熊猫系列
- google-cloud-platform - 如何通过尝试将数据流式传输到 bigquery 来修复“语法错误:位置上的意外标记”?
- java - LifecycleOwner onChanged 永远循环
- java - java中持续将小文件读入对象的最有效方法
- django - Django表单提交多个url(或)视图
- python - 使用 plotly 在 mapbox 上绘制多边形