magento2
magento2 copied to clipboard
Wrong store ID used in Order Address Renderer
Description (*)
\Magento\Sales\Model\Order\Address\Renderer::format
allows to format order address. Internally, the method retrieve the order store ID and update the current store ID. This produces strange behavior if used in a context with a different store as the current store is not set to its previous value at the end of the execution of the method.
The class \Magento\Customer\Model\Address\Config
is used within the format method in order to resolve the address format to use accordingly to the order store. This class allows to set the store context thanks to \Magento\Customer\Model\Address\Config::setStore
. However this method was not called. Here we call it and reverse the value to its original state at the end of the execution, in order to prevent weird behavior.
With this solution, the current store in the manager is not altered and the global context is preserved.
Previously, when the method \Magento\Customer\Model\Address\Config::getFormatByCode
was called, by the method format, the store was resolved at the first call :
-> \Magento\Customer\Model\Address\Config::getFormatByCode
--> \Magento\Customer\Model\Address\Config::getFormats
---> \Magento\Customer\Model\Address\Config::getStore
public function getStore()
{
if ($this->_store === null) {
$this->_store = $this->_storeManager->getStore();
}
return $this->_store;
}
I guess that's why there was a $this->storeManager->setCurrentStore($orderStore);
in \Magento\Sales\Model\Order\Address\Renderer::format
.
This MR aims to remove the usage of $this->storeManager->setStore which may produce unwanted side-effects and use proper method available in the \Magento\Customer\Model\Address\Config
API.
Related Pull Requests
Fixed Issues (if relevant)
Cases where multiple order mails (with different stores) have to be sent by the cron job. Order addresses are not formatted accordingly to their respective store ID. Different formats must be set by store ID.
Manual testing scenarios (*)
- ...
- ...
Questions or comments
Contribution checklist (*)
- [ ] Pull request has a meaningful description of its purpose
- [ ] All commits are accompanied by meaningful commit messages
- [ ] All new or changed code is covered with unit/integration tests (if applicable)
- [ ] README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
- [ ] All automated tests passed successfully (all builds are green)
Resolved issues:
- [x] resolves magento/magento2#38412: Wrong store ID used in Order Address Renderer
Hi @thomas-kl1. Thank you for your contribution! Here are some useful tips on how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:
-
@magento give me test instance
- deploy test instance based on PR changes -
@magento give me 2.4-develop instance
- deploy vanilla Magento instance
:exclamation: Automated tests can be triggered manually with an appropriate comment:
-
@magento run all tests
- run or re-run all required tests against the PR changes -
@magento run <test-build(s)>
- run or re-run specific test build(s) For example:@magento run Unit Tests
<test-build(s)>
is a comma-separated list of build names.
Allowed build names are:
-
Database Compare
-
Functional Tests CE
-
Functional Tests EE
-
Functional Tests B2B
-
Integration Tests
-
Magento Health Index
-
Sample Data Tests CE
-
Sample Data Tests EE
-
Sample Data Tests B2B
-
Static Tests
-
Unit Tests
-
WebAPI Tests
-
Semantic Version Checker
You can find more information about the builds here :information_source: Run only required test builds during development. Run all test builds before sending your pull request for review.
For more details, review the Code Contributions documentation. Join Magento Community Engineering Slack and ask your questions in #github channel.
@magento run all tests
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.
@magento run all tests
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.
@magento run all tests
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.
Unit tests needs to be reworked as they don't test expected results but internal implementation 🤡
@magento run all tests
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.
@magento create issue
@magento run all tests
@magento run all tests
@magento run all tests
@magento run all tests
@thomas-kl1 Can you please have look on build failure of Integration Tests seems to be caused by PR changes.
@magento run all tests
\Magento\Customer\Model\Metadata\AddressMetadata::getAttributeMetadata
$attribute = $this->attributeMetadataDataProvider->getAttribute(AddressMetadataInterface::ENTITY_TYPE_ADDRESS, $attributeCode);
\Magento\Customer\Model\AttributeMetadataDataProvider::getAttribute
return $this->eavConfig->getAttribute($entityType, $attributeCode);
\Magento\Eav\Model\Config::initSystemAttributes
$attributeCollection = $this->_universalFactory->create($entityType->getEntityAttributeCollection());
$websiteId = $attributeCollection instanceof Collection ? $this->getWebsiteId($attributeCollection) : 0;
\Magento\Eav\Model\ResourceModel\Attribute\Collection::getWebsite
if ($this->_website === null) {
$this->_website = $this->_storeManager->getStore()->getWebsite();
}
return $this->_website;
@magento run all tests
@magento run all tests
@magento run all tests
@magento run all tests
@magento run all tests
@magento run all tests
I'll squash the commits tomorrow, right now I'm on my phone 😅
@magento run all tests
@magento run all tests
@magento run all tests
@magento run Functional Tests B2B, Functional Tests EE, Functional Tests CE
@magento run Functional Tests B2B