31
31
use Magento \Framework \Data \Collection \AbstractDb ;
32
32
use Magento \Framework \DataObject ;
33
33
use Magento \Framework \Escaper ;
34
+ use Magento \Framework \Exception \FileSystemException ;
34
35
use Magento \Framework \Exception \LocalizedException ;
36
+ use Magento \Framework \Exception \NoSuchEntityException ;
37
+ use Magento \Framework \Exception \ValidatorException ;
35
38
use Magento \Framework \Filesystem ;
36
39
use Magento \Framework \Model \Context ;
37
40
use Magento \Framework \Model \ResourceModel \AbstractResource ;
45
48
use Magento \Sitemap \Model \Sitemap as CoreSitemap ;
46
49
use Magento \Store \Model \StoreManagerInterface ;
47
50
use Mageplaza \Sitemap \Helper \Data as HelperConfig ;
51
+ use Zend_Db_Statement_Exception ;
48
52
49
53
/**
50
54
* Class Sitemap
@@ -202,24 +206,25 @@ public function _initSitemapItems()
202
206
}
203
207
204
208
/**
205
- * @return $this
206
- * @throws Exception
209
+ * @return $this|CoreSitemap
207
210
* @throws LocalizedException
211
+ * @throws FileSystemException
212
+ * @throws ValidatorException
208
213
*/
209
214
public function generateXml ()
210
215
{
211
216
$ this ->_initSitemapItems ();
212
217
/** @var $sitemapItem DataObject */
213
218
foreach ($ this ->_sitemapItems as $ item ) {
214
- $ changefreq = $ item ->getChangefreq ();
219
+ $ changeFreq = $ item ->getChangefreq ();
215
220
$ priority = $ item ->getPriority ();
216
221
$ urlType = $ item ->getUrlType ();
217
222
foreach ($ item ->getCollection () as $ itemChild ) {
218
223
$ xml = $ this ->getSitemapRow (
219
224
$ itemChild ->getUrl (),
220
225
$ urlType ,
221
226
$ itemChild ->getUpdatedAt (),
222
- $ changefreq ,
227
+ $ changeFreq ,
223
228
$ priority ,
224
229
$ itemChild ->getImages ()
225
230
);
@@ -258,10 +263,10 @@ public function generateXml()
258
263
/**
259
264
* Get site map row
260
265
*
261
- * @param $url
262
- * @param $urlType
263
- * @param null $lastmod
264
- * @param null $changefreq
266
+ * @param string $url
267
+ * @param int $urlType
268
+ * @param null $lastMod
269
+ * @param null $changeFreq
265
270
* @param null $priority
266
271
* @param null $images
267
272
*
@@ -270,8 +275,8 @@ public function generateXml()
270
275
protected function getSitemapRow (
271
276
$ url ,
272
277
$ urlType ,
273
- $ lastmod = null ,
274
- $ changefreq = null ,
278
+ $ lastMod = null ,
279
+ $ changeFreq = null ,
275
280
$ priority = null ,
276
281
$ images = null
277
282
) {
@@ -281,11 +286,11 @@ protected function getSitemapRow(
281
286
$ url = $ this ->convertUrl ($ url );
282
287
}
283
288
$ row = '<loc> ' . htmlspecialchars ($ url ) . '</loc> ' ;
284
- if ($ lastmod ) {
285
- $ row .= '<lastmod> ' . $ this ->_getFormattedLastmodDate ($ lastmod ) . '</lastmod> ' ;
289
+ if ($ lastMod ) {
290
+ $ row .= '<lastmod> ' . $ this ->_getFormattedLastmodDate ($ lastMod ) . '</lastmod> ' ;
286
291
}
287
- if ($ changefreq ) {
288
- $ row .= '<changefreq> ' . $ changefreq . '</changefreq> ' ;
292
+ if ($ changeFreq ) {
293
+ $ row .= '<changefreq> ' . $ changeFreq . '</changefreq> ' ;
289
294
}
290
295
if ($ priority ) {
291
296
$ row .= sprintf ('<priority>%.1f</priority> ' , $ priority );
@@ -315,7 +320,7 @@ protected function getSitemapRow(
315
320
/**
316
321
* Get link collection added by config Additional Links
317
322
*
318
- * @param $storeId
323
+ * @param int $storeId
319
324
*
320
325
* @return array
321
326
*/
@@ -339,7 +344,7 @@ public function getLinkCollectionAdded($storeId)
339
344
/**
340
345
* Get category collection
341
346
*
342
- * @param $storeId
347
+ * @param int $storeId
343
348
*
344
349
* @return array
345
350
*/
@@ -360,7 +365,7 @@ public function _getCategoryCollection($storeId)
360
365
/**
361
366
* Get page collection
362
367
*
363
- * @param $storeId
368
+ * @param int $storeId
364
369
*
365
370
* @return array
366
371
*/
@@ -382,9 +387,12 @@ public function _getPageCollection($storeId)
382
387
/**
383
388
* Get product Collection
384
389
*
385
- * @param $storeId
390
+ * @param int $storeId
386
391
*
387
392
* @return array
393
+ * @throws LocalizedException
394
+ * @throws NoSuchEntityException
395
+ * @throws Zend_Db_Statement_Exception
388
396
*/
389
397
public function _getProductCollection ($ storeId )
390
398
{
@@ -393,9 +401,7 @@ public function _getProductCollection($storeId)
393
401
if ($ this ->_coreProductFactory ->create ()->load ($ item ->getId ())->getData ('mp_exclude_sitemap ' ) == 1 ) {
394
402
continue ;
395
403
}
396
- if ($ this ->stockItem ->load ($ item ->getId (), 'product_id ' )->getIsInStock () == 0 ) {
397
- continue ;
398
- }
404
+
399
405
$ collection [] = $ item ;
400
406
}
401
407
@@ -405,7 +411,7 @@ public function _getProductCollection($storeId)
405
411
/**
406
412
* Convert Url
407
413
*
408
- * @param $url
414
+ * @param string $url
409
415
*
410
416
* @return string
411
417
*/
@@ -421,8 +427,8 @@ public function convertUrl($url)
421
427
/**
422
428
* Remove the link of the CMS page using for homepage.
423
429
*
424
- * @param $storeId
425
- * @param $page
430
+ * @param int $storeId
431
+ * @param Object $page
426
432
*
427
433
* @return bool
428
434
*/
0 commit comments