1

I am having an issue on my website

the issue

Error: cannot call methods on priceBox prior to initialization;
attempted to call method 'option'

My website https://www.cartaroo.com.cy/?SID=5fe6b01812786b8145c48eaa0fde65ad

When I click on homepage product icon a view popup and due to js issue it won't allow me to select drop down. screenshot http://prntscr.com/h33mg9

Please help

0

I have also faced this problem after migrating from Magento 2.1.6 to 2.2.5.

Issue was due to the theme file phtml with scripts

Old File : app/design/frontend/Mytheme/theme/Magento_Catalog/templates/product/view/form.phtml

<script>
  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() ?>});
});
</script>

Copy script from new vendor file in your theme:

New Code: vendor/magento/module-catalog/view/frontend/templates/product/view/form.phtml

<script>
    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() ?>});
    });
</script>
0

I had the same problem with error

 cannot call methods on priceBox prior to initialization; attempted to call method 'option'

I was try to create price-box-mixin.js to extend mage.priceBox widget.

So it's the shame but that was my mistake. In the top of mixin I forgot to remove line 'Magento_Catalog/js/price-box'. At the beginning I was try to extend the widget mage.priceBox and I needed this line in section

define([
    'jquery',
    'Magento_Catalog/js/price-utils',
    'underscore',
    'mage/template',
    'jquery/ui',
    'Magento_Catalog/js/price-box'
], function ($, utils, _, mageTemplate) {

But after updating the script when I transform this script to mixin I needed to remove this line. So it became:

define([
    'jquery',
    'Magento_Catalog/js/price-utils',
    'underscore',
    'mage/template',
    'jquery/ui'
], function ($, utils, _, mageTemplate) {

I hope this helps someone to save time.

0

We ran into this error with a theme that allowed putting products in the top navigation menu. (It was a module called "Mega Nav".) When we added a product to the Mega Nav it broke all of our product pages that contained a dropdown with the error described above. Removing the product fixed the issue. We had a guess that loading the product for the purpose of putting it in the nav loaded some javascript too early.

Hope that helps someone fix this issue without going into code.

0

I had same issues and after days of brainstorming i discovered that solution does not require any code writing.

Goto your "Mega Menu" Disable any product menu item on the menu list and issue is resolved. See here - https://prnt.sc/n18cq5

Your Answer

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

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