11
11
use Magento \Robots \Model \Config \Value ;
12
12
use Magento \Sitemap \Helper \Data as SitemapHelper ;
13
13
use Magento \Sitemap \Model \ResourceModel \Sitemap \CollectionFactory ;
14
+ use Magento \Sitemap \Model \SitemapConfigReader ;
15
+ use Magento \Framework \App \ObjectManager ;
14
16
use Magento \Store \Model \StoreManagerInterface ;
15
17
use Magento \Store \Model \StoreResolver ;
16
18
@@ -29,6 +31,7 @@ class Robots extends AbstractBlock implements IdentityInterface
29
31
30
32
/**
31
33
* @var SitemapHelper
34
+ * @deprecated
32
35
*/
33
36
private $ sitemapHelper ;
34
37
@@ -37,14 +40,19 @@ class Robots extends AbstractBlock implements IdentityInterface
37
40
*/
38
41
private $ storeManager ;
39
42
43
+ /**
44
+ * @var SitemapConfigReader
45
+ */
46
+ private $ sitemapConfigReader ;
47
+
40
48
/**
41
49
* @param Context $context
42
50
* @param StoreResolver $storeResolver
43
51
* @param CollectionFactory $sitemapCollectionFactory
44
52
* @param SitemapHelper $sitemapHelper
45
53
* @param StoreManagerInterface $storeManager
46
54
* @param array $data
47
- *
55
+ * @param SitemapConfigReader|null $sitemapConfigReader
48
56
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
49
57
*/
50
58
public function __construct (
@@ -53,11 +61,14 @@ public function __construct(
53
61
CollectionFactory $ sitemapCollectionFactory ,
54
62
SitemapHelper $ sitemapHelper ,
55
63
StoreManagerInterface $ storeManager ,
56
- array $ data = []
64
+ array $ data = [],
65
+ ?SitemapConfigReader $ sitemapConfigReader = null
57
66
) {
58
67
$ this ->sitemapCollectionFactory = $ sitemapCollectionFactory ;
59
68
$ this ->sitemapHelper = $ sitemapHelper ;
60
69
$ this ->storeManager = $ storeManager ;
70
+ $ this ->sitemapConfigReader = $ sitemapConfigReader
71
+ ?: ObjectManager::getInstance ()->get (SitemapConfigReader::class);
61
72
62
73
parent ::__construct ($ context , $ data );
63
74
}
@@ -74,22 +85,16 @@ public function __construct(
74
85
*/
75
86
protected function _toHtml ()
76
87
{
77
- $ defaultStore = $ this ->storeManager ->getDefaultStoreView ();
78
-
79
- /** @var \Magento\Store\Model\Website $website */
80
- $ website = $ this ->storeManager ->getWebsite ($ defaultStore ->getWebsiteId ());
88
+ $ website = $ this ->storeManager ->getWebsite ();
81
89
82
90
$ storeIds = [];
83
91
foreach ($ website ->getStoreIds () as $ storeId ) {
84
- if ((bool )$ this ->sitemapHelper ->getEnableSubmissionRobots ($ storeId )) {
85
- $ storeIds [] = (int )$ storeId ;
92
+ if ((bool ) $ this ->sitemapConfigReader ->getEnableSubmissionRobots ($ storeId )) {
93
+ $ storeIds [] = (int ) $ storeId ;
86
94
}
87
95
}
88
96
89
- $ links = [];
90
- if ($ storeIds ) {
91
- $ links = array_merge ($ links , $ this ->getSitemapLinks ($ storeIds ));
92
- }
97
+ $ links = $ storeIds ? $ this ->getSitemapLinks ($ storeIds ) : [];
93
98
94
99
return $ links ? implode (PHP_EOL , $ links ) . PHP_EOL : '' ;
95
100
}
@@ -106,18 +111,12 @@ protected function _toHtml()
106
111
*/
107
112
protected function getSitemapLinks (array $ storeIds )
108
113
{
109
- $ sitemapLinks = [];
110
-
111
- /** @var \Magento\Sitemap\Model\ResourceModel\Sitemap\Collection $collection */
112
114
$ collection = $ this ->sitemapCollectionFactory ->create ();
113
115
$ collection ->addStoreFilter ($ storeIds );
114
116
117
+ $ sitemapLinks = [];
115
118
foreach ($ collection as $ sitemap ) {
116
- /** @var \Magento\Sitemap\Model\Sitemap $sitemap */
117
- $ sitemapFilename = $ sitemap ->getSitemapFilename ();
118
- $ sitemapPath = $ sitemap ->getSitemapPath ();
119
-
120
- $ sitemapUrl = $ sitemap ->getSitemapUrl ($ sitemapPath , $ sitemapFilename );
119
+ $ sitemapUrl = $ sitemap ->getSitemapUrl ($ sitemap ->getSitemapPath (), $ sitemap ->getSitemapFilename ());
121
120
$ sitemapLinks [$ sitemapUrl ] = 'Sitemap: ' . $ sitemapUrl ;
122
121
}
123
122
0 commit comments