Skip to content
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

[Issue] Magento_Backend store switcher: Use nowdoc instead of heredoc #32262

Closed
m2-assistant bot opened this issue Feb 23, 2021 · 1 comment · Fixed by #32249
Closed

[Issue] Magento_Backend store switcher: Use nowdoc instead of heredoc #32262

m2-assistant bot opened this issue Feb 23, 2021 · 1 comment · Fixed by #32249
Assignees
Labels
Component: Backend Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S2 Major restrictions or short-term circumventions are required until a fix is available.

Comments

@m2-assistant
Copy link

m2-assistant bot commented Feb 23, 2021

This issue is automatically created based on existing pull request: #32249: Magento_Backend store switcher: Use nowdoc instead of heredoc

Description (*)

The heredoc in Magento/Backend/view/adminhtml/templates/store/switcher.phtml#L203-L216 is not valid, because the embedded JavaScript contains $this, which happens to be a valid variable name in PHP, too. Consequently, PHP tries to replace its occurrences by the current class object which results in an error. This can be avoided by using nowdoc instead of heredoc, which is the aim of this PR.

In Magento core, the is*using_iframe flag is never set. As a consequence, the else-branch in [Magento/Backend/view/adminhtml/templates/store/switcher.phtml#L203-L216](https://github.com/magento/magento2/blob/896f0d6/app/code/Magento/Backend/view/adminhtml/templates/store/switcher.phtml#L203-L216] is never called, so the error does not occur in a standard environment. However, we use Amasty's [_Improved Layered Navigation*|https://amasty.com/improved-layered-navigation-for-magento-2.html), which sets this flag to true for one of their backend configurations. The resulting error (in developer mode) looks as follows:

Screenshot from 2021-02-23 08-32-05

Related Pull Requests

Two years ago, there was #20656 to replace all heredoc by nowdoc, but it was closed.

Fixed Issues (if relevant)

No separate issue created.

Preconditions (*)

Magento 2.4-develop

Steps to reproduce (*)

For reproducing this error, it is not necessary to install Magento or the referenced Amasty extension at all. Simply paste the snippet into a fresh PHP file test.php:

<?php
$test = <<<script
            jQuery('#preview*selected*store').val(scopeId);
            jQuery('#preview_form').submit();

            jQuery('.store-switcher .dropdown-menu li a').each(function() {
                var $this = jQuery(this);

                if ($this.data('role') === 'store-view-id' && $this.data('value') == scopeId) {
                    jQuery('#store-change-button').html($this.text());
                }
            });

            jQuery('#store-change-button').click();
script;
echo $test;
{code}

Calling the script via `php -f test.php` yields a similar error. Changing the first line to `<<<'script'` resolves this issue.

### Actual result
An Exception message appeared 
{code}
1 exception(s):
Exception #0 (Exception): Notice: Undefined variable: test in .../app/code/Magento/Backend/view/adminhtml/templates/store/switcher.phtml on line 227

Exception #0 (Exception): Notice: Undefined variable: test in .../app/code/Magento/Backend/view/adminhtml/templates/store/switcher.phtml on line 227
<pre]#1 include() called at [lib/internal/Magento/Framework/View/TemplateEngine/Php.php:71]
#2 Magento\Framework\View\TemplateEngine\Php->render() called at [lib/internal/Magento/Framework/View/Element/Template.php:273]
#3 Magento\Framework\View\Element\Template->fetchView() called at [generated/code/Magento/Backend/Block/Store/Switcher/Interceptor.php:419]
#4 Magento\Backend\Block\Store\Switcher\Interceptor->fetchView() called at [lib/internal/Magento/Framework/View/Element/Template.php:303]
#5 Magento\Framework\View\Element\Template->_toHtml() called at [app/code/Magento/Backend/Block/Template.php:141]
...
#46 Magento\Backend\Model\View\Result\Page\Interceptor->renderResult() called at [lib/internal/Magento/Framework/App/Http.php:120]
#47 Magento\Framework\App\Http->launch() called at [generated/code/Magento/Framework/App/Http/Interceptor.php:23]
#48 Magento\Framework\App\Http\Interceptor->launch() called at [lib/internal/Magento/Framework/App/Bootstrap.php:264]
#49 Magento\Framework\App\Bootstrap->run() called at [pub/index.php:29]
[/pre>

exc_before

Expected Result

No errors appear in the Admin panel. The Scope can be changed.

@m2-assistant m2-assistant bot added Component: Backend Priority: P2 A defect with this priority could have functionality issues which are not to expectations. labels Feb 23, 2021
@m2-community-project m2-community-project bot added this to Pull Request In Progress in High Priority Backlog Feb 23, 2021
@engcom-Bravo engcom-Bravo added Severity: S2 Major restrictions or short-term circumventions are required until a fix is available. Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed labels Mar 2, 2021
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Bravo
Thank you for verifying the issue. Based on the provided information internal tickets MC-41126 were created

Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Backend Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S2 Major restrictions or short-term circumventions are required until a fix is available.
Projects
Development

Successfully merging a pull request may close this issue.

3 participants