Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,29 @@
*/
namespace Magento\Sitemap\Controller\Adminhtml\Sitemap;

use Magento\Backend\App\Action;
use Magento\Store\Model\App\Emulation;
use Magento\Framework\App\ObjectManager;

class Generate extends \Magento\Sitemap\Controller\Adminhtml\Sitemap
{
/** @var \Magento\Store\Model\App\Emulation $appEmulation */
private $appEmulation;

/**
* Generate constructor.
* @param Action\Context $context
* @param \Magento\Store\Model\App\Emulation|null $appEmulation
*/
public function __construct(
Action\Context $context,
Emulation $appEmulation = null
) {
parent::__construct($context);
$this->appEmulation = $appEmulation ?: ObjectManager::getInstance()
->get(\Magento\Store\Model\App\Emulation::class);
}

/**
* Generate sitemap
*
Expand All @@ -23,6 +44,12 @@ public function execute()
// if sitemap record exists
if ($sitemap->getId()) {
try {
//We need to emulate to get the correct frontend URL for the product images
$this->appEmulation->startEnvironmentEmulation(
$sitemap->getStoreId(),
\Magento\Framework\App\Area::AREA_FRONTEND,
true
);
$sitemap->generateXml();

$this->messageManager->addSuccess(
Expand All @@ -32,6 +59,8 @@ public function execute()
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addException($e, __('We can\'t generate the sitemap right now.'));
} finally {
$this->appEmulation->stopEnvironmentEmulation();
}
} else {
$this->messageManager->addError(__('We can\'t find a sitemap to generate.'));
Expand Down