Skip to content

[Forwardport] #15588 Fixed incorrect image urls in multistore xml sitemap #16813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 10, 2018
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