diff -Nuar a/vendor/magento/module-sitemap/Model/Observer.php b/vendor/magento/module-sitemap/Model/Observer.php index ce74d738c4b..4333c71c749 100644 --- a/vendor/magento/module-sitemap/Model/Observer.php +++ b/vendor/magento/module-sitemap/Model/Observer.php @@ -3,11 +3,15 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Sitemap\Model; -use Magento\Sitemap\Model\EmailNotification as SitemapEmail; +use Magento\Framework\App\Area; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Sitemap\Model\EmailNotification as SitemapEmail; use Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory; +use Magento\Store\Model\App\Emulation; use Magento\Store\Model\ScopeInterface; /** @@ -62,19 +66,27 @@ class Observer private $emailNotification; /** + * @var Emulation + */ + private $appEmulation; + + /** * Observer constructor. * @param ScopeConfigInterface $scopeConfig * @param CollectionFactory $collectionFactory * @param EmailNotification $emailNotification + * @param Emulation $appEmulation */ public function __construct( ScopeConfigInterface $scopeConfig, CollectionFactory $collectionFactory, - SitemapEmail $emailNotification + SitemapEmail $emailNotification, + Emulation $appEmulation ) { $this->scopeConfig = $scopeConfig; $this->collectionFactory = $collectionFactory; $this->emailNotification = $emailNotification; + $this->appEmulation = $appEmulation; } /** @@ -105,9 +117,16 @@ class Observer foreach ($collection as $sitemap) { /* @var $sitemap \Magento\Sitemap\Model\Sitemap */ try { + $this->appEmulation->startEnvironmentEmulation( + $sitemap->getStoreId(), + Area::AREA_FRONTEND, + true + ); $sitemap->generateXml(); } catch (\Exception $e) { $errors[] = $e->getMessage(); + } finally { + $this->appEmulation->stopEnvironmentEmulation(); } } if ($errors && $recipient) {