0

I have created a mixin to extend the mage.promptEditWithList widget in /vendor/magento/module-multiple-wishlist/view/frontend/web/js/multiple-wishlist.js, but it breaks the edit wishlist functionality and the modal does not open. When using breakpoints, I can see the code going through the create method, but it skips the super reference and does not go through the parent method.

The second mixin I have created to extend mage.multipleWishlist works perfectly, so I do not understand why it does not work.

requirejs-config.js

var config = {
    config: {
        mixins: {
            'Magento_MultipleWishlist/js/multiple-wishlist': {
                'XXXXX_Wishlist/js/multiple-wishlist-prompt-edit-mixin': true,
                'XXXXX_Wishlist/js/multiple-wishlist-mixin': true
            }
        }
    }
};

multiple-wishlist-prompt-edit-mixin.js


define([
    'jquery',
    'Magento_Ui/js/modal/prompt',
], function ($) {
    'use strict';

    return function (promptEditWithListWidget) {
        $.widget('mage.promptEditWithList', promptEditWithListWidget, {
            options: {
                descriptionLabel: '',
                descriptionValue: '',
            },


            /**
             * @private
             */
            _create: function () {
                this._super();

                console.log('my mixin', this);
            },

            /**
             * @return {*|jQuery|HTMLElement}
             */
            getNoticeTemplate: function () {
                var template = $('<div class="field"><label for="wishlist-description" class="label">' +
                    '<span>' + this.options.descriptionLabel + '</span></label>' +
                    '<input type="text" id="wishlist-description" class="input-text" name="description" value="' + this.options.descriptionValue + '"></div>' +
                    '<div class="field choice">' +
                    '<input id="wishlist-public" type="checkbox" name="' + this.options.isPublicFieldAttributeName + '">' +
                    '<label for="wishlist-public" class="label">' +
                    '<span>' + this.options.isPublicFieldLabel + '</span>' +
                    '</label>' +
                    '<input name="form_key" type="hidden" value="' + this.options.hiddenFieldValue + '">' +
                    '</div>');

                if (this.options.isPublicFieldChecked) {
                    template.find('input[type = checkbox]').attr('checked', 'checked');
                }

                return descriptionTemplate;
            }
        });

        return $.mage.promptEditWithList;
    }
});

Original widget in /vendor/magento/module-multiple-wishlist/view/frontend/web/js/multiple-wishlist.js

$.widget('mage.promptEditWithList', $.mage.prompt, {
        options: {
            label: '',
            isPublicFieldLabel: '',
            isPublicFieldAttributeName: '',
            isPublicFieldChecked: false,
            hiddenFieldValue: ''
        },

        /**
         * @private
         */
        _create: function () {
            this._super();
            this.modal.find(this.options.modalContent).find('fieldset').append(this.getNoticeTemplate());
        },

        /**
         * @return {*|jQuery|HTMLElement}
         */
        getNoticeTemplate: function () {
            var template = $('<div class="field choice">' +
                '<input id="wishlist-public" type="checkbox" name="' + this.options.isPublicFieldAttributeName + '">' +
                '<label for="wishlist-public" class="label">' +
                '<span>' + this.options.isPublicFieldLabel + '</span>' +
                '</label>' +
                '<input name="form_key" type="hidden" value="' + this.options.hiddenFieldValue + '">' +
                '</div>');

            if (this.options.isPublicFieldChecked) {
                template.find('input[type = checkbox]').attr('checked', 'checked');
            }

            return template;
        }
    });

This post had a very similar problem, but no answers https://stackoverflow.com/questions/61640888/multiple-wishlist-widget-mixin

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.