Skip to content

Commit

Permalink
Merge pull request #1228 from magento-engcom/develop-prs
Browse files Browse the repository at this point in the history
Public Pull Requests:
#9970
  • Loading branch information
Oleksii Korshenko authored Jun 24, 2017
2 parents d6efc8e + 1a36824 commit 3cfa32b
Showing 1 changed file with 42 additions and 16 deletions.
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

0 comments on commit 3cfa32b

Please sign in to comment.