88
99namespace Magefan \Blog \Model ;
1010
11+ use Magento \Framework \App \ProductMetadataInterface ;
12+ use Magefan \Blog \Api \SitemapConfigInterface ;
13+
1114/**
1215 * Deprecated
1316 * Used for Magento 2.1.x only to create blog_sitemap.xml
@@ -22,32 +25,81 @@ class Sitemap extends \Magento\Sitemap\Model\Sitemap
2225 */
2326 protected function _initSitemapItems ()
2427 {
28+
29+
30+ $ objectManager = \Magento \Framework \App \ObjectManager::getInstance ();
31+
32+ $ megento = $ objectManager ->create (ProductMetadataInterface::class);
33+ $ sitemapConfig = $ objectManager ->create (SitemapConfigInterface::class);
34+
35+
2536 parent ::_initSitemapItems ();
26- $ this ->_sitemapItems = [];
27-
28- $ this ->_sitemapItems [] = new \Magento \Framework \DataObject (
29- [
30- 'changefreq ' => 'weekly ' ,
31- 'priority ' => '0.25 ' ,
32- 'collection ' => \Magento \Framework \App \ObjectManager::getInstance ()->create (
33- \Magefan \Blog \Model \Category::class
34- )->getCollection ($ this ->getStoreId ())
35- ->addStoreFilter ($ this ->getStoreId ())
36- ->addActiveFilter (),
37- ]
38- );
39-
40- $ this ->_sitemapItems [] = new \Magento \Framework \DataObject (
41- [
42- 'changefreq ' => 'weekly ' ,
43- 'priority ' => '0.25 ' ,
44- 'collection ' => \Magento \Framework \App \ObjectManager::getInstance ()->create (
45- \Magefan \Blog \Model \Post::class
46- )->getCollection ($ this ->getStoreId ())
47- ->addStoreFilter ($ this ->getStoreId ())
48- ->addActiveFilter (),
49- ]
50- );
37+
38+ $ sitemapItems = [];
39+ if ($ sitemapConfig ->isEnabledSitemap (SitemapConfigInterface::HOME_PAGE )) {
40+ $ sitemapItems [] = new \Magento \Framework \DataObject (
41+ [
42+ 'changefreq ' => $ sitemapConfig ->getFrequency (SitemapConfigInterface::HOME_PAGE ),
43+ 'priority ' => $ sitemapConfig ->getPriority (SitemapConfigInterface::HOME_PAGE ),
44+ 'collection ' => \Magento \Framework \App \ObjectManager::getInstance ()->create (
45+ \Magento \Framework \Data \Collection::class
46+ )->addItem (
47+ \Magento \Framework \App \ObjectManager::getInstance ()->create (
48+ \Magento \Framework \DataObject::class
49+ )->setData ([
50+ 'updated_at ' => '' ,
51+ 'url ' => '' ,
52+ ])
53+ )
54+ ]
55+ );
56+ }
57+
58+ if ($ sitemapConfig ->isEnabledSitemap (SitemapConfigInterface::CATEGORIES_PAGE )) {
59+ $ sitemapItems [] = new \Magento \Framework \DataObject (
60+ [
61+ 'changefreq ' => $ sitemapConfig ->getFrequency (SitemapConfigInterface::CATEGORIES_PAGE ),
62+ 'priority ' => $ sitemapConfig ->getPriority (SitemapConfigInterface::CATEGORIES_PAGE ),
63+ 'collection ' => \Magento \Framework \App \ObjectManager::getInstance ()->create (
64+ \Magefan \Blog \Model \Category::class
65+ )->getCollection ($ this ->getStoreId ())
66+ ->addStoreFilter ($ this ->getStoreId ())
67+ ->addActiveFilter (),
68+ ]
69+ );
70+ }
71+
72+ if ($ sitemapConfig ->isEnabledSitemap (SitemapConfigInterface::POSTS_PAGE )) {
73+ $ sitemapItems [] = new \Magento \Framework \DataObject (
74+ [
75+ 'changefreq ' => $ sitemapConfig ->getFrequency (SitemapConfigInterface::POSTS_PAGE ),
76+ 'priority ' => $ sitemapConfig ->getPriority (SitemapConfigInterface::POSTS_PAGE ),
77+ 'collection ' => \Magento \Framework \App \ObjectManager::getInstance ()->create (
78+ \Magefan \Blog \Model \Post::class
79+ )->getCollection ($ this ->getStoreId ())
80+ ->addStoreFilter ($ this ->getStoreId ())
81+ ->addActiveFilter (),
82+ ]
83+ );
84+ }
85+
86+ if (version_compare ($ megento ->getVersion (), '2.3.0 ' , '< ' )) {
87+ $ this ->_sitemapItems = $ sitemapItems ;
88+ } else {
89+ $ this ->_sitemapItems = [];
90+ foreach ($ sitemapItems as $ sitemapItem ) {
91+ foreach ($ sitemapItem ->getCollection () as $ item ) {
92+ $ this ->_sitemapItems [] = new \Magento \Framework \DataObject (
93+ [
94+ 'url ' => $ item ->getUrl (),
95+ 'updated_at ' => '' ,
96+ 'priority ' => $ sitemapItem ->getData ('priority ' ),
97+ 'change_frequency ' => $ sitemapItem ->getData ('changefreq ' ),
98+ ]
99+ );
100+ }
101+ }
102+ }
51103 }
52104
53105 /**
0 commit comments