浏览文章
文章信息
Magento2 【前端】js发起请求
13526
示例:
define( [ 'jquery', 'mage/storage', 'Magento_Checkout/js/model/quote', 'Magento_Catalog/js/price-utils', 'Magento_Checkout/js/view/summary/abstract-total', 'Magento_Checkout/js/model/url-builder' ], function ($, storage, quote, priceUtils, Component, urlBuilder) { "use strict"; let isVisible = false; let discount = 0; // 获取Quote的优惠 storage.get( urlBuilder.createUrl('/aiweline/quote/upsell') ).done(function (response) { if (response.upsell_discount_amount) { isVisible = true; discount = upsell_discount_amount; } }).error(function (response) { errorProcessor.process(response); }).always(function () { }); return Component.extend({ defaults: { template: 'Aiweline_Upsell/checkout/summary/upsell-discount' }, isDisplayedCustomdiscount: function () { return isVisible; }, getUpsellDiscount: function () { return priceUtils.formatPrice(discount, quote.getPriceFormat()); } }); } );重点:
storage.get( urlBuilder.createUrl('/aiweline/quote/upsell') ).done(function (response) { if (response.upsell_discount_amount) { isVisible = true; discount = upsell_discount_amount; } }).error(function (response) { errorProcessor.process(response); }).always(function () { });