Skip to content

fix: Disable global attribute field when editing on a store view scope - #5699

Open
wild82pl wants to merge 3 commits into
OpenMage:mainfrom
wild82pl:fix/global-attribute-store-scope-save
Open

fix: Disable global attribute field when editing on a store view scope#5699
wild82pl wants to merge 3 commits into
OpenMage:mainfrom
wild82pl:fix/global-attribute-store-scope-save

Conversation

@wild82pl

Copy link
Copy Markdown

Description (*)

Mage_Adminhtml_Block_Catalog_Form_Renderer_Fieldset_Element::checkFieldDisable() already disables the "use default" checkbox for global-scope attributes via canDisplayUseDefault(), but the field itself remains editable and savable when the fieldset is rendered for a specific store view (not the default/all-store-views scope). Saving from that state writes a store-scoped row for an attribute that should only ever have a global value, corrupting the attribute's data.

This adds isGlobalAttributeOnStoreScope() to detect that case (global-scope attribute + a data object with a non-default store id) and disable the field the same way canDisplayUseDefault()/usedDefault() already do, closing the gap that mechanism leaves open.

Manual testing scenarios (*)

  1. In admin, go to Catalog > Attributes > Manage Attributes, create (or pick an existing) attribute with Scope = Global.
  2. Go to Catalog > Manage Products, open any product, switch to a specific store view (not "Default Values") using the store switcher.
  3. Locate the global-scope attribute's field on the product edit form.
  4. Before this fix: the field is editable; changing and saving it writes a store-scoped value row for that attribute.
  5. After this fix: the field is disabled (same as attributes whose "Use Default Value" is checked), and no store-scoped row is written when saving.
  6. Switch back to "Default Values" scope and confirm the field is still editable there, unaffected.

Questions or comments

Added isGlobalAttributeOnStoreScope() and a PHPUnit test (ElementTest/ElementTrait) covering: global attribute on a store view (disabled), global attribute on default scope (editable), and website/store-scope attributes on a store view (unaffected, editable). Verified locally: PHPUnit, PHPStan, ECS and PHPMD all pass clean on the changed files.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All automated tests passed successfully (all builds are green, SonarCloud checks are not required to merge)

Mage_Adminhtml_Block_Catalog_Form_Renderer_Fieldset_Element::checkFieldDisable()
already disables the "use default" checkbox for global-scope attributes
via canDisplayUseDefault(), but the field itself remained editable and
savable when the fieldset was rendered for a specific store view (not
the default/all-store-views scope). Saving from that state writes a
store-scoped row for an attribute that should only ever have a global
value, corrupting the attribute's data.

Add isGlobalAttributeOnStoreScope() to detect that case (global-scope
attribute + a data object with a non-default store id) and disable the
field the same way canDisplayUseDefault()/usedDefault() already does,
closing the gap that mechanism leaves open.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an admin product-edit form edge case where global-scope EAV attributes remained editable when editing a product in a specific store view scope, allowing an invalid store-scoped value row to be saved for a globally-scoped attribute.

Changes:

  • Added Mage_Adminhtml_Block_Catalog_Form_Renderer_Fieldset_Element::isGlobalAttributeOnStoreScope() to detect global attributes being edited in a non-default store scope.
  • Updated checkFieldDisable() to disable the form element when this invalid edit context is detected.
  • Added a PHPUnit test + data provider covering global/default scope behavior and ensuring website/store-scoped attributes remain unaffected.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
app/code/core/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/Element.php Adds detection for global-attribute-on-store-scope and disables the field to prevent invalid store-scoped saves.
tests/unit/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/ElementTest.php Introduces a unit test validating the new detection logic via a mocked subject.
tests/unit/Traits/DataProvider/Mage/Adminhtml/Block/Catalog/Form/Renderer/Fieldset/ElementTrait.php Adds a data provider with cases for global/website/store scope attributes across store-id contexts.

wild82pl and others added 2 commits July 23, 2026 14:31
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants