Skip to content

MC-38592 Fixed load regions for scope #30755

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
merged 11 commits into from
Mar 18, 2021

Conversation

bogutskyy
Copy link
Contributor

Description (*)

Currently, if different scopes have different allowed countries, then can be issue on address forms. One of issue described in #30577: new order can not be created from admin. Another issue, which I found, on customer address edit page, when for US doesn't appear states dropdown.
image
I fixed regions loading depending on current scope.

Related Pull Requests

No related PRs

Fixed Issues (if relevant)

  1. Fixes Can't place order on admin: "regionId" is required #30577

Manual testing scenarios (*)

See #30577

Questions or comments

Looks like directory helper has been broken after fix in ticket MC-33168. Unfortunately I don't know what the problem was in MC-33168, but after code changes investigation I guess it was issue, when scope present in request params. Not sure the fix of MC-33168 was correct, maybe logic of current scope determination should be moved from app/code/Magento/Directory/Helper/Data.php to app/code/Magento/Store/Model/StoreResolver.php.

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)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Nov 2, 2020

Hi @bogutskyy. Thank you for your contribution
Here is some useful tips 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

❗ 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:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@vveb-developer
Copy link
Contributor

@magento run all tests

@ghost ghost added Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. labels Nov 3, 2020
@bogutskyy
Copy link
Contributor Author

@magento run all tests

Copy link
Contributor

@gabrieldagama gabrieldagama left a comment

Choose a reason for hiding this comment

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

Hi @bogutskyy, thanks for contributing! Can you have a look at my comments below? Also, can you have a look at the failed tests and fix them?

Thank you!

Comment on lines 193 to 194
$scopeKey = $scope['value'] ? '_' . implode('_', $scope) : '';
$cacheKey = 'DIRECTORY_REGIONS_JSON' . $scopeKey;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you give more details on why this change here is relevant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't make sense to have string _STORE in cache key template, because $scope['type'] already contains scope type. In result currently cache key for store takes value DIRECTORY_REGIONS_JSON_STORE_STORE_1.

@@ -406,14 +406,21 @@ public function getWeightUnit()
* Get current scope from request
*
* @return array
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
private function getCurrentScope(): array
Copy link
Contributor

Choose a reason for hiding this comment

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

This method has as a goal (as described on the PHP doc block) to get the current scope from the request, I'm not sure that such change makes sense, maybe we should look at the problem from the request perspective?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Method getCurrentScope has been added in commit 2b4cfab, ticket MC-33168, and this change produced issue #30577. tbh, my change looks like quick fix. I am not sure that method getCurrentScope should be here. In this class we have store resolver. I think make sense to move logic of current scope determination into store resolver. But I don't know what issue MC-33168 was about, and afraid to broke something, what has been fixed previously. Therefore I decided change default value in method getCurrentScope. If somebody can explain me issue of MC-33168, then I'll be able to move on.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that getCurrentScope probably shouldn't be on this helper, but by adding that condition it makes the function ambiguous. My proposal would be to look at the solution from the Create Order perspective, see from which request this function is being called, and make sure we have the correct scope on the request, it should be also a quick fix, what do you think?

@bogutskyy
Copy link
Contributor Author

@magento run all tests

@gabrieldagama
Copy link
Contributor

Hi @bogutskyy, sorry for the delay on this. Please follow some information from MC-33168:

Default State dropdown is not filled with correct data

ISSUE:
When configuring 'Default Tax Destination Calculation', the 'Default State' dropdown only fills with data based on allowed countries of the default website.

STEPS TO REPLICATE:
1. Configure a second website, e.g. 'Test Website'.
2. Go to Stores -> Configurations.
3. Change the scope to 'Main Website'.
4. Navigate to General -> General -> Country Options -> Allow Countries and select some countries, e.g. select France and Germany.
5. Clear the cache.
6. Go to Stores -> Configurations again and change the scope to 'Test Website'.
7. Navigate to Sales -> Tax -> Default Tax Destination Calculation.
8. Select Default Country from the dropdown list instead of Use Default.
9. Try to select Default State from the dropdown list instead of Use Default.

ACTUAL RESULTS:
Only when selecting countries that have been selected for the Main Website (Step 4), will the Default State dropdown display a full list. Otherwise, it does not display the full list of states:

@@ -406,14 +406,21 @@ public function getWeightUnit()
* Get current scope from request
*
* @return array
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
private function getCurrentScope(): array
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that getCurrentScope probably shouldn't be on this helper, but by adding that condition it makes the function ambiguous. My proposal would be to look at the solution from the Create Order perspective, see from which request this function is being called, and make sure we have the correct scope on the request, it should be also a quick fix, what do you think?

@engcom-Charlie
Copy link
Contributor

Hello @bogutskyy, could you please look at #30755 (comment)?
Thank you.

@engcom-Charlie
Copy link
Contributor

Hello @bogutskyy, I'll try to continue with your PR.

@bogutskyy
Copy link
Contributor Author

@engcom-Charlie sure. Unfortunately, I don't have time to finish PR in the coming weeks Let me know if you need anything from me.

@gabrieldagama
Copy link
Contributor

@magento run all tests

@magento-engcom-team
Copy link
Contributor

Hi @gabrieldagama, thank you for the review.
ENGCOM-8797 has been created to process this Pull Request
✳️ @gabrieldagama, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@engcom-Delta
Copy link
Contributor

✔️ QA passed
Was checked case described in issue #30577
Before:
❌ Error Please check the shipping address information. "regionId" is required. Enter and try again. is shown and the order is not placed.
Screenshot from 2021-02-22 13-54-20

After:
✔️ Order is placed successfully
Screenshot from 2021-02-22 14-06-43

@engcom-Delta engcom-Delta added the QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope label Feb 22, 2021
@engcom-Delta
Copy link
Contributor

Note: Functional Tests B2B are failed

@m2-assistant
Copy link

m2-assistant bot commented Mar 18, 2021

Hi @bogutskyy, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@hussainbaig34
Copy link

Hi Guys,

I am running Magento 2.4.2. I Just migrated from 1.9.3. Alot of my orders are declining due to this issue. Is there a way I can fix this on my website quick?

Regards,
Hussain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Component: Config Component: Customer Component: Directory Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: accept QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope Release Line: 2.4 Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Type: Bug Fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't place order on admin: "regionId" is required
7 participants