1

Magento 2 bundle product has a set of simple products. If you click each simple product's checkbox, its bundle product's price is re-calculated and displayed in bundle.summary block. I want to move it to product.info.price so that it is displayed at the top of product-info-main. If it is moved using layout xml, it is displayed at product.info.price block, but its calculation for changing checkboxes is not updated.

By debugging on browser, I found

priceBox.trigger('updatePrice', changes) 

of _onBundleOptionChanged function in Magento_Bundle/js/price-bundle.js can't call updatePrice function of Magento_Catalog/js/price-box.js, so its price is not re-calculated on checkbox click event. Could you help how should I do this? Thanks.

1 Answer 1

0

I had the exact same issue. My problem was related to the fact that the priceBox was not initialized, therefore priceBox.trigger('updatePrice') did not work. Check your code in the Magento_Catalog/templates/product/view/form.phtml. My code was like:

require([
    'jquery',
    'Magento_Catalog/js/price-box'
], function($){
    var priceBoxes = $('.product-info-price [data-role=priceBox]');

    priceBoxes = priceBoxes.filter(function(index, elem){
        return !$(elem).find('.price-from').length;
    });

    priceBoxes.priceBox({'priceConfig': <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>});
});

after correcting it to

require([
    'jquery',
    'priceBox'
], function($){
    var dataPriceBoxSelector = '[data-role=priceBox]',
        dataProductIdSelector = '[data-product-id=<?= $block->escapeHtml($_product->getId()) ?>]',
        priceBoxes = $(dataPriceBoxSelector + dataProductIdSelector);

    priceBoxes = priceBoxes.filter(function(index, elem){
        return !$(elem).find('.price-from').length;
    });

    priceBoxes.priceBox({'priceConfig': <?= /* @escapeNotVerified */ $block->getJsonConfig() ?>});
});

the update of the configuration price worked again.

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.