0

In addbysku.js file, I want to override the configure function of Magento_AdvancedCheckout module using mixins in Magento Enterprise Edition.

And my js code is,

define([
/* eslint-disable strict */
    'prototype',
    'mage/translate',
    'Magento_Catalog/catalog/product/composite/configure'
], function () {
    var mixin = {
        configure: function (id, sku) {
            var productRow = $('sku_errors_table').select('div[id=sku_' + sku + ']')[0],
                noticeElement = productRow.select('.notice'),
                productQtyElement = productRow.up('tr').select('input[name=qty]')[0];

            if (typeof this.configurableItems[sku] === 'undefined') {
                this.configurableItems[sku] = id;
            }

            // Don't process configured element by addBySku() observer method (it won't be serialized by serialize())
            productConfigure.setConfirmCallback(this.listType, function () {
                var $qty;

                // It is vital to push string element, check this line in configure.js:
                // this.itemsFilter[listType].indexOf(itemId) != -1
                productConfigure.skuObject.configuredSkus.push(sku.toString());

                if (noticeElement.length) {
                    // Remove message saying product requires configuration
                    noticeElement[0].remove();
                }
                $qty = productConfigure.getCurrentConfirmedQtyElement();

                if ($qty) { // Product set does not have this
                    // Synchronize qtys between configure window and grid
                    productQtyElement.value = $qty.value;
                }
            });
            productConfigure.showItemConfiguration(this.listType, sku);
            productConfigure.setShowWindowCallback(this.listType, function () {
                // sync qty of grid and qty of popup
                var qty = productQtyElement.value,
                    formCurrentQty;

                if (qty && !isNaN(qty)) {
                    formCurrentQty = productConfigure.getCurrentFormQtyElement();

                    if (formCurrentQty) {
                        formCurrentQty.value = qty;
                    }
                }
            });
        },
    };
    return function (target) {
        return target.extend(mixin);
    };
});

This does not work for me.

Does anyone have an idea about how to override js using mixins?

  • Why you want to do this from mixins. I think you can do this from map as well. – Ramkishan Suthar Nov 12 '18 at 13:21
  • Because I do not want to override the whole js code. I want to change in configure function only. That's why I want. – Emipro Technologies Pvt. Ltd. Nov 12 '18 at 13:22
  • actually your question is bit confusing like in first line you wrote you want to override addbysku.js and later you wrote you want to override configure function only :) – Ramkishan Suthar Nov 12 '18 at 13:29
  • I updated my question. Please see. – Emipro Technologies Pvt. Ltd. Nov 12 '18 at 13:32
  • Can you please let me know the path of requirejs file in your module – Ramkishan Suthar Nov 12 '18 at 13: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.