Skip to content

Commit dcd7f39

Browse files
committed
Refactored last sitemap changes
1 parent f0abaa9 commit dcd7f39

File tree

7 files changed

+59
-36
lines changed

7 files changed

+59
-36
lines changed

Api/SitemapConfigInterface.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,30 @@
88

99
namespace Magefan\Blog\Api;
1010

11+
/**
12+
* Interface SitemapConfigInterface
13+
* @package Magefan\Blog\Api
14+
*/
1115
interface SitemapConfigInterface
1216
{
1317
const HOME_PAGE = 'index';
1418
const CATEGORIES_PAGE = 'category';
1519
const POSTS_PAGE = 'post';
20+
1621
/**
17-
* @param $page
22+
* @param string $page
1823
* @return bool
1924
*/
2025
public function isEnabledSitemap($page);
2126

2227
/**
23-
* @param $page
28+
* @param string $page
2429
* @return string
2530
*/
2631
public function getFrequency($page);
2732

2833
/**
29-
* @param $page
34+
* @param string $page
3035
* @return float
3136
*/
3237
public function getPriority($page);

Model/Post.php

+9
Original file line numberDiff line numberDiff line change
@@ -926,4 +926,13 @@ public function getSecret()
926926

927927
return $this->getData('secret');
928928
}
929+
930+
/**
931+
* Retrieve updated at time
932+
* @return mixed
933+
*/
934+
public function getUpdatedAt()
935+
{
936+
return $this->getData('update_time');
937+
}
929938
}

Model/Sitemap.php

+6-10
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,10 @@ class Sitemap extends \Magento\Sitemap\Model\Sitemap
2525
*/
2626
protected function _initSitemapItems()
2727
{
28-
28+
parent::_initSitemapItems();
2929

3030
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
31-
32-
$megento = $objectManager->create(ProductMetadataInterface::class);
33-
$sitemapConfig = $objectManager->create(SitemapConfigInterface::class);
34-
35-
36-
parent::_initSitemapItems();
31+
$sitemapConfig = $objectManager->get(SitemapConfigInterface::class);
3732

3833
$sitemapItems = [];
3934
if ($sitemapConfig->isEnabledSitemap(SitemapConfigInterface::HOME_PAGE)) {
@@ -48,7 +43,7 @@ protected function _initSitemapItems()
4843
\Magento\Framework\DataObject::class
4944
)->setData([
5045
'updated_at' => '',
51-
'url' => '',
46+
'url' => $objectManager->get(\Magefan\Blog\Model\Url::class)->getBasePath(),
5247
])
5348
)
5449
]
@@ -83,7 +78,8 @@ protected function _initSitemapItems()
8378
);
8479
}
8580

86-
if (version_compare($megento->getVersion(), '2.3.0', '<')) {
81+
$productMetadata = $objectManager->get(ProductMetadataInterface::class);
82+
if (version_compare($productMetadata->getVersion(), '2.3.0', '<')) {
8783
$this->_sitemapItems = $sitemapItems;
8884
} else {
8985
$this->_sitemapItems = [];
@@ -92,7 +88,7 @@ protected function _initSitemapItems()
9288
$this->_sitemapItems[] = new \Magento\Framework\DataObject(
9389
[
9490
'url' => $item->getUrl(),
95-
'updated_at' => '',
91+
'updated_at' => $item->getData('update_time'),
9692
'priority' => $sitemapItem->getData('priority'),
9793
'change_frequency' => $sitemapItem->getData('changefreq'),
9894
]

Model/Sitemap/SitemapConfig.php

+13-11
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010

1111
use Magefan\Blog\Api\SitemapConfigInterface;
1212

13+
/**
14+
* Class SitemapConfig
15+
* @package Magefan\Blog\Model\Sitemap
16+
*/
1317
class SitemapConfig implements SitemapConfigInterface
1418
{
15-
1619
/**
17-
* @param $page
20+
* @param string $page
1821
* @return bool
1922
*/
2023
public function isEnabledSitemap($page)
@@ -23,46 +26,45 @@ public function isEnabledSitemap($page)
2326
}
2427

2528
/**
26-
* @param $page
29+
* @param string $page
2730
* @return string
2831
*/
2932
public function getFrequency($page)
3033
{
3134
switch ($page) {
3235
case 'index':
33-
$frequency = 'Dailly';
36+
$frequency = 'daily';
3437
break;
3538
case 'category':
36-
$frequency = 'Dailly';
39+
$frequency = 'daily';
3740
break;
3841
case 'post':
39-
$frequency = 'Dailly';
42+
$frequency = 'daily';
4043
break;
4144
default:
42-
$frequency = 'Dailly';
45+
$frequency = 'daily';
4346
}
4447
return $frequency;
4548
}
4649

4750
/**
48-
* @param $page
51+
* @param string $page
4952
* @return float
5053
*/
5154
public function getPriority($page)
5255
{
53-
5456
switch ($page) {
5557
case 'index':
5658
$priority = 1;
5759
break;
5860
case 'category':
59-
$priority = 0.75;
61+
$priority = 0.8;
6062
break;
6163
case 'post':
6264
$priority = 0.5;
6365
break;
6466
default:
65-
$priority = 0.25;
67+
$priority = 0.3;
6668
}
6769
return $priority;
6870
}

Model/Url.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function getControllerName($route, $skip = true)
137137
*/
138138
public function getBaseUrl()
139139
{
140-
$url = $this->_url->getUrl($this->getRoute());
140+
$url = $this->_url->getUrl($this->getBasePath());
141141
$url = $this->trimSlash($url);
142142
return $url;
143143
}
@@ -204,6 +204,14 @@ public function getCanonicalUrl(\Magento\Framework\Model\AbstractModel $object)
204204
return $url;
205205
}
206206

207+
/**
208+
* Retrieve blog base path
209+
* @return string
210+
*/
211+
public function getBasePath()
212+
{
213+
return $this->getRoute();
214+
}
207215

208216
/**
209217
* Retrieve blog url path

Plugin/Magento/Sitemap/SitemapPlugin.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,21 @@ public function afterGenerateXml(\Magento\Framework\Model\AbstractModel $sitemap
9292
);
9393

9494
$blogSitemap->generateXml();
95-
/*}*/
95+
/* } */
9696
}
9797
return $result;
9898
}
9999

100100
/**
101+
* Deprecated
101102
* @param \Magento\Framework\Model\AbstractModel $sitemap
102103
* @param $result
103104
* @return mixed
104105
*/
105-
/* Deprecated
106106
public function afterCollectSitemapItems(\Magento\Framework\Model\AbstractModel $sitemap, $result)
107107
{
108+
return $result;
109+
/*
108110
if ($this->isEnabled($sitemap) && !$this->isMageWorxXmlSitemap($sitemap)) {
109111
$storeId = $sitemap->getStoreId();
110112
@@ -132,8 +134,8 @@ public function afterCollectSitemapItems(\Magento\Framework\Model\AbstractModel
132134
}
133135
134136
return $result;
137+
*/
135138
}
136-
*/
137139

138140
/**
139141
* @param $sitemap
@@ -147,6 +149,7 @@ protected function isEnabled($sitemap)
147149
}
148150

149151
/**
152+
* Deprecated
150153
* @param $sitemap
151154
* @return mixed
152155
*/

etc/adminhtml/system.xml

+8-8
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,12 @@
372372
<label>Permalink Settings</label>
373373
<field id="route" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
374374
<label>Blog Route</label>
375-
<comment>E.g.: "blog" will make the blog accessible from mystore.com/blog/</comment>
375+
<comment>E.g.: "blog" will make the blog accessible from mystore.com/blog</comment>
376376
</field>
377377
<field id="redirect_to_no_slash" translate="label" type="select" sortOrder="12" showInDefault="1" showInWebsite="1" showInStore="1">
378378
<label>Auto-redirect to No-Slash URL</label>
379379
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
380-
<comment><![CDATA[I.e. redirect from <b>http://example.com/blog/</b> to <b>http://example.com/blog</b>]]></comment>
380+
<comment><![CDATA[E.g. auto 301 redirect from <b>http://example.com/blog/</b> to <b>http://example.com/blog</b>]]></comment>
381381
</field>
382382
<field id="type" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
383383
<label>Permalink Type</label>
@@ -389,7 +389,7 @@
389389
<depends>
390390
<field id="type">default</field>
391391
</depends>
392-
<comment>E.g.: "post" will make the blog post accessible from mystore.com/{blog_route}/post/post-identifier/</comment>
392+
<comment>E.g.: "post" will make the blog post accessible from mystore.com/{blog_route}/post/post-identifier</comment>
393393
</field>
394394
<field id="post_sufix" translate="label comment" type="text" sortOrder="35" showInDefault="1" showInWebsite="1" showInStore="1">
395395
<label>Post URL Suffix</label>
@@ -404,7 +404,7 @@
404404
<depends>
405405
<field id="type">default</field>
406406
</depends>
407-
<comment>E.g.: "category" will make the blog category accessible from mystore.com/{blog_route}/category/category-identifier/</comment>
407+
<comment>E.g.: "category" will make the blog category accessible from mystore.com/{blog_route}/category/category-identifier</comment>
408408
</field>
409409
<field id="category_sufix" translate="label comment" type="text" sortOrder="45" showInDefault="1" showInWebsite="1" showInStore="1">
410410
<label>Category URL Suffix</label>
@@ -419,27 +419,27 @@
419419
<depends>
420420
<field id="type">default</field>
421421
</depends>
422-
<comment>E.g.: "archive" will make the blog archive accessible from mystore.com/{blog_route}/archive/2016-02/</comment>
422+
<comment>E.g.: "archive" will make the blog archive accessible from mystore.com/{blog_route}/archive/2016-02</comment>
423423
</field>
424424
<field id="tag_route" translate="label comment" type="text" sortOrder="55" showInDefault="1" showInWebsite="1" showInStore="1">
425425
<label>Tag Route</label>
426-
<comment>E.g.: "tag" will make the blog posts by tag accessible from mystore.com/{blog_route}/tag/tag-name/</comment>
426+
<comment>E.g.: "tag" will make the blog posts by tag accessible from mystore.com/{blog_route}/tag/tag-name</comment>
427427
</field>
428428
<field id="tag_sufix" translate="label comment" type="text" sortOrder="56" showInDefault="1" showInWebsite="1" showInStore="1">
429429
<label>Tag URL Suffix</label>
430430
<comment>E.g.: ".html" will make the blog tag accessible from mystore.com/{blog_route}/tag/tag-name.html</comment>
431431
</field>
432432
<field id="author_route" translate="label comment" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
433433
<label>Author Route</label>
434-
<comment>E.g.: "author" will make the blog author posts accessible from mystore.com/{blog_route}/author/author-name/</comment>
434+
<comment>E.g.: "author" will make the blog author posts accessible from mystore.com/{blog_route}/author/author-name</comment>
435435
</field>
436436
<field id="author_sufix" translate="label comment" type="text" sortOrder="61" showInDefault="1" showInWebsite="1" showInStore="1">
437437
<label>Author URL Suffix</label>
438438
<comment>E.g.: ".html" will make the blog author accessible from mystore.com/{blog_route}/author/author-name.html</comment>
439439
</field>
440440
<field id="search_route" translate="label comment" type="text" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1">
441441
<label>Search Route</label>
442-
<comment>E.g.: "search" will make the blog search accessible from mystore.com/{blog_route}/search/query/</comment>
442+
<comment>E.g.: "search" will make the blog search accessible from mystore.com/{blog_route}/search/query</comment>
443443
</field>
444444
</group>
445445
<group id="seo" translate="label" type="text" sortOrder="90" showInDefault="1" showInWebsite="1" showInStore="1">

0 commit comments

Comments
 (0)