首页 > 解决方案 > 在 Magento-2 中,如何编辑带有值的订单摘要标签并在购物车页面中添加更多标签?

问题描述

我想在 magento2 的购物车页面上的订单摘要框中添加一些标签。现在我从默认的 magento2 行为中只得到了订单摘要中的小计和税款,请参见截图:https ://prnt.sc/1ggnt4j

我想添加和显示具有所有这些值的标签,请参阅屏幕截图以供参考:https ://prnt.sc/1ggna7r

虚拟代码,例如,

<div class="cart-summary" role="tablist" style="top: 0px;"><strong class="summary title">Summary</strong></div>
<div class="table-wrapper" data-bind="blockLoader: isLoading">
    <table class="data table totals">
        <tbody><tr><td>Price on Mrp</td><!---Want to show regular price -->
</tr><tr><td><?= _$regularprice; ?></td><!---regular price value -->
</tr><tr><td>Discount on MRP</td><!---Want to show discount amount-->
</tr><tr><td><?= _$discountamount; ?></td><!---discount price amount value-->
</tr><tr><td>Shipping</td><!---Want to show shipping custom label here -->
</tr><tr><td><strike>₹80</strike><?= _"FREE"; ?></td><!---shipping value -->
</tr><tr><td>Subtotal</td><!---Default show specail price -->
</tr><tr><td><?= _$specialprice; ?></td><!---Default special price value -->
</tr><tr><td>Tax</td><!---Default -->
</tr><tr><td><?= _$tax; ?></td><!---Default tax value -->
</tr>        </tbody>
    </table>
</div>

我们如何在 magento2 中做到这一点,请帮忙?

提前致谢!

标签: javascriptphphtmlmagento2magento2.2

解决方案


您需要abstract-total.js使用 RequireJs mixin 覆盖以实现这一点。这样你就可以扩展 Magento 提供的 JavaScript 对象并且只添加你自己的调整:

view/frontend/requirejs-config.js

var config = {
    config: {
        mixins: {
            'Magento_Checkout/js/view/summary/abstract-total': {
                'Vendor_Module/js/abstract-total-mixin': true
            }
        }
    }
};

view/frontend/web/js/abstract-total-mixin.js

define([], function () {
    "use strict";

    return function (target) {
        return target.extend({
            /**
             * @return {*}
             */
            isFullMode: function () {
                if (!this.getTotals()) {
                    return false;
                }

                return true;
            }
        });
    }
});

参考:https ://magento.stackexchange.com/a/235329/56248


推荐阅读