0

In vendor/magento/module-catalog/view/base/web/js/price-options.js there is a method _onOptionChanged: function onOptionChanged(event).

I would like to call this method in my template when page load.

app/design/frontend/Smartwave/porto/Magento_Catalog/templates/product/view/options/wrapper.phtml

How can i achieve this? is it possible to call this method in my template file ? if possible please help me and suggest me how can do it?

1

You can't do it in template, and you can't access directly to a private method. You can do it in a requireJS module through the mixins configuration.

See the docs.

In your case you could do something like his:

var config = {
    'config':{
        'mixins': {
            'priceOptions': {
                'Vendor_Module/script' : true
            }
        }
    }
}; 

And in your script.js

define(['jquery'], function ($) {

    return function (widget) {

       $.widget('mage.priceOptions', widget, {

           yourMethod: function () {
                 this._onOptionChanged
           }

       });
       return $.mage.priceOptions;
   }
});
2

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.