Open
Description
Theme assets are managed by Magento\Framework\View\Asset\Repository and there are problems with it when using "app emulation" (used by email template processing) :
- Sending emails from backend use the backend base url for static urls (it is a real problem if the admin url is to be hidden and/or is inaccessible from most IP).
- Besides the "pub" problem ( MAGETWO-84709 - Respect Magento document root in CLI #14334 ) which is way more critical ; the app emulation works in CLI/cronjobs except there are cache problems (results stored in object fields). Then multiple template processing for different stores in the same process generates wrong static urls (it uses the first generated template store url).
I put the two issues in same ticket to keep them in mind when reworking this asset management if any
I used the "Reset password" feature to demonstrate the issues but it's the same with order confirmation email.
Preconditions
- Magento 2.2.4
- Apache 2.4 / PHP 7.0.27
Steps to reproduce
- Setup a Magento with 2 websites with different domains as described here https://devdocs.magento.com/guides/v2.2/config-guide/multi-site/ms_apache.html + with a custom admin url to a different domain (Advanced > Admin > Admin Base URL > Custom Admin URL) ; so 3 domains in total
- Create "Customer 1" in the frontend of Website 1
- Create "Customer 2" in the frontend of Website 2
- Edit "Customer 2" in the backend and click "reset password"
- Create a CLI Command and/or a cronjob that calls the password reset process the same way the backend controller does (see cronjob class sample below) and make it run
namespace Xxx\MailBug\Cron;
class Test
{
protected $storeManager;
protected $customerRepository;
protected $accountManagement;
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
\Magento\Customer\Api\AccountManagementInterface $accountManagement)
{
$this->storeManager = $storeManager;
$this->customerRepository = $customerRepository;
$this->accountManagement = $accountManagement;
}
public function execute()
{
echo "cron test email\n";
/** @see \Magento\Customer\Controller\Adminhtml\Index\ResetPassword::execute() */
$customer = $this->customerRepository->getById(/* Customer 2 id */ 2);
$this->accountManagement->initiatePasswordReset(
$customer->getEmail(),
\Magento\Customer\Model\AccountManagement::EMAIL_REMINDER,
$customer->getWebsiteId()
);
$customer = $this->customerRepository->getById(/* Customer 1 id */ 1);
$this->accountManagement->initiatePasswordReset(
$customer->getEmail(),
\Magento\Customer\Model\AccountManagement::EMAIL_REMINDER,
$customer->getWebsiteId()
);
echo "done\n";
}
}
Expected result
- Received mails should have asset urls matching the desired store (for Customer password reset mails : the store or website in which the user registered), including logo url and inlined css assets in head section
Actual result
- Mail sent using the backend Reset password feature has admin static urls
- First mail sent using CLI/cron is ok (except "pub" problem), second mail sent from the same process has static urls from the wrong frontend store
Metadata
Metadata
Assignees
Labels
Gate 3 Passed. Manual verification of the issue completed. Issue is confirmedA defect with this priority could have functionality issues which are not to expectations.The issue has been reproduced on latest 2.2 releaseThe issue has been reproduced on latest 2.3 releaseThe issue has been reproduced on latest 2.4-develop branchMajor restrictions or short-term circumventions are required until a fix is available.Issue related to Developer Experience and needs help with Triage to Confirm or Reject it