I have a single price on the page so i create a method on the priceBox to collect it via an API.

The problem i am having is that from my other JS module i can not access this widget or method. Every time i do so it will execute the _create or _init on that price-box which triggers a second call (the _create call).

Is there a way to to retrieve the actual instance of the widget and just call that refresh method?

There are different things i already tried though:

# Unknown function
const priceBox = $('.price-box', '.product-info-price').priceBox();

# New create is invoked
var priceBox = $.mage.priceBox;

Below is the example code of the actual price-box. Hope someone can help!

], function ($, utils, _, mageTemplate) {
    'use strict';

    return function (widget) {
        $.widget('mage.priceBox', widget, {
            _create: function initPriceBox() {
                var sku = $('div.product-info-main .product-info-price .product.attribute.sku div').html();
            collectPricesForProduct: function(sku, language){
                jQuery('.price-box').parent().prepend('<i class="fa fa-circle-o-notch fa-2x fa-spin"></i>');

                var self = this;
                $('#product-addtocart-button').attr('disabled', 'disabled');
                request.done(function (response) {
                    const prices = {
                        baseOldPrice: {
                            amount: response.prices.excl
                        oldPrice: {
                            amount: response.prices.incl
                        basePrice: {
                            amount: response.prices.excl
                        finalPrice: {
                            amount: response.prices.incl
                    self.options.prices = prices;
                request.error(function () {
                    alert('fatal error, no price');
        return $.mage.priceBox;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.