Skip to content

Commit 7b8fe3d

Browse files
Added the appEmulation to get the correct image Url for the generated sitemaps. Context had incorrect Url data.
1 parent 20474b1 commit 7b8fe3d

File tree

1 file changed

+27
-0
lines changed
  • app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap

1 file changed

+27
-0
lines changed

app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,29 @@
66
*/
77
namespace Magento\Sitemap\Controller\Adminhtml\Sitemap;
88

9+
use Magento\Backend\App\Action;
10+
use Magento\Store\Model\App\Emulation;
11+
912
class Generate extends \Magento\Sitemap\Controller\Adminhtml\Sitemap
1013
{
14+
/** @var \Magento\Store\Model\App\Emulation $appEmulation */
15+
private $appEmulation;
16+
17+
/**
18+
* Generate constructor.
19+
* @param Action\Context $context
20+
* @param \Magento\Store\Model\App\Emulation $appEmulation
21+
*/
22+
public function __construct(
23+
Action\Context $context,
24+
Emulation $appEmulation
25+
) {
26+
$this->appEmulation = $appEmulation;
27+
parent::__construct(
28+
$context
29+
);
30+
}
31+
1132
/**
1233
* Generate sitemap
1334
*
@@ -23,7 +44,13 @@ 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($sitemap->getStoreId(),
49+
\Magento\Framework\App\Area::AREA_FRONTEND,
50+
true
51+
);
2652
$sitemap->generateXml();
53+
$this->appEmulation->stopEnvironmentEmulation();
2754

2855
$this->messageManager->addSuccess(
2956
__('The sitemap "%1" has been generated.', $sitemap->getSitemapFilename())

0 commit comments

Comments
 (0)