diff --git a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php index 9592ab6f57c55..c8e2d356b3ffb 100644 --- a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php +++ b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php @@ -7,10 +7,15 @@ namespace Magento\Sitemap\Controller\Adminhtml\Sitemap; use Magento\Backend\App\Action; +use Magento\Framework\App\Action\HttpGetActionInterface; +use Magento\Sitemap\Controller\Adminhtml\Sitemap; use Magento\Store\Model\App\Emulation; use Magento\Framework\App\ObjectManager; -class Generate extends \Magento\Sitemap\Controller\Adminhtml\Sitemap +/** + * Generate sitemap file + */ +class Generate extends Sitemap implements HttpGetActionInterface { /** @var \Magento\Store\Model\App\Emulation $appEmulation */ private $appEmulation; @@ -44,14 +49,7 @@ 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->addSuccessMessage( __('The sitemap "%1" has been generated.', $sitemap->getSitemapFilename()) ); @@ -59,8 +57,6 @@ public function execute() $this->messageManager->addErrorMessage($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addExceptionMessage($e, __('We can\'t generate the sitemap right now.')); - } finally { - $this->appEmulation->stopEnvironmentEmulation(); } } else { $this->messageManager->addErrorMessage(__('We can\'t find a sitemap to generate.')); diff --git a/app/code/Magento/Sitemap/Model/Observer.php b/app/code/Magento/Sitemap/Model/Observer.php index bd7a84f601b77..ce74d738c4bc3 100644 --- a/app/code/Magento/Sitemap/Model/Observer.php +++ b/app/code/Magento/Sitemap/Model/Observer.php @@ -5,7 +5,6 @@ */ namespace Magento\Sitemap\Model; -use Magento\Store\Model\App\Emulation; use Magento\Sitemap\Model\EmailNotification as SitemapEmail; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory; @@ -57,11 +56,6 @@ class Observer */ private $collectionFactory; - /** - * @var Emulation - */ - private $appEmulation; - /** * @var $emailNotification */ @@ -72,17 +66,14 @@ class Observer * @param ScopeConfigInterface $scopeConfig * @param CollectionFactory $collectionFactory * @param EmailNotification $emailNotification - * @param Emulation $appEmulation */ public function __construct( ScopeConfigInterface $scopeConfig, CollectionFactory $collectionFactory, - SitemapEmail $emailNotification, - Emulation $appEmulation + SitemapEmail $emailNotification ) { $this->scopeConfig = $scopeConfig; $this->collectionFactory = $collectionFactory; - $this->appEmulation = $appEmulation; $this->emailNotification = $emailNotification; } @@ -114,17 +105,9 @@ public function scheduledGenerateSitemaps() foreach ($collection as $sitemap) { /* @var $sitemap \Magento\Sitemap\Model\Sitemap */ try { - $this->appEmulation->startEnvironmentEmulation( - $sitemap->getStoreId(), - \Magento\Framework\App\Area::AREA_FRONTEND, - true - ); - $sitemap->generateXml(); } catch (\Exception $e) { $errors[] = $e->getMessage(); - } finally { - $this->appEmulation->stopEnvironmentEmulation(); } } if ($errors && $recipient) { diff --git a/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php b/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php index 82024b3b015e5..4d678f5c1cb94 100644 --- a/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php +++ b/app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php @@ -389,6 +389,7 @@ protected function _prepareProduct(array $productRow, $storeId) */ protected function _loadProductImages($product, $storeId) { + $this->_storeManager->setCurrentStore($storeId); /** @var $helper \Magento\Sitemap\Helper\Data */ $helper = $this->_sitemapData; $imageIncludePolicy = $helper->getProductImageIncludePolicy($storeId); diff --git a/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php b/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php index 5fae54ff3c5d0..09f5418bbd762 100644 --- a/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php +++ b/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php @@ -118,7 +118,7 @@ public function testScheduledGenerateSitemapsSendsExceptionEmail() ->method('getStoreId') ->willReturn($storeId); - $this->sitemapMock->expects($this->at(1)) + $this->sitemapMock->expects($this->once()) ->method('generateXml') ->willThrowException(new \Exception($exception)); @@ -130,17 +130,6 @@ public function testScheduledGenerateSitemapsSendsExceptionEmail() ) ->willReturn('error-recipient@example.com'); - $this->appEmulationMock->expects($this->at(0)) - ->method('startEnvironmentEmulation') - ->with( - $storeId, - Area::AREA_FRONTEND, - true - ); - - $this->appEmulationMock->expects($this->at(1)) - ->method('stopEnvironmentEmulation'); - $this->observer->scheduledGenerateSitemaps(); } }