Skip to content

fix(store): set store/currency context for ActionInterface controllers (#40747)#40829

Open
lbajsarowicz wants to merge 2 commits into
magento:2.4-developfrom
lbajsarowicz:fix/40747-store-context-plugin-beforeexecute
Open

fix(store): set store/currency context for ActionInterface controllers (#40747)#40829
lbajsarowicz wants to merge 2 commits into
magento:2.4-developfrom
lbajsarowicz:fix/40747-store-context-plugin-beforeexecute

Conversation

@lbajsarowicz
Copy link
Copy Markdown
Contributor

Description

Magento\Store\App\Action\Plugin\Context was registered as a plugin on
Magento\Framework\App\Action\AbstractAction::dispatch(). Controllers that
implement HttpGetActionInterface / ActionInterface directly (without
extending AbstractAction) never triggered the plugin, so the store and
currency values were never written to the HTTP context.

For logged-in customers on full-page-cache hosts this manifested as the
X-Magento-Vary cookie alternating between two hashes between requests,
corrupting cache lookups for the affected endpoint.

Mirrors the migration already done for Customer/Tax/Weee context plugins:

  • plugin attaches to Magento\Framework\App\ActionInterface
  • beforeDispatch(AbstractAction, RequestInterface) becomes
    beforeExecute(ActionInterface), pulling the request from a
    constructor-injected RequestInterface (OM fallback preserves
    third-party constructor BC)

Fixes #40747

Fixed Issues

Manual testing scenarios

  1. Create a frontend controller implementing HttpGetActionInterface directly (no AbstractAction).
  2. Open the route as a logged-in customer with FPC enabled.
  3. Reload — X-Magento-Vary cookie stable across requests (before: alternates between two hashes).

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (new ContextTest + StoreCheckTest pass)
  • Changes to the codebase comply with technical guidelines

Magento\Store\App\Action\Plugin\Context was registered as a plugin
on Magento\Framework\App\Action\AbstractAction::dispatch(). Controllers
that implement HttpGetActionInterface / ActionInterface directly
without extending AbstractAction never triggered the plugin, so the
store and currency values were never written to the HTTP context.

For logged-in customers on full-page-cache hosts this manifested as
the X-Magento-Vary cookie alternating between two hashes between
requests, corrupting cache lookups for the affected endpoint.

Mirror the migration already done for Customer/Tax/Weee context
plugins:
- plugin attaches to Magento\Framework\App\ActionInterface
- beforeDispatch(AbstractAction, RequestInterface) becomes
  beforeExecute(ActionInterface), pulling the request from a
  constructor-injected RequestInterface (OM fallback preserves
  third-party constructor BC).

Fixes magento#40747
@m2-assistant
Copy link
Copy Markdown

m2-assistant Bot commented May 25, 2026

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 lbajsarowicz changed the title fix(store): set store/currency context for ActionInterface controllers fix(store): set store/currency context for ActionInterface controllers (#40747) May 25, 2026
@engcom-Hotel engcom-Hotel added the Priority: P3 May be fixed according to the position in the backlog. label May 26, 2026
@github-project-automation github-project-automation Bot moved this to Pending Review in Pull Requests Dashboard May 26, 2026
Remove the _files/ContextTestSession.php helper and the require_once
that loaded it. The abstract class existed only to expose getCurrencyCode
on a SessionManagerInterface mock; replace with getMockBuilder()->
addMethods()->getMockForAbstractClass() directly in setUp so no external
file is needed. This resolves the Magento2.PHP.NoRequireOnce PHPCS violation
and eliminates the non-standard PSR-4 _files namespace path.
@lbajsarowicz
Copy link
Copy Markdown
Contributor Author

@magento run all tests

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

Labels

Priority: P3 May be fixed according to the position in the backlog. Progress: pending review

Projects

Status: Pending Review

2 participants