Skip to content
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

Images in XML sitemap are always linked to base store in multistore on Schedule #19598

Merged
merged 9 commits into from
Feb 13, 2019
24 changes: 23 additions & 1 deletion app/code/Magento/Sitemap/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Sitemap\Model;

use Magento\Store\Model\App\Emulation;
use Magento\Framework\App\ObjectManager;
/**
Nazar65 marked this conversation as resolved.
Show resolved Hide resolved
* Sitemap module observer
*
Expand Down Expand Up @@ -67,13 +69,21 @@ class Observer
protected $inlineTranslation;

/**
* @var \Magento\Store\Model\App\Emulation $appEmulation
Nazar65 marked this conversation as resolved.
Show resolved Hide resolved
*/
protected $appEmulation;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change the access level to private

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


/**
* Observer constructor.
* @param Emulation|null $appEmulation
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory $collectionFactory
* @param ResourceModel\Sitemap\CollectionFactory $collectionFactory
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
* @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
*/
public function __construct(
Emulation $appEmulation = null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add move the new parameter to the last position in the parameters list

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory $collectionFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
Expand All @@ -85,6 +95,8 @@ public function __construct(
$this->_storeManager = $storeManager;
$this->_transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->appEmulation = $appEmulation ?: ObjectManager::getInstance()
->get(\Magento\Store\Model\App\Emulation::class);
}

/**
Expand Down Expand Up @@ -112,10 +124,20 @@ 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 && $this->_scopeConfig->getValue(
Expand Down