首页 > 解决方案 > 需要在 magento 2 的结帐页面上编写自定义消息

问题描述

我正在尝试在客户输入结帐详细信息的结帐页面上显示一条消息。我想在表格的开头显示消息。

标签: magento2cart

解决方案


编辑结帐并不是那么容易。这是我在结帐时在运输方式选择顶部添加消息的操作:

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.htmlapp/code/MyModule/Shipping/view/frontend/web/template/shipping-method-item-template.html.

您现在可以编辑结帐文件。

当心:它是使用 javascript 的 html 文件(这里没有 PHP)。如果您需要添加数据库信息,您还必须使用文件重写一些 javascriptrequirejs-config.js文件。


推荐阅读