Skip to content

Use per-store or per-website skin if available in the error application #35095

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

Open
wants to merge 5 commits into
base: 2.4-develop
Choose a base branch
from

Conversation

fredden
Copy link
Member

@fredden fredden commented Feb 13, 2022

Description (*)

When Magento is unable or unwilling to process a request (eg, because maintenance mode has been enabled) the request is forwarded to the application within pub/errors/. This uses a different set of theme files to the main website (intentionally), but is not flexible when dealing with multi-store or multi-website configurations.

This is not necessarily a problem when all the stores/website share a common theme and language. (For example, British & American & Australian stores with the same brand but different currencies / localisation will all be fine using a shared skin/theme in English for pub/errors/.) However, when there are multiple distinct brands being served from a single Magento instance or when different languages are being used, a single skin for pub/errors/ is not suitable.

We have implemented a similar approach to what is being proposed here on websites for our merchants with good results. Here we are using the MAGE_RUN_TYPE and MAGE_RUN_CODE environment variables to determine which skin / theme to use in error pages.

Calling _setSkin() multiple times is safe. If there is no suitable skin matching the name of the store/website, then these lines have no impact, falling back to other skin-setting mechanisms like $_GET['skin'] or pub/errors/local.xml or pub/errors/design.xml.

Related Pull Requests

Fixed Issues

None. Please feel free to create an issue if you feel this is appropriate.

Manual testing scenarios (*)

  1. Set up Magento with multi-store or multi-website, ensure these have distinct URLs, eg https://de.magento.test/ https://es.magento.test/ https://fr.magento.test/. - see guide here for details: https://devdocs.magento.com/guides/v2.4/config-guide/multi-site/ms_over.html
  2. Enable maintenance mode with bin/magento maintenance:enable
  3. Navigate to each store front. Notice that all serve the same skin for pub/errors/.
  4. Create a new skin for error pages by copying pub/errors/local.xml.sample to pub/errors/local.xml, and pub/errors/default/ to pub/errors/custom/, and setting <skin>custom</skin> in pub/errors/local.xml.
  5. Navigate to each store front. Notice that all serve the same skin for pub/errors/.
  6. Notice no ability to customise the errors per-store nor per-website before the changes here.
  7. Apply the changes in this pull request.
  8. Create new skins for each store/website as desired. For example, copy pub/errors/custom/ to pub/errors/es/ and translate/theme this appropriately.
  9. Navigate to each store front. Notice that a different skin is applied to each where this exists, and that where no matching theme/skin exists, the default is used.

Questions or comments

None

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)

@m2-assistant
Copy link

m2-assistant bot commented Feb 13, 2022

Hi @fredden. Thank you for your contribution
Here are 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
  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 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, join the Community Contributions Triage session to discuss the appropriate ticket.

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

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@engcom-Hotel
Copy link
Contributor

@magento run static tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@sdzhepa sdzhepa added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Feb 17, 2022
@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

Copy link

@leonhelmus leonhelmus left a comment

Choose a reason for hiding this comment

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

I do suggest another approach the approach taken now should do as well.

@@ -186,6 +186,15 @@ public function __construct(
$this->_root = is_dir($this->_indexDir . 'app');

$this->_prepareConfig();

if (isset($_ENV['MAGE_RUN_CODE'])) {

Choose a reason for hiding this comment

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

Suggested change
if (isset($_ENV['MAGE_RUN_CODE'])) {
if (isset($_ENV['MAGE_RUN_CODE'])) {
$skin = isset($_ENV['MAGE_RUN_TYPE']) ? $ENV_['MAGE_RUN_TYPE'] . '-' . $_ENV['MAGE_RUN_CODE'] : $_ENV['MAGE_RUN_CODE'];
$this->_setSkin($skin);
}

Choose a reason for hiding this comment

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

This way you prevent a second request of the same method _setSkin()

Copy link
Member Author

@fredden fredden Mar 20, 2023

Choose a reason for hiding this comment

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

Calling _setSkin() multiple times (and in this order) is intentional. The _setSkin() method includes some name validation and (importantly) an is_dir() check. With the current implementation, a developer can create a per-website theme, even if there is a store code in the web server configuration. With the proposed implementation, a per-website theme is ignored / unusable when a store code is specified in web server configuration.

Edit: I've clearly forgotten how the code actually works; it's been a long time since I opened this pull request. The double-call allows developers to differentiate between a store-hats and website-hats (or store-hats and hats) while keeping the simple case simple with just hats when the same theme is used in both scopes. Like with other places in Magento, the most specific option will be used.

Copy link
Member Author

Choose a reason for hiding this comment

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

@leonhelmus would it help if I add a code comment to explain why we're calling _setSkin() multiple times?

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Partner: Fisheye partners-contribution Pull Request is created by Magento Partner Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: review Release Line: 2.4
Projects
Status: Review in Progress
Development

Successfully merging this pull request may close these issues.

6 participants