-
-
Notifications
You must be signed in to change notification settings - Fork 449
Fix website-specific attribute values not loading correctly #4745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…collection as default
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
Hanmac
approved these changes
Apr 17, 2025
kiatng
approved these changes
Apr 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested.
Closed
1 task
fballiano
added a commit
to MahoCommerce/maho
that referenced
this pull request
Apr 18, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes an issue where website-specific attribute values (stored in tables like
customer_eav_attribute_website
) are not loaded correctly for EAV attributes. The problem affects attributes liketaxvat
that should respect website-specific configurations.Problem
The issue occurs in the EAV attribute loading process. When loading entity attributes in
Mage_Eav_Model_Config::_loadEntityAttributes()
, the code calls:The
newAttributeCollection()
method inMage_Eav_Model_Entity_Type
calls_getAttributeCollection()
, which creates a collection using:This always returns an instance of
Mage_Eav_Model_Resource_Entity_Attribute_Collection
, which does not have thesetWebsite()
method needed to load website-specific attribute values.For entity types like 'customer' that have website-specific attributes, this means the website-specific values are never loaded, even though they exist in the database.
Proposed Solution
The solution has two parts:
1. Fix the attribute collection creation
Modify the
_getAttributeCollection()
method inMage_Eav_Model_Entity_Type
to use the entity's configured attribute collection class instead of always using the base collection:This leverages the existing
getEntityAttributeCollection()
method, which returns the collection class specified in the entity type's XML configuration. By default, it returns 'eav/entity_attribute_collection', but modules can override this for specific entity types.2. Fix the attribute loading process with cache
Modify the
_loadEntityAttributes()
method inMage_Eav_Model_Config
to check for website-specific collections and set the website ID:Using
instanceof
instead ofmethod_exists()
is more reliable and efficient because:setWebsite()
on collections that are designed to handle website-specific valuesMage_Eav_Model_Resource_Attribute_Collection
support website-specific valuesCurrently, only two collections in the core code implement the abstract class with
setWebsite()
:Mage_Customer_Model_Resource_Attribute_Collection
Mage_Customer_Model_Entity_Attribute_Collection
(which extends the first one)This is consistent with the database schema, as only the Customer module has a
customer_eav_attribute_website
table to store website-specific attribute values. Other entity types like Catalog do not have equivalent tables and their collections do not extend the abstract class withsetWebsite()
.For example, the Customer module can specify:
With these changes, entity types that have website-specific attributes can provide their own attribute collection class that implements the
setWebsite()
method, and the attribute loading process will correctly use this method when caching attributes.Diagram
Benefits
taxvat
will now correctly respect website-specific configurations.Testing
taxvat
attribute on different websitesNote: This solution requires thorough testing across different environments and configurations as it affects a core part of the EAV system. Comprehensive regression testing is strongly recommended to ensure no unintended side effects occur in other parts of the system that rely on attribute collections.
Backward Compatibility
This change is backward compatible as it:
Related Issues
This fixes the following issues: