3

We are attempting to override the behavior of Bundle Products in Magento2, specifically, to enable user defined quantities for Checkbox type products within the bundle.

We have written an extension, and followed instructions about how to replace a default JS component found here: http://devdocs.magento.com/guides/v2.0/javascript-dev-guide/javascript/custom_js.html

Our custom js file is found in (app/code/Endertech/BundleExtended/view/base/web/js) directory

Our requirejs-config.js within our extension's frontend (app/code/Endertech/BundleExtended/view/frontend/) view looks like:

var config = {
    "map": {
        "*": {
            'Magento_Bundle/js/price-bundle': "Endertech_BundleExtended/js/price-bundle"
        }
    }
};

This is having the effect of loading BOTH the core Magento2 price-bundle.js AND our modified version... and the customization we've added to our modified version is not executing... presumably because the Magento2 core version is loading first.

We expected for this revision to PREVENT the core version from loading in favor of ours.

Perhaps we are approaching the problem from the wrong direction, or have some other misunderstanding.

We are seeking a solution to have our modified price-bundle.js be loaded in lieu of the built-in that comes in the Magento Bundle module... or at least a way to override specific methods within and is required here (vendor/magento/module-bundle/view/frontend/requirejs-config.js).

If our approach is wrong, we'd be happy to be corrected!

2

You can try 'mixins' feature, all you need is to create requireJS module with extended method like this:

default_mixin.js:

define(function () {
    'use strict';

    var mixin = {

        methodToExtend: function () {
            //...
        }
    };

    return function (target) { // target == Result that Magento_Ui/.../default returns.
        return target.extend(mixin); // new result that all other modules receive 
    };
});

requirejs-config.js:

config: {
    mixins: {
        'My_Module/js/payment/default': {  // Target module
            'My_Module/js/payment/default_mixin': true  // Extender module
        }
    }
}

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.