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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pub/errors/processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,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?

$this->_setSkin($_ENV['MAGE_RUN_CODE']);

if (isset($_ENV['MAGE_RUN_TYPE'])) {
$this->_setSkin($ENV_['MAGE_RUN_TYPE'] . '-' . $_ENV['MAGE_RUN_CODE']);
}
}

if (isset($_GET['skin'])) {
$this->_setSkin($_GET['skin']);
}
Expand Down Expand Up @@ -729,7 +738,7 @@ protected function _validate()
*/
protected function _setSkin($value, \stdClass $config = null)
{
if (preg_match('/^[a-z0-9_]+$/i', $value) && is_dir($this->_errorDir . $value)) {
if (preg_match('/^[a-z0-9_-]+$/i', $value) && is_dir($this->_errorDir . $value)) {
if (!$config) {
if ($this->_config) {
$config = $this->_config;
Expand Down