1

I am working with custom options in Magento 2 and have implemented logic to update the product price dynamically. Additionally, I have added custom logic to update the custom option prices within the widget configuration. My goal is to refresh or reload only the price option widget when these prices change, without reloading the entire page. Is there a way to achieve this in JavaScript, specifically by targeting a single widget?

1 Answer 1

0

Solution: Use RequireJS to target the price widget and reinitialize it:

require(['jquery', 'mage/priceBox'], function ($) {
function refreshPriceWidget() {
    var priceBox = $('.price-box'); // Adjust selector based on your widget
    if (priceBox.data('mage-priceBox')) {
        priceBox.priceBox('reloadPrices'); // Reload the prices dynamically
    }
}

// Trigger the refresh when prices update
$(document).on('customPriceUpdate', function () {
    refreshPriceWidget();
});
    $(document).trigger('customPriceUpdate');
});

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.