0

As the titel suggests. What is the purpose of vendor/magento/module-catalog/view/base/web/js/price-box.js::reloadPrice()? See: https://github.com/magento/magento2/blob/7d80b877d7057e62555d3376f2be7e7be68838f0/app/code/Magento/Catalog/view/base/web/js/price-box.js#L144

/*eslint-disable no-extra-parens*/
/**
 * Render price unit block.
 */
reloadPrice: function reDrawPrices() {
    var priceFormat = (this.options.priceConfig && this.options.priceConfig.priceFormat) || {},
        priceTemplate = mageTemplate(this.options.priceTemplate);

    _.each(this.cache.displayPrices, function (price, priceCode) {
        price.final = _.reduce(price.adjustments, function (memo, amount) {
            return memo + amount;
        }, price.amount);

        price.formatted = utils.formatPrice(price.final, priceFormat);

        $('[data-price-type="' + priceCode + '"]', this.element).html(priceTemplate({
            data: price
        }));
    }, this);
},

1 Answer 1

1

It is used by configurable and bundle prices to change the displayed prices when you select a configuration / bundle option. Let's say that you have a t-shirt and the default price is 90. Then you select size XL which costs 100. All the prices in the page will change accordingly using this script. This allows you to add also different types of prices. they should all change based on your selection

4
  • Thanks! It also does a "reload" of the price (html) on initial page load which makes it weird. We are trying to do a reformat of pricing html, this method just overrides the changes done in PHP.
    – Akif
    Commented May 4, 2022 at 12:50
  • the initial load is done in case you have a preselected value for the configurable or bundle options.
    – Marius
    Commented May 5, 2022 at 9:17
  • it's actually a simple product...
    – Akif
    Commented May 8, 2022 at 17:29
  • 1
    oh, I forgot it covers also the custom options for products. So this is needed for simple products also
    – Marius
    Commented May 9, 2022 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.