问题描述
我想在 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 中做到这一点,请帮忙?
提前致谢!
解决方法
您需要使用 RequireJs 混合来覆盖 abstract-total.js
以实现此目的。这样你就可以扩展 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;
}
});
}
});