magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.46k stars 9.29k forks source link

Magento 2.1.6 - Cronjob triggered e-mails ignores theme-fallback (Template, PDF, Customizations,...) #9916

Closed lfritsche closed 6 years ago

lfritsche commented 7 years ago

Preconditions

  1. Magento 2.1.6
  2. PHP 7.0

Steps to reproduce

  1. We create invoice and shipment programmatically after placing an order with some cronjob routines.
  2. After creating the invoice the email should be sent which worked very well until we updated from 2.0.4 to 2.1.6
  3. Right no those mails sent within a cronjob routine are free from any design changes within app/design. They are sent in the magento standard design, without any customizations applied, placed unter app/design.
  4. Not only the e-mail templates get ignored, but also the PDF templates (I'm using Fooman PDF customizer).
  5. Language translation (using de_DE) seems to work properly.

Expected result

  1. E-Mail sending should behave like sending them from the backend or on creating an order.
  2. E-Mail should rely on custom templates and use third party PDF templates...
  3. Magento should not ignore custom .phtml templates.

Actual result

  1. Every app/design/../*.phtml file is ignored by magento, if email sending ist triggered by cronjob.
  2. Magento uses the standard files and ignores theme-fallback.

Problem:

If you have Magento 2.0.4 and use Single Store Mode = On and set theme in Store>Configuration>Design>Design Theme and update magento to 2.1.x, then $theme not retrieve from config in \Magento\Theme\Model\View\Design::getConfigurationDesignTheme

if ($this->_storeManager->isSingleStoreMode()) {
    $theme = $this->_scopeConfig->getValue(
        self::XML_PATH_THEME_ID,
        ScopeInterface::SCOPE_WEBSITES
    );
} else {
    $theme = (string) $this->_scopeConfig->getValue(
        self::XML_PATH_THEME_ID,
        ScopeInterface::SCOPE_STORE,
        $store
    );
}
lfritsche commented 7 years ago

I had some great help and can provide an update on this:

startEnvironmentEmulation in \Magento\Store\Model\App\Emulation:

$storeTheme = $this->_viewDesign->getConfigurationDesignTheme($area, ['store' => $storeId]);
$this->_viewDesign->setDesignTheme($storeTheme, $area);

If run by cronjob $storeTheme seems to be empty. Within getConfigurationDesignTheme the Single Store Mode seems to involved.

            if ($this->_storeManager->isSingleStoreMode()) {
                $theme = $this->_scopeConfig->getValue(
                    self::XML_PATH_THEME_ID,
                    ScopeInterface::SCOPE_WEBSITES
                );
            } else {
                $theme = (string) $this->_scopeConfig->getValue(
                    self::XML_PATH_THEME_ID,
                    ScopeInterface::SCOPE_STORE,
                    $store
                );
            }

I turned SingleStore Mode OFF and everything worked as expected again. Any Idea why getConfigurationDesignTheme doesn't respond with a valid $storeTheme, if the Single Store Mode is turned on?

Thank you!

magento-engcom-team commented 6 years ago

@lfritsche Thanks for reporting this issue. This is migration bug. You can use "Single Store Mode" = "Yes" after resave your theme configuration in: Content>Design>Configuration

magento-engcom-team commented 6 years ago

We update description:

Problem:

If you have Magento 2.0.4 and use Single Store Mode = On and set theme in Store>Configuration>Design>Design Theme and update magento to 2.1.x, then $theme not retrieve from config in \Magento\Theme\Model\View\Design::getConfigurationDesignTheme

if ($this->_storeManager->isSingleStoreMode()) {
    $theme = $this->_scopeConfig->getValue(
        self::XML_PATH_THEME_ID,
        ScopeInterface::SCOPE_WEBSITES
    );
} else {
    $theme = (string) $this->_scopeConfig->getValue(
        self::XML_PATH_THEME_ID,
        ScopeInterface::SCOPE_STORE,
        $store
    );
}
magento-engcom-team commented 6 years ago

@lfritsche, thank you for your report. We've created internal ticket(s) MAGETWO-80156 to track progress on the issue.

serhii-balko commented 6 years ago

Hi @lfritsche This issue already fixed in 2.1.10 version

JeremyPlease commented 6 years ago

I am experiencing this issue in Magento CE 2.2.5.

Debugging the code, I see that from cron jobs, the following code returns nothing for the theme id:

$theme = $this->_scopeConfig->getValue(
    self::XML_PATH_THEME_ID,
    ScopeInterface::SCOPE_WEBSITES
);

However, the same code not triggered by a cronjob gets the theme id correctly.

@serhii-balko and @magento-engcom-team Was this fixed in Magento 2.2.x? Can you link to the commit that has the fix?

Thanks!

jfmontanaro commented 6 years ago

@JeremyPlease I had the same issue in 2.2.5. Here's the solution that worked for me:

JeremyPlease commented 6 years ago

Thanks for the suggestion @jfmontanaro.

I ended up working around this by moving the email template to an extension and using etc/email_templates.xml to override the email template.