javascript - 在 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 中做到这一点,请帮忙?
提前致谢!
解决方案
您需要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;
}
});
}
});
推荐阅读
- android - (AsyncTask) 和 (Thread with runOnUiThread) 有什么区别
- ceph - 使用多路径作为 OSD 的正确方法是什么?
- angular - 在 ngSelect 上使用 ngModel 绑定对象不起作用
- react-native - 打印磅签到反应本机热敏打印机( react-native-bluetooth-escpos-printer )
- python - 为什么我的矩形不出现(python 3.8 windows 7)
- javascript - 为什么这个计时器脚本不能按预期工作?
- flutter - 如何使用异步方法返回的值初始化小部件状态中的字段?
- python - “树视图焦点”时如何将图像表单数据库检索到标签?
- android - 如何实现 WhatsApp 之类的图片点击功能
- flutter - Flutter:计算两个日期之间的月差