Skip to content

Commit

Permalink
ENGCOM-1866: #15588 Fixed incorrect image urls in multistore xml site…
Browse files Browse the repository at this point in the history
…map #15689

 - Merge Pull Request #15689 from StevenGuapaBV/magento2:2.2-develop
 - Merged commits:
   1. 7b8fe3d
   2. 498047c
   3. 63ed864
   4. 83ad777
   5. 6a490a8
   6. f1dd4e8
   7. b7f8d28
  • Loading branch information
magento-engcom-team committed Jun 6, 2018
2 parents 10f84fd + b7f8d28 commit ec41e34
Showing 1 changed file with 29 additions and 0 deletions.
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

0 comments on commit ec41e34

Please sign in to comment.