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

Added public methods to make Sitemap model plugin friendly #9970

Merged
merged 1 commit into from
Jun 24, 2017
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
58 changes: 42 additions & 16 deletions app/code/Magento/Sitemap/Model/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
// @codingStandardsIgnoreFile

namespace Magento\Sitemap\Model;

use Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DataObject;

/**
* Sitemap model
Expand Down Expand Up @@ -225,55 +227,78 @@ protected function _getStream()
}

/**
* Initialize sitemap items
* Add a sitemap item to the array of sitemap items
*
* @param DataObject $sitemapItem
* @return $this
*/
public function addSitemapItem(DataObject $sitemapItem)
{
$this->_sitemapItems[] = $sitemapItem;

return $this;
}

/**
* Collect all sitemap items
*
* @return void
*/
protected function _initSitemapItems()
public function collectSitemapItems()
{
/** @var $helper \Magento\Sitemap\Helper\Data */
$helper = $this->_sitemapData;
$storeId = $this->getStoreId();

$this->_sitemapItems[] = new \Magento\Framework\DataObject(
$this->addSitemapItem(new DataObject(
[
'changefreq' => $helper->getCategoryChangefreq($storeId),
'priority' => $helper->getCategoryPriority($storeId),
'collection' => $this->_categoryFactory->create()->getCollection($storeId),
]
);
));

$this->_sitemapItems[] = new \Magento\Framework\DataObject(
$this->addSitemapItem(new DataObject(
[
'changefreq' => $helper->getProductChangefreq($storeId),
'priority' => $helper->getProductPriority($storeId),
'collection' => $this->_productFactory->create()->getCollection($storeId),
]
);
));

$this->_sitemapItems[] = new \Magento\Framework\DataObject(
$this->addSitemapItem(new DataObject(
[
'changefreq' => $helper->getPageChangefreq($storeId),
'priority' => $helper->getPagePriority($storeId),
'collection' => $this->_cmsFactory->create()->getCollection($storeId),
]
);
));
}

/**
* Initialize sitemap
*
* @return void
*/
protected function _initSitemapItems()
{
$this->collectSitemapItems();

$this->_tags = [
self::TYPE_INDEX => [
self::OPEN_TAG_KEY => '<?xml version="1.0" encoding="UTF-8"?>' .
PHP_EOL .
'<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' .
PHP_EOL,
PHP_EOL .
'<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' .
PHP_EOL,
self::CLOSE_TAG_KEY => '</sitemapindex>',
],
self::TYPE_URL => [
self::OPEN_TAG_KEY => '<?xml version="1.0" encoding="UTF-8"?>' .
PHP_EOL .
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' .
' xmlns:content="http://www.google.com/schemas/sitemap-content/1.0"' .
' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">' .
PHP_EOL,
PHP_EOL .
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' .
' xmlns:content="http://www.google.com/schemas/sitemap-content/1.0"' .
' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">' .
PHP_EOL,
self::CLOSE_TAG_KEY => '</urlset>',
],
];
Expand Down Expand Up @@ -341,6 +366,7 @@ public function beforeSave()
public function generateXml()
{
$this->_initSitemapItems();

/** @var $sitemapItem \Magento\Framework\DataObject */
foreach ($this->_sitemapItems as $sitemapItem) {
$changefreq = $sitemapItem->getChangefreq();
Expand Down