66 */
77namespace Magento \Sitemap \Controller \Adminhtml \Sitemap ;
88
9+ use Magento \Backend \App \Action ;
10+ use Magento \Store \Model \App \Emulation ;
11+ use Magento \Framework \App \ObjectManager ;
12+
913class Generate extends \Magento \Sitemap \Controller \Adminhtml \Sitemap
1014{
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+
1132 /**
1233 * Generate sitemap
1334 *
@@ -23,6 +44,12 @@ public function execute()
2344 // if sitemap record exists
2445 if ($ sitemap ->getId ()) {
2546 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+ );
2653 $ sitemap ->generateXml ();
2754
2855 $ this ->messageManager ->addSuccess (
@@ -32,6 +59,8 @@ public function execute()
3259 $ this ->messageManager ->addError ($ e ->getMessage ());
3360 } catch (\Exception $ e ) {
3461 $ this ->messageManager ->addException ($ e , __ ('We can \'t generate the sitemap right now. ' ));
62+ } finally {
63+ $ this ->appEmulation ->stopEnvironmentEmulation ();
3564 }
3665 } else {
3766 $ this ->messageManager ->addError (__ ('We can \'t find a sitemap to generate. ' ));
0 commit comments