0

I'm trying to follow the example here

Magento 2 - Why do SKU not change dynamically in configurable product view page

to create a mixin for configurable products that will show dynamically a notification when the user selects an option that changes the price.

My task is very similar to the original post where the sku is changed but I haven't been able to make that example work or achieve what I'm trying to do.

I'm putting the relevant parts of the code here.

Vendor/Module/view/frontend/web/js/configurable-mixin.js

define([
    'jquery',
    'mage/utils/wrapper'
], function ($, wrapper) {
    'use strict';
    return function (targetModule) {

        //code here is executed
        var reloadPriceWrapper = wrapper.wrap(targetModule.prototype._reloadPrice, function (original) {

            //code in here never gets executed
            //call original method
            var result = original();

            //custom code to show a notification
            console.log('test');

            //return original value
            return result;
        });

        targetModule.prototype._reloadPrice = reloadPriceWrapper;
        return targetModule;
    };
});

requirejs-config.js

var config = {
    config: {
        mixins: {
            'Magento_ConfigurableProduct/js/configurable': {
                'Vendor_Module/js/configurable-mixin': true
            }
        }
    }
};

My mixin seems to be loaded in the page, but I don't see any part of the code inside the wrapped function execute at all and it seems targetModule.prototype._reloadPrice is undefined during the whole process which I assume is the reason it fails.

What could cause this issue?

I'm on Magento 2.3.1

  • var reloadPrice = targetModule.prototype._reloadPrice; define and try – Rk Rathod May 10 at 16:06
  • var reloadPrice is also undefined after var reloadPrice = targetModule.prototype._reloadPrice and the result is the same as before. – gabtzi May 10 at 17:06
  • I discovered it, another mixin was not returning the correct result that's why the variable targetModule was not defined correctly. – gabtzi May 11 at 7:34

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.