Skip to content

Commit 3cfa32b

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1228 from magento-engcom/develop-prs
Public Pull Requests: #9970
2 parents d6efc8e + 1a36824 commit 3cfa32b

File tree

1 file changed

+42
-16
lines changed

1 file changed

+42
-16
lines changed

app/code/Magento/Sitemap/Model/Sitemap.php

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
// @codingStandardsIgnoreFile
88

99
namespace Magento\Sitemap\Model;
10+
1011
use Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot;
1112
use Magento\Framework\App\ObjectManager;
13+
use Magento\Framework\DataObject;
1214

1315
/**
1416
* Sitemap model
@@ -225,55 +227,78 @@ protected function _getStream()
225227
}
226228

227229
/**
228-
* Initialize sitemap items
230+
* Add a sitemap item to the array of sitemap items
231+
*
232+
* @param DataObject $sitemapItem
233+
* @return $this
234+
*/
235+
public function addSitemapItem(DataObject $sitemapItem)
236+
{
237+
$this->_sitemapItems[] = $sitemapItem;
238+
239+
return $this;
240+
}
241+
242+
/**
243+
* Collect all sitemap items
229244
*
230245
* @return void
231246
*/
232-
protected function _initSitemapItems()
247+
public function collectSitemapItems()
233248
{
234249
/** @var $helper \Magento\Sitemap\Helper\Data */
235250
$helper = $this->_sitemapData;
236251
$storeId = $this->getStoreId();
237252

238-
$this->_sitemapItems[] = new \Magento\Framework\DataObject(
253+
$this->addSitemapItem(new DataObject(
239254
[
240255
'changefreq' => $helper->getCategoryChangefreq($storeId),
241256
'priority' => $helper->getCategoryPriority($storeId),
242257
'collection' => $this->_categoryFactory->create()->getCollection($storeId),
243258
]
244-
);
259+
));
245260

246-
$this->_sitemapItems[] = new \Magento\Framework\DataObject(
261+
$this->addSitemapItem(new DataObject(
247262
[
248263
'changefreq' => $helper->getProductChangefreq($storeId),
249264
'priority' => $helper->getProductPriority($storeId),
250265
'collection' => $this->_productFactory->create()->getCollection($storeId),
251266
]
252-
);
267+
));
253268

254-
$this->_sitemapItems[] = new \Magento\Framework\DataObject(
269+
$this->addSitemapItem(new DataObject(
255270
[
256271
'changefreq' => $helper->getPageChangefreq($storeId),
257272
'priority' => $helper->getPagePriority($storeId),
258273
'collection' => $this->_cmsFactory->create()->getCollection($storeId),
259274
]
260-
);
275+
));
276+
}
277+
278+
/**
279+
* Initialize sitemap
280+
*
281+
* @return void
282+
*/
283+
protected function _initSitemapItems()
284+
{
285+
$this->collectSitemapItems();
261286

262287
$this->_tags = [
263288
self::TYPE_INDEX => [
264289
self::OPEN_TAG_KEY => '<?xml version="1.0" encoding="UTF-8"?>' .
265-
PHP_EOL .
266-
'<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' .
267-
PHP_EOL,
290+
PHP_EOL .
291+
'<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' .
292+
PHP_EOL,
268293
self::CLOSE_TAG_KEY => '</sitemapindex>',
269294
],
270295
self::TYPE_URL => [
271296
self::OPEN_TAG_KEY => '<?xml version="1.0" encoding="UTF-8"?>' .
272-
PHP_EOL .
273-
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' .
274-
' xmlns:content="http://www.google.com/schemas/sitemap-content/1.0"' .
275-
' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">' .
276-
PHP_EOL,
297+
PHP_EOL .
298+
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' .
299+
' xmlns:content="http://www.google.com/schemas/sitemap-content/1.0"' .
300+
' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">' .
301+
PHP_EOL,
277302
self::CLOSE_TAG_KEY => '</urlset>',
278303
],
279304
];
@@ -341,6 +366,7 @@ public function beforeSave()
341366
public function generateXml()
342367
{
343368
$this->_initSitemapItems();
369+
344370
/** @var $sitemapItem \Magento\Framework\DataObject */
345371
foreach ($this->_sitemapItems as $sitemapItem) {
346372
$changefreq = $sitemapItem->getChangefreq();

0 commit comments

Comments
 (0)