magento2-code-generator icon indicating copy to clipboard operation
magento2-code-generator copied to clipboard

crudEAV cannot handle "Use Default Value"

Open ioweb-gr opened this issue 2 years ago • 1 comments

I've created an EAV entity with this template, and added a custom attribute with store view scope.

e.g.

        $attributes = [];
        $attributes['name'] = [
            'type' => 'varchar',
            'label' => 'Name',
            'input' => 'text',
            'required' => true, //true/false
            'sort_order' => 10,
            'global' => ScopedAttributeInterface::SCOPE_STORE,
            'group' => 'General',
        ];

        foreach($attributes as $attributeCode => $attributeData){
            $this->eavSetup->addAttribute(CookieSetup::ENTITY_TYPE_CODE, $attributeCode, $attributeData);
        }

My problem here is when trying to save the object in the backend for a different store view other than default, I'm unable to reset the value to use default.

image

I've tried modifying the ui form component to add the "Use Default Value" checkbox to test, but it's totally ignored

e.g.

        <field name="name" formElement="input" sortOrder="20" >
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="service" xsi:type="array">
                        <item name="template" xsi:type="string">ui/form/element/helper/service</item>
                    </item>
                </item>
            </argument>
            <settings>
                <visible>true</visible>
                <dataType>text</dataType>
                <label translate="true">Name</label>
                <validation>
                    <rule name="required-entry" xsi:type="boolean">true</rule>
                </validation>
            </settings>
        </field>

image

And after saving the value still remains. It's never deleted for the current store view.

I'm assuming something is missing from the resourceModel to handle the "Use Default Value"?

ioweb-gr avatar Jan 31 '22 20:01 ioweb-gr

I've noticed that even without "Use Default Value" if I resave the entity with an empty value on the store view level, the upper scope level value is deleted.

So in a tree like this

All Store Views (Value Default) 
|--Website (Value Website)
|----Store View 1 (Value Store View 1)
|----Store View 2 (Value Store View 2)

If I navigate to Store View 2 and save twice with an empty value

On the first save the "Value Store View 2" is deleted. On the second save the "Value Website" is deleted even though I didn't change scope.

Any ideas what this bug is?

ioweb-gr avatar Feb 03 '22 10:02 ioweb-gr