Magento2: Cannot Switch Attribute Set After Upgrade to Magento 2.1.0

Created on 16 Aug 2016  Â·  20Comments  Â·  Source: magento/magento2

Preconditions

  1. I have upgraded from 2.0.7 to 2.1.0. Now in admin when I try to switch the attributes sets of product, the JavaScript loader appears and never goes away. In console I see JavaScript error.

Steps to reproduce

  1. Upgrade to 2.1.0 from 2.0.7
  2. Add new product attribute set
  3. Create new product, and change the attribute set from dropdown

Expected result

  1. New attribute set should load

Actual result

  1. One thing I notice is when I change attribute set, product name, SKU and price textboxes become empty.
  2. Also I get JavaScript error. See below screenshot:
    attr
    attr-1
Catalog Cannot Reproduce Clear Description Format is valid bug report

Most helpful comment

My fix:
requirejs-config.js file:

var config = {
    config: {
        mixins: {
            'Magento_Ui/js/lib/core/element/element': {
                'MyCompany_Catalog/js/element-mixin': true
            }
        }
    }
};

app/code/MyCompany/Catalog/view/adminhtml/web/js/element-mixin.js

define([
    'mageUtils'
], function (utils) {
    'use strict';

    var mixin = {
        /**
         * Invokes subscribers for the provided changes.
         *
         * @param {Object} diffs - Object with changes descriptions.
         * @returns {Element} Chainable.
         */
        _notifyChanges: function (diffs) {
            diffs.changes.forEach(function (change) {
                if (typeof change.value == 'undefined') {
                    return;
                }

                this.trigger(change.path, change.value, change);
            }, this);

            _.each(diffs.containers, function (changes, name) {
                var value = utils.nested(this, name);

                this.trigger(name, value, changes);
            }, this);

            return this;
        }
    };

    return function (target) {
        return target.extend(mixin);
    };
});

All 20 comments

Is there any update on this?

Strange enough, this bug occurred in one of mu installation. But upgrade on other installation went well.
Cant say what is that.

Same issue here. But here is my console error message
TypeError: $data.recordData(...) is undefined
knockout.js%20line%202624%20%3E%20Function:1:69

Tried to update M2.0.7 to M2.1.0 and can't reproduce. Have you figured out the cause of the issue?
If you use Chrome try hard reload of cache. It might help

Destination attribute set had a group or attribute where the origin attribute set doesn't have. I was able to fix my issue by adding the "Bundle Items" group in my destination attribute set.

Got it, this occurs when you have and attribute in different Attribute sets.
For example you created and attribute named 'ATTR'. You created two attributes sets 'SET1' and 'SET2'.
Now in SET1, the ATTR is in Price group but in SET2 ATTR is in 'Product Details' group.. Now when you switch from SET1 to SET2, you will see the above error.

So always make sure that all attributes reside in same groups across all attribute sets,

OK, so here is an updated way to reproduce this issue:

  1. Install Magento 2.1.2 (seems like this has not been fixed from 2.1.0)
  2. Create a new attribute set.
  3. Move some attributes into the new attribute set
  4. Create a new product and try to select the new attribute set

Expected result:
The set of attributes shown will change

Actual result:
Attributes are cleared and shown as failed validation.
JS error shown: VM8003:3 Uncaught TypeError: Cannot read property 'length' of undefined(…)
Spinner does not clear

Upshot: It is not possible to create a product in anything other than the default attribute set

As a work-around, I edited eav_entity_type and cleared the config cache. Now creating as product defaults to my new attribute set.

@maderlock what have you changed on the eav_entity_type table?

To further clarify the issue and workaround https://github.com/magento/magento2/issues/6173#issuecomment-245184005...

In order to switch a product from one attribute set to another, the destination attribute set must contain the attributes of the source attribute set in the same attribute group. Since all product start out as the Default attribute set, all subsequent attribute sets must have similar group structure to this otherwise you wont be able to switch.

Is a fix in the works for this bug?

This issue is still happening in 2.1.9. Shouldn't you be able to add and remove groups from the attribute set?

They fixed the bug in 2.2. But introduced a new one.
https://github.com/magento/magento2/issues/11516

@webspeaks, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.
We tested the issue on 2.2.0, 2.1.9

Incase if anyone still finding the issue,

Workaround:
I feel that only the Ajax call is having issues so directly set the attribute value via a URL
The default URL is for 'default' attribute set is

domain.com/admin/catalog/product/new/set/4/type/simple/key...

from eav_attribute_set table find the attribute set id

to switch the attribute set use that id in place of 4 like
say 'test_attribute_set' id is 12 then,

domain.com/admin/catalog/product/new/set/12/type/simple/key...

This is still reproducible in vanilla 2.2.5, just so you know.

My fix:
requirejs-config.js file:

var config = {
    config: {
        mixins: {
            'Magento_Ui/js/lib/core/element/element': {
                'MyCompany_Catalog/js/element-mixin': true
            }
        }
    }
};

app/code/MyCompany/Catalog/view/adminhtml/web/js/element-mixin.js

define([
    'mageUtils'
], function (utils) {
    'use strict';

    var mixin = {
        /**
         * Invokes subscribers for the provided changes.
         *
         * @param {Object} diffs - Object with changes descriptions.
         * @returns {Element} Chainable.
         */
        _notifyChanges: function (diffs) {
            diffs.changes.forEach(function (change) {
                if (typeof change.value == 'undefined') {
                    return;
                }

                this.trigger(change.path, change.value, change);
            }, this);

            _.each(diffs.containers, function (changes, name) {
                var value = utils.nested(this, name);

                this.trigger(name, value, changes);
            }, this);

            return this;
        }
    };

    return function (target) {
        return target.extend(mixin);
    };
});

@Tereta you're a star mate

@Tereta what are the exact steps to implement the solution, could you please share file name?

I can confirm this issue is still reproductible in Magento 2.3.4, but only when creating attribute sets programmatically without specifying the skeleton, see Set::initFromSkeleton()

When adding a new attribute to this new attribute set, you'll get an ajax error because of the parameter set=undefined, resulting in the very informative message "A technical problem with the server created an error. Try again to continue what you were doing. If the problem persists, try again later."

Making sure all my attribute sets were initialized from the "Default" attribute set with $set->initFromSkeleton($defaultAttributeSetId) fixed the pb.

Was this page helpful?
0 / 5 - 0 ratings