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

Mail templates sent with scheduler don't get translated #3805

Closed
nobodypb opened this issue Mar 16, 2016 · 6 comments
Closed

Mail templates sent with scheduler don't get translated #3805

nobodypb opened this issue Mar 16, 2016 · 6 comments

Comments

@nobodypb
Copy link

If I sent mails using cron they won't get translated, because PART_TRANSLATE is never loaded in the App\Area.
To quick fix this I added

$areaObject = $this->_areaList->getArea($this->getDesignConfig()->getArea());
$areaObject->load(\Magento\Framework\App\Area::PART_TRANSLATE);

to \Magento\Email\Model\AbstractTemplate::applyDesignConfig()
(And some di things for _areaList)

I don't know if that bug is somehow related to my setup, I'm running Magento 2.0.2 on php7

@vzabaznov vzabaznov added the PS label Mar 16, 2016
@srbarba
Copy link

srbarba commented Jun 10, 2016

I have the same problem.
Thank you @nobodypb , Your fix solved my issue! :D

Please, add this fix to future releases!

@JDavidVR
Copy link
Contributor

JDavidVR commented Jun 23, 2016

Hi @srbarba , @nobodypb can you clarify the solution

just for test I edited file: vendor/magento/module-email/Model/AbstractTemplate.php

in constructor I added:

protected $_areaList;
public function __construct(
        \Magento\Framework\Model\Context $context,
        \Magento\Framework\View\DesignInterface $design,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\App\AreaList $areaList, // <-----------------
        \Magento\Store\Model\App\Emulation $appEmulation,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Framework\View\Asset\Repository $assetRepo,
        \Magento\Framework\Filesystem $filesystem,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Email\Model\Template\Config $emailConfig,
        \Magento\Email\Model\TemplateFactory $templateFactory,
        \Magento\Framework\Filter\FilterManager $filterManager,
        \Magento\Framework\UrlInterface $urlModel,
        array $data = []
    ) {
        $this->design = $design;
        $this->area = isset($data['area']) ? $data['area'] : null;
        $this->store = isset($data['store']) ? $data['store'] : null;
        $this->appEmulation = $appEmulation;
        $this->_areaList = $areaList; // <-----------------
        $this->storeManager = $storeManager;
        $this->assetRepo = $assetRepo;
        $this->filesystem = $filesystem;
        $this->scopeConfig = $scopeConfig;
        $this->emailConfig = $emailConfig;
        $this->templateFactory = $templateFactory;
        $this->filterManager = $filterManager;
        $this->urlModel = $urlModel;
        parent::__construct($context, $registry, null, null, $data);
    }

and in method applyDesignConfig()

protected function applyDesignConfig()
    {
        $areaObject = $this->_areaList->getArea($this->getDesignConfig()->getArea()); //<--------
        $areaObject->load(\Magento\Framework\App\Area::PART_TRANSLATE); //<------

        // Only run app emulation if this is the parent template and emulation isn't already running.
        // Otherwise child will run inside parent emulation.
        if ($this->isChildTemplate() || $this->hasDesignBeenApplied) {
            return false;
        }
        $this->hasDesignBeenApplied = true;

        $designConfig = $this->getDesignConfig();
        $storeId = $designConfig->getStore();
        $area = $designConfig->getArea();
        if ($storeId !== null) {
            // Force emulation in case email is being sent from same store so that theme will be loaded. Helpful
            // for situations where emails may be sent from bootstrap files that load frontend store, but not theme
            $this->appEmulation->startEnvironmentEmulation($storeId, $area, true);
        }
        return true;
    }

but when I change order status from backend it is giving me an error.

please can you help me, to understand what is wrong with my changes

@srbarba
Copy link

srbarba commented Jun 23, 2016

I'm sorry @JDavidVR but I only used this fix for my custom module. I didn't try to set it at core.

Reading the function I think you should use this fix AFTER the first validation:

protected function applyDesignConfig()
    {


        // Only run app emulation if this is the parent template and emulation isn't already running.
        // Otherwise child will run inside parent emulation.
        if ($this->isChildTemplate() || $this->hasDesignBeenApplied) {
            return false;
        }

        $areaObject = $this->_areaList->getArea($this->getDesignConfig()->getArea()); //<--------
        $areaObject->load(\Magento\Framework\App\Area::PART_TRANSLATE); //<------

        $this->hasDesignBeenApplied = true;

        $designConfig = $this->getDesignConfig();
        $storeId = $designConfig->getStore();
        $area = $designConfig->getArea();
        if ($storeId !== null) {
            // Force emulation in case email is being sent from same store so that theme will be loaded. Helpful
            // for situations where emails may be sent from bootstrap files that load frontend store, but not theme
            $this->appEmulation->startEnvironmentEmulation($storeId, $area, true);
        }
        return true;
    }

Can you share the given error?

@nobodypb
Copy link
Author

nobodypb commented Jul 5, 2016

@srbarba is right, but make sure to also change the constructor of
Magento\Email\Model\BackendTemplate
since Magento\Email\Model\Template::__construct is called there

@veloraven
Copy link
Contributor

@nobodypb if this issue is still actual please describe it according to the Issue reporting guidelines: with steps to reproduce, actual result and expected result.

@veloraven
Copy link
Contributor

According to contributor guide, tickets without response for two weeks should be closed.
If this issue still reproducible please feel free to create the new one: format new issue according to the Issue reporting guidelines: with steps to reproduce, actual result and expected result and specify Magento version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants