|
3 | 3 | * Copyright © Magento, Inc. All rights reserved.
|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
| 6 | +declare(strict_types=1); |
| 7 | + |
6 | 8 | namespace Magento\Sitemap\Model;
|
7 | 9 |
|
8 |
| -use Magento\Sitemap\Model\EmailNotification as SitemapEmail; |
| 10 | +use Magento\Framework\App\Area; |
9 | 11 | use Magento\Framework\App\Config\ScopeConfigInterface;
|
| 12 | +use Magento\Sitemap\Model\EmailNotification as SitemapEmail; |
10 | 13 | use Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory;
|
| 14 | +use Magento\Store\Model\App\Emulation; |
11 | 15 | use Magento\Store\Model\ScopeInterface;
|
12 | 16 |
|
13 | 17 | /**
|
@@ -61,20 +65,28 @@ class Observer
|
61 | 65 | */
|
62 | 66 | private $emailNotification;
|
63 | 67 |
|
| 68 | + /** |
| 69 | + * @var Emulation |
| 70 | + */ |
| 71 | + private $appEmulation; |
| 72 | + |
64 | 73 | /**
|
65 | 74 | * Observer constructor.
|
66 | 75 | * @param ScopeConfigInterface $scopeConfig
|
67 | 76 | * @param CollectionFactory $collectionFactory
|
68 | 77 | * @param EmailNotification $emailNotification
|
| 78 | + * @param Emulation $appEmulation |
69 | 79 | */
|
70 | 80 | public function __construct(
|
71 | 81 | ScopeConfigInterface $scopeConfig,
|
72 | 82 | CollectionFactory $collectionFactory,
|
73 |
| - SitemapEmail $emailNotification |
| 83 | + SitemapEmail $emailNotification, |
| 84 | + Emulation $appEmulation |
74 | 85 | ) {
|
75 | 86 | $this->scopeConfig = $scopeConfig;
|
76 | 87 | $this->collectionFactory = $collectionFactory;
|
77 | 88 | $this->emailNotification = $emailNotification;
|
| 89 | + $this->appEmulation = $appEmulation; |
78 | 90 | }
|
79 | 91 |
|
80 | 92 | /**
|
@@ -105,7 +117,13 @@ public function scheduledGenerateSitemaps()
|
105 | 117 | foreach ($collection as $sitemap) {
|
106 | 118 | /* @var $sitemap \Magento\Sitemap\Model\Sitemap */
|
107 | 119 | try {
|
| 120 | + $this->appEmulation->startEnvironmentEmulation( |
| 121 | + $sitemap->getStoreId(), |
| 122 | + Area::AREA_FRONTEND, |
| 123 | + true |
| 124 | + ); |
108 | 125 | $sitemap->generateXml();
|
| 126 | + $this->appEmulation->stopEnvironmentEmulation(); |
109 | 127 | } catch (\Exception $e) {
|
110 | 128 | $errors[] = $e->getMessage();
|
111 | 129 | }
|
|
0 commit comments