5
5
*/
6
6
namespace Magento \Sitemap \Model ;
7
7
8
+ use Magento \Store \Model \App \Emulation ;
9
+ use Magento \Framework \App \ObjectManager ;
8
10
/**
9
11
* Sitemap module observer
10
12
*
@@ -67,13 +69,21 @@ class Observer
67
69
protected $ inlineTranslation ;
68
70
69
71
/**
72
+ * @var \Magento\Store\Model\App\Emulation $appEmulation
73
+ */
74
+ protected $ appEmulation ;
75
+
76
+ /**
77
+ * Observer constructor.
78
+ * @param Emulation|null $appEmulation
70
79
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
71
- * @param \Magento\Sitemap\Model\ ResourceModel\Sitemap\CollectionFactory $collectionFactory
80
+ * @param ResourceModel\Sitemap\CollectionFactory $collectionFactory
72
81
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
73
82
* @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
74
83
* @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
75
84
*/
76
85
public function __construct (
86
+ Emulation $ appEmulation = null ,
77
87
\Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
78
88
\Magento \Sitemap \Model \ResourceModel \Sitemap \CollectionFactory $ collectionFactory ,
79
89
\Magento \Store \Model \StoreManagerInterface $ storeManager ,
@@ -85,6 +95,8 @@ public function __construct(
85
95
$ this ->_storeManager = $ storeManager ;
86
96
$ this ->_transportBuilder = $ transportBuilder ;
87
97
$ this ->inlineTranslation = $ inlineTranslation ;
98
+ $ this ->appEmulation = $ appEmulation ?: ObjectManager::getInstance ()
99
+ ->get (\Magento \Store \Model \App \Emulation::class);
88
100
}
89
101
90
102
/**
@@ -112,10 +124,20 @@ public function scheduledGenerateSitemaps()
112
124
foreach ($ collection as $ sitemap ) {
113
125
/* @var $sitemap \Magento\Sitemap\Model\Sitemap */
114
126
try {
127
+
128
+ $ this ->appEmulation ->startEnvironmentEmulation (
129
+ $ sitemap ->getStoreId (),
130
+ \Magento \Framework \App \Area::AREA_FRONTEND ,
131
+ true
132
+ );
133
+
115
134
$ sitemap ->generateXml ();
116
135
} catch (\Exception $ e ) {
117
136
$ errors [] = $ e ->getMessage ();
137
+ } finally {
138
+ $ this ->appEmulation ->stopEnvironmentEmulation ();
118
139
}
140
+
119
141
}
120
142
121
143
if ($ errors && $ this ->_scopeConfig ->getValue (
0 commit comments