21
21
22
22
namespace Mageplaza \Sitemap \Model ;
23
23
24
+ use Exception ;
24
25
use Magento \Catalog \Model \CategoryFactory ;
25
26
use Magento \Catalog \Model \ProductFactory ;
26
27
use Magento \CatalogInventory \Model \Stock \Item ;
27
28
use Magento \Cms \Model \PageFactory ;
28
29
use Magento \Framework \App \ObjectManager ;
29
30
use Magento \Framework \App \RequestInterface ;
30
31
use Magento \Framework \Data \Collection \AbstractDb ;
32
+ use Magento \Framework \DataObject ;
31
33
use Magento \Framework \Escaper ;
34
+ use Magento \Framework \Exception \LocalizedException ;
32
35
use Magento \Framework \Filesystem ;
33
36
use Magento \Framework \Model \Context ;
34
37
use Magento \Framework \Model \ResourceModel \AbstractResource ;
@@ -55,17 +58,17 @@ class Sitemap extends CoreSitemap
55
58
const HOMEPAGE_PATH = 'web/default/cms_home_page ' ;
56
59
57
60
/**
58
- * @var \Magento\Catalog\Model\ CategoryFactory
61
+ * @var CategoryFactory
59
62
*/
60
63
protected $ _coreCategoryFactory ;
61
64
62
65
/**
63
- * @var \Magento\Catalog\Model\ ProductFactory
66
+ * @var ProductFactory
64
67
*/
65
68
protected $ _coreProductFactory ;
66
69
67
70
/**
68
- * @var \Magento\Cms\Model\ PageFactory
71
+ * @var PageFactory
69
72
*/
70
73
protected $ _corePageFactory ;
71
74
@@ -75,7 +78,7 @@ class Sitemap extends CoreSitemap
75
78
protected $ helperConfig ;
76
79
77
80
/**
78
- * @var \Magento\CatalogInventory\Model\Stock\ Item
81
+ * @var Item
79
82
*/
80
83
protected $ stockItem ;
81
84
@@ -159,7 +162,7 @@ public function _initSitemapItems()
159
162
$ helper = $ this ->_sitemapData ;
160
163
$ storeId = $ this ->getStoreId ();
161
164
$ this ->_sitemapItems = null ;
162
- $ this ->_sitemapItems [] = new \ Magento \ Framework \ DataObject (
165
+ $ this ->_sitemapItems [] = new DataObject (
163
166
[
164
167
'changefreq ' => $ helper ->getCategoryChangefreq ($ storeId ),
165
168
'priority ' => $ helper ->getCategoryPriority ($ storeId ),
@@ -168,7 +171,7 @@ public function _initSitemapItems()
168
171
]
169
172
);
170
173
171
- $ this ->_sitemapItems [] = new \ Magento \ Framework \ DataObject (
174
+ $ this ->_sitemapItems [] = new DataObject (
172
175
[
173
176
'changefreq ' => $ helper ->getProductChangefreq ($ storeId ),
174
177
'priority ' => $ helper ->getProductPriority ($ storeId ),
@@ -177,7 +180,7 @@ public function _initSitemapItems()
177
180
]
178
181
);
179
182
180
- $ this ->_sitemapItems [] = new \ Magento \ Framework \ DataObject (
183
+ $ this ->_sitemapItems [] = new DataObject (
181
184
[
182
185
'changefreq ' => $ helper ->getPageChangefreq ($ storeId ),
183
186
'priority ' => $ helper ->getPagePriority ($ storeId ),
@@ -187,7 +190,7 @@ public function _initSitemapItems()
187
190
);
188
191
189
192
if ($ this ->helperConfig ->isEnableAdditionalLinks ($ storeId )) {
190
- $ this ->_sitemapItems [] = new \ Magento \ Framework \ DataObject (
193
+ $ this ->_sitemapItems [] = new DataObject (
191
194
[
192
195
'changefreq ' => $ this ->helperConfig ->getFrequency ($ storeId ),
193
196
'priority ' => $ this ->helperConfig ->getPriority ($ storeId ),
@@ -200,13 +203,13 @@ public function _initSitemapItems()
200
203
201
204
/**
202
205
* @return $this
203
- * @throws \ Exception
204
- * @throws \Magento\Framework\Exception\ LocalizedException
206
+ * @throws Exception
207
+ * @throws LocalizedException
205
208
*/
206
209
public function generateXml ()
207
210
{
208
211
$ this ->_initSitemapItems ();
209
- /** @var $sitemapItem \Magento\Framework\ DataObject */
212
+ /** @var $sitemapItem DataObject */
210
213
foreach ($ this ->_sitemapItems as $ item ) {
211
214
$ changefreq = $ item ->getChangefreq ();
212
215
$ priority = $ item ->getPriority ();
@@ -236,12 +239,8 @@ public function generateXml()
236
239
237
240
if ($ this ->_sitemapIncrement == 1 ) {
238
241
// In case when only one increment file was created use it as default sitemap
239
- $ path = rtrim (
240
- $ this ->getSitemapPath (),
241
- '/ '
242
- ) . '/ ' . $ this ->_getCurrentSitemapFilename (
243
- $ this ->_sitemapIncrement
244
- );
242
+ $ path = rtrim ($ this ->getSitemapPath (), '/ ' ) . '/ '
243
+ . $ this ->_getCurrentSitemapFilename ($ this ->_sitemapIncrement );
245
244
$ destination = rtrim ($ this ->getSitemapPath (), '/ ' ) . '/ ' . $ this ->getSitemapFilename ();
246
245
247
246
$ this ->_directory ->renameFile ($ path , $ destination );
@@ -273,8 +272,14 @@ public function generateXml()
273
272
*
274
273
* @return string
275
274
*/
276
- protected function getSitemapRow ($ url , $ urlType , $ lastmod = null , $ changefreq = null , $ priority = null , $ images = null )
277
- {
275
+ protected function getSitemapRow (
276
+ $ url ,
277
+ $ urlType ,
278
+ $ lastmod = null ,
279
+ $ changefreq = null ,
280
+ $ priority = null ,
281
+ $ images = null
282
+ ) {
278
283
if ($ urlType == self ::URL ) {
279
284
$ url = $ this ->_getUrl ($ url );
280
285
} else {
@@ -304,9 +309,8 @@ protected function getSitemapRow($url, $urlType, $lastmod = null, $changefreq =
304
309
// Add PageMap image for Google web search
305
310
$ row .= '<PageMap xmlns="http://www.google.com/schemas/sitemap-pagemap/1.0"><DataObject type="thumbnail"> ' ;
306
311
$ row .= '<Attribute name="name" value=" ' . htmlspecialchars ($ images ->getTitle ()) . '"/> ' ;
307
- $ row .= '<Attribute name="src" value=" ' . htmlspecialchars (
308
- $ this ->_getMediaUrl ($ images ->getThumbnail ())
309
- ) . '"/> ' ;
312
+ $ row .= '<Attribute name="src" value=" ' . htmlspecialchars ($ this ->_getMediaUrl ($ images ->getThumbnail ()))
313
+ . '"/> ' ;
310
314
$ row .= '</DataObject></PageMap> ' ;
311
315
}
312
316
@@ -325,8 +329,8 @@ public function getLinkCollectionAdded($storeId)
325
329
$ id = 1 ;
326
330
$ collection = [];
327
331
foreach ($ this ->helperConfig ->getXmlAdditionalLinks ($ storeId ) as $ item ) {
328
- if ($ item != null ) {
329
- $ obj = ObjectManager::getInstance ()->create (' \Magento\Framework\DataObject ' );
332
+ if ($ item !== null ) {
333
+ $ obj = ObjectManager::getInstance ()->create (\Magento \Framework \DataObject::class );
330
334
$ obj ->setData ('id ' , $ id ++);
331
335
$ obj ->setData ('url ' , $ item );
332
336
$ obj ->setData ('updated_at ' , $ this ->getSitemapTime ());
@@ -347,6 +351,7 @@ public function getLinkCollectionAdded($storeId)
347
351
public function _getCategoryCollection ($ storeId )
348
352
{
349
353
$ collection = [];
354
+
350
355
foreach ($ this ->_categoryFactory ->create ()->getCollection ($ storeId ) as $ item ) {
351
356
if ($ this ->_coreCategoryFactory ->create ()->load ($ item ->getId ())->getData ('mp_exclude_sitemap ' ) == 1 ) {
352
357
continue ;
@@ -428,12 +433,7 @@ public function convertUrl($url)
428
433
*/
429
434
public function optimizeHomepage ($ storeId , $ page )
430
435
{
431
- if ($ this ->helperConfig ->isEnableHomepageOptimization ($ storeId ) == 1 ) {
432
- if ($ this ->helperConfig ->getConfigValue (self ::HOMEPAGE_PATH , $ storeId ) == $ page ->getUrl ()) {
433
- return true ;
434
- }
435
- }
436
-
437
- return false ;
436
+ return $ this ->helperConfig ->isEnableHomepageOptimization ($ storeId ) == 1
437
+ && $ this ->helperConfig ->getConfigValue (self ::HOMEPAGE_PATH , $ storeId ) == $ page ->getUrl ();
438
438
}
439
439
}
0 commit comments