6
6
*/
7
7
namespace Magento \Sitemap \Controller \Adminhtml \Sitemap ;
8
8
9
+ use Magento \Backend \App \Action ;
10
+ use Magento \Store \Model \App \Emulation ;
11
+ use Magento \Framework \App \ObjectManager ;
12
+
9
13
class Generate extends \Magento \Sitemap \Controller \Adminhtml \Sitemap
10
14
{
15
+ /** @var \Magento\Store\Model\App\Emulation $appEmulation */
16
+ private $ appEmulation ;
17
+
18
+ /**
19
+ * Generate constructor.
20
+ * @param Action\Context $context
21
+ * @param \Magento\Store\Model\App\Emulation|null $appEmulation
22
+ */
23
+ public function __construct (
24
+ Action \Context $ context ,
25
+ Emulation $ appEmulation = null
26
+ ) {
27
+ parent ::__construct ($ context );
28
+ $ this ->appEmulation = $ appEmulation ?: ObjectManager::getInstance ()
29
+ ->get (\Magento \Store \Model \App \Emulation::class);
30
+ }
31
+
11
32
/**
12
33
* Generate sitemap
13
34
*
@@ -23,6 +44,12 @@ public function execute()
23
44
// if sitemap record exists
24
45
if ($ sitemap ->getId ()) {
25
46
try {
47
+ //We need to emulate to get the correct frontend URL for the product images
48
+ $ this ->appEmulation ->startEnvironmentEmulation (
49
+ $ sitemap ->getStoreId (),
50
+ \Magento \Framework \App \Area::AREA_FRONTEND ,
51
+ true
52
+ );
26
53
$ sitemap ->generateXml ();
27
54
28
55
$ this ->messageManager ->addSuccess (
@@ -32,6 +59,8 @@ public function execute()
32
59
$ this ->messageManager ->addError ($ e ->getMessage ());
33
60
} catch (\Exception $ e ) {
34
61
$ this ->messageManager ->addException ($ e , __ ('We can \'t generate the sitemap right now. ' ));
62
+ } finally {
63
+ $ this ->appEmulation ->stopEnvironmentEmulation ();
35
64
}
36
65
} else {
37
66
$ this ->messageManager ->addError (__ ('We can \'t find a sitemap to generate. ' ));
0 commit comments