|
7 | 7 | // @codingStandardsIgnoreFile
|
8 | 8 |
|
9 | 9 | namespace Magento\Sitemap\Model;
|
| 10 | + |
10 | 11 | use Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot;
|
11 | 12 | use Magento\Framework\App\ObjectManager;
|
| 13 | +use Magento\Framework\DataObject; |
12 | 14 |
|
13 | 15 | /**
|
14 | 16 | * Sitemap model
|
@@ -225,55 +227,78 @@ protected function _getStream()
|
225 | 227 | }
|
226 | 228 |
|
227 | 229 | /**
|
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 |
229 | 244 | *
|
230 | 245 | * @return void
|
231 | 246 | */
|
232 |
| - protected function _initSitemapItems() |
| 247 | + public function collectSitemapItems() |
233 | 248 | {
|
234 | 249 | /** @var $helper \Magento\Sitemap\Helper\Data */
|
235 | 250 | $helper = $this->_sitemapData;
|
236 | 251 | $storeId = $this->getStoreId();
|
237 | 252 |
|
238 |
| - $this->_sitemapItems[] = new \Magento\Framework\DataObject( |
| 253 | + $this->addSitemapItem(new DataObject( |
239 | 254 | [
|
240 | 255 | 'changefreq' => $helper->getCategoryChangefreq($storeId),
|
241 | 256 | 'priority' => $helper->getCategoryPriority($storeId),
|
242 | 257 | 'collection' => $this->_categoryFactory->create()->getCollection($storeId),
|
243 | 258 | ]
|
244 |
| - ); |
| 259 | + )); |
245 | 260 |
|
246 |
| - $this->_sitemapItems[] = new \Magento\Framework\DataObject( |
| 261 | + $this->addSitemapItem(new DataObject( |
247 | 262 | [
|
248 | 263 | 'changefreq' => $helper->getProductChangefreq($storeId),
|
249 | 264 | 'priority' => $helper->getProductPriority($storeId),
|
250 | 265 | 'collection' => $this->_productFactory->create()->getCollection($storeId),
|
251 | 266 | ]
|
252 |
| - ); |
| 267 | + )); |
253 | 268 |
|
254 |
| - $this->_sitemapItems[] = new \Magento\Framework\DataObject( |
| 269 | + $this->addSitemapItem(new DataObject( |
255 | 270 | [
|
256 | 271 | 'changefreq' => $helper->getPageChangefreq($storeId),
|
257 | 272 | 'priority' => $helper->getPagePriority($storeId),
|
258 | 273 | 'collection' => $this->_cmsFactory->create()->getCollection($storeId),
|
259 | 274 | ]
|
260 |
| - ); |
| 275 | + )); |
| 276 | + } |
| 277 | + |
| 278 | + /** |
| 279 | + * Initialize sitemap |
| 280 | + * |
| 281 | + * @return void |
| 282 | + */ |
| 283 | + protected function _initSitemapItems() |
| 284 | + { |
| 285 | + $this->collectSitemapItems(); |
261 | 286 |
|
262 | 287 | $this->_tags = [
|
263 | 288 | self::TYPE_INDEX => [
|
264 | 289 | 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, |
268 | 293 | self::CLOSE_TAG_KEY => '</sitemapindex>',
|
269 | 294 | ],
|
270 | 295 | self::TYPE_URL => [
|
271 | 296 | 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, |
277 | 302 | self::CLOSE_TAG_KEY => '</urlset>',
|
278 | 303 | ],
|
279 | 304 | ];
|
@@ -341,6 +366,7 @@ public function beforeSave()
|
341 | 366 | public function generateXml()
|
342 | 367 | {
|
343 | 368 | $this->_initSitemapItems();
|
| 369 | + |
344 | 370 | /** @var $sitemapItem \Magento\Framework\DataObject */
|
345 | 371 | foreach ($this->_sitemapItems as $sitemapItem) {
|
346 | 372 | $changefreq = $sitemapItem->getChangefreq();
|
|
0 commit comments