Skip to content

Commit d5b0ffd

Browse files
committed
fix issue-19596 Images in XML sitemap
1 parent 2a389b0 commit d5b0ffd

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

app/code/Magento/Sitemap/Model/Observer.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Sitemap\Model;
77

8+
use Magento\Store\Model\App\Emulation;
9+
use Magento\Framework\App\ObjectManager;
810
/**
911
* Sitemap module observer
1012
*
@@ -67,13 +69,21 @@ class Observer
6769
protected $inlineTranslation;
6870

6971
/**
72+
* @var \Magento\Store\Model\App\Emulation $appEmulation
73+
*/
74+
protected $appEmulation;
75+
76+
/**
77+
* Observer constructor.
78+
* @param Emulation|null $appEmulation
7079
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
71-
* @param \Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory $collectionFactory
80+
* @param ResourceModel\Sitemap\CollectionFactory $collectionFactory
7281
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
7382
* @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
7483
* @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
7584
*/
7685
public function __construct(
86+
Emulation $appEmulation = null,
7787
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
7888
\Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory $collectionFactory,
7989
\Magento\Store\Model\StoreManagerInterface $storeManager,
@@ -85,6 +95,8 @@ public function __construct(
8595
$this->_storeManager = $storeManager;
8696
$this->_transportBuilder = $transportBuilder;
8797
$this->inlineTranslation = $inlineTranslation;
98+
$this->appEmulation = $appEmulation ?: ObjectManager::getInstance()
99+
->get(\Magento\Store\Model\App\Emulation::class);
88100
}
89101

90102
/**
@@ -112,10 +124,20 @@ public function scheduledGenerateSitemaps()
112124
foreach ($collection as $sitemap) {
113125
/* @var $sitemap \Magento\Sitemap\Model\Sitemap */
114126
try {
127+
128+
$this->appEmulation->startEnvironmentEmulation(
129+
$sitemap->getStoreId(),
130+
\Magento\Framework\App\Area::AREA_FRONTEND,
131+
true
132+
);
133+
115134
$sitemap->generateXml();
116135
} catch (\Exception $e) {
117136
$errors[] = $e->getMessage();
137+
} finally {
138+
$this->appEmulation->stopEnvironmentEmulation();
118139
}
140+
119141
}
120142

121143
if ($errors && $this->_scopeConfig->getValue(

0 commit comments

Comments
 (0)