Skip to content

Theme templates overrides don't work in environment emulation cross-area #10402

@alessandroniciforo

Description

@alessandroniciforo

The theme templates overrides are not resolved correctly if we're in an environment emulation cross-area (e.g.: we're in adminhtml emulating frontend).

My particular case has been this: I have a custom template overriding the payment method info template, I login in the Magento admin, find an order, click "Send email". The email won't have the overridden template.

Techincal details

To render the payment method info block Magento emulates the order's store in the frontend area (https://github.com/magento/magento2/blob/develop/app/code/Magento/Payment/Helper/Data.php#L208) and then calls toHtml() on the block. The template file resolution will pass through Magento\Framework\View\Asset\Repository::updateDesignParams(), will execute line #145 setting $theme to the theme ID, and will execute line #149 that tries to load the theme by full path rather than by ID, thus returning no theme.

The code of this method normally works because if we're not in an environment emulation cross-area, the execution will not fall into that elseif and will not execute line #145 going likely into line #154.

I'm going to submit a pull request with what I believe is a possible solution.

Preconditions

  1. Magento CE 2.1.7

Steps to reproduce

  1. Create a new custom frontend template that inherits from Magento/Luma
  2. Inside the template directory (app/design/frontend/<vendor>/<themeName>) create the folder Magento_OfflinePayments/templates/info/ and create checkmo.phtml into it. The content of this file can be, for example, "Payment method override test"
  3. Go on Magento admin, set the store design to use this template and flush cache
  4. Go on frontend, login, complete an order with payment method "Check / Money order"
  5. Go in your account area, open this order and verify that it shows "Payment method override test" as payment method
  6. Go on Magento admin, find this order and click "Send email" on it

Expected result

  1. The email received has "Payment method override test" as well as payment method

Actual result

  1. The email doesn't have "Payment method override test" but it has the standard payment method label provided by the module template

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasebug reporttriage wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions