Skip to content

Fix GraphQL Content-Currency validation against the store named by the Store header (#41242) - #41247

Open
lbajsarowicz wants to merge 2 commits into
magento:2.4-developfrom
lbajsarowicz:fix/41242-graphql-currency-validator-store-header
Open

Fix GraphQL Content-Currency validation against the store named by the Store header (#41242)#41247
lbajsarowicz wants to merge 2 commits into
magento:2.4-developfrom
lbajsarowicz:fix/41242-graphql-currency-validator-store-header

Conversation

@lbajsarowicz

Copy link
Copy Markdown
Contributor

Description (*)

A GraphQL request that sends Store: <store code> together with Content-Currency: <code> is rejected with Please correct the target currency whenever that currency is allowed only on the requested website and not on the default one.

Root cause: Magento\GraphQlCache\Controller\Plugin\GraphQl::beforeDispatch() runs validateRequest() before processHeaders(). Magento\DirectoryGraphQl\Controller\HttpRequestValidator\CurrencyValidator therefore checks the header against storeManager->getStore(), which is still the default store, because the Store header is only applied by StoreProcessor inside processHeaders(). The validator throws, processHeaders() is skipped, and the second validation pass in GraphQl::dispatch() fails the same way. This ordering was introduced by AC-821 for #31336 (store validation must run before the store is switched) and tightened by AC-11729, so the plugin order is not changed here.

The fix makes CurrencyValidator resolve the store it validates against from the Store header itself, falling back to the current store when the header is absent. An unknown or inactive store code keeps producing Requested store is not found, matching StoreValidator, so the validator no longer depends on the order in which the two validators are registered.

Tests:

  • New unit test Magento\DirectoryGraphQl\Test\Unit\Controller\HttpRequestValidator\CurrencyValidatorTest covering the header/no-header paths, rejected currencies, unknown and inactive store codes, empty header and normalisation.
  • New API-functional test Magento\GraphQl\Directory\CurrencyHeaderValidationTest with a second website whose only allowed, base and default currency is NOK (absent from the default scope): Store + Content-Currency: NOK succeeds, Content-Currency: NOK without Store is rejected, Store + Content-Currency: USD is rejected.

Related Pull Requests

None.

Fixed Issues (if relevant)

  1. Fixes GraphQl Content-Currency exception when default config differs from website/storeview. #41242
  2. Same defect as reported in Error "Please correct the target currency" when switching store with different currency than default one on GraphQl #38732

Manual testing scenarios (*)

  1. Create a second website, store and store view (code nok_sv).
  2. Set catalog/price/scope to Website. For the new website set currency/options/allow, currency/options/base and currency/options/default to NOK. Leave the default scope on USD.
  3. POST /graphql with headers Store: nok_sv, Content-Currency: NOK and query { storeConfig { store_code base_currency_code } }.
  4. Before the fix: Please correct the target currency. After the fix: store_code is nok_sv, base_currency_code is NOK.
  5. Repeat without the Store header: still rejected, because NOK is not allowed on the default store.

Questions or comments

Local gates: unit, integration (no integration tests changed), PHPCS, PHPStan and the Static Tests reproduction were run on the changed files; the API-functional test relies on the upstream WebAPI build.

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

…er (magento#41242)

CurrencyValidator validated Content-Currency against the default store
because it ran before StoreProcessor applied the Store header. It now
resolves the store named by the Store header itself, matching the store
StoreProcessor sets afterwards, and treats an inactive store the same as
a missing one instead of depending on validator registration order.
@m2-assistant

m2-assistant Bot commented Sep 8, 2026

Copy link
Copy Markdown

Hi @lbajsarowicz. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ 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
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ 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.

@lbajsarowicz

Copy link
Copy Markdown
Contributor Author

@magento run all tests

@lbajsarowicz

Copy link
Copy Markdown
Contributor Author

@magento run all tests

@ct-prd-projects-boards-automation ct-prd-projects-boards-automation Bot added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Sep 11, 2026
@github-project-automation github-project-automation Bot moved this to Pending Review in Pull Requests Dashboard Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: pending review

Projects

Status: Pending Review

Development

Successfully merging this pull request may close these issues.

GraphQl Content-Currency exception when default config differs from website/storeview.

1 participant