Skip to content
This repository was archived by the owner on Feb 8, 2023. It is now read-only.

Commit 40dd206

Browse files
authored
Merge pull request #17 from mageplaza/2.4-develop
2.4-develop
2 parents f46d447 + 345b748 commit 40dd206

File tree

4 files changed

+50
-34
lines changed

4 files changed

+50
-34
lines changed

Block/Sitemap.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,23 @@ public function getCategoryUrl($categoryId)
170170

171171
/**
172172
* Get page collection
173-
* @return mixed
173+
*
174+
* @return PageCollection
175+
* @throws NoSuchEntityException
174176
*/
175177
public function getPageCollection()
176178
{
177-
return $this->pageCollection->addFieldToFilter('is_active', Page::STATUS_ENABLED)
178-
->addFieldToFilter('identifier', [
179+
$excludePages = $this->_helper->getExcludePageListing();
180+
$pageCollection = $this->pageCollection->addFieldToFilter('is_active', Page::STATUS_ENABLED)
181+
->addStoreFilter($this->_storeManager->getStore());
182+
183+
if ($this->_helper->isEnableExcludePage() && !empty($excludePages)) {
184+
$pageCollection->addFieldToFilter('identifier', [
179185
'nin' => $this->getExcludedPages()
180186
]);
187+
}
188+
189+
return $pageCollection;
181190
}
182191

183192
/**
@@ -186,11 +195,7 @@ public function getPageCollection()
186195
*/
187196
public function getExcludedPages()
188197
{
189-
if ($this->_helper->isEnableExcludePage()) {
190-
return explode(',', $this->_helper->getExcludePageListing());
191-
}
192-
193-
return ['home', 'no-route'];
198+
return explode(',', $this->_helper->getExcludePageListing());
194199
}
195200

196201
/**

Model/Sitemap.php

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
use Magento\Framework\Data\Collection\AbstractDb;
3232
use Magento\Framework\DataObject;
3333
use Magento\Framework\Escaper;
34+
use Magento\Framework\Exception\FileSystemException;
3435
use Magento\Framework\Exception\LocalizedException;
36+
use Magento\Framework\Exception\NoSuchEntityException;
37+
use Magento\Framework\Exception\ValidatorException;
3538
use Magento\Framework\Filesystem;
3639
use Magento\Framework\Model\Context;
3740
use Magento\Framework\Model\ResourceModel\AbstractResource;
@@ -45,6 +48,7 @@
4548
use Magento\Sitemap\Model\Sitemap as CoreSitemap;
4649
use Magento\Store\Model\StoreManagerInterface;
4750
use Mageplaza\Sitemap\Helper\Data as HelperConfig;
51+
use Zend_Db_Statement_Exception;
4852

4953
/**
5054
* Class Sitemap
@@ -202,24 +206,25 @@ public function _initSitemapItems()
202206
}
203207

204208
/**
205-
* @return $this
206-
* @throws Exception
209+
* @return $this|CoreSitemap
207210
* @throws LocalizedException
211+
* @throws FileSystemException
212+
* @throws ValidatorException
208213
*/
209214
public function generateXml()
210215
{
211216
$this->_initSitemapItems();
212217
/** @var $sitemapItem DataObject */
213218
foreach ($this->_sitemapItems as $item) {
214-
$changefreq = $item->getChangefreq();
219+
$changeFreq = $item->getChangefreq();
215220
$priority = $item->getPriority();
216221
$urlType = $item->getUrlType();
217222
foreach ($item->getCollection() as $itemChild) {
218223
$xml = $this->getSitemapRow(
219224
$itemChild->getUrl(),
220225
$urlType,
221226
$itemChild->getUpdatedAt(),
222-
$changefreq,
227+
$changeFreq,
223228
$priority,
224229
$itemChild->getImages()
225230
);
@@ -258,10 +263,10 @@ public function generateXml()
258263
/**
259264
* Get site map row
260265
*
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
265270
* @param null $priority
266271
* @param null $images
267272
*
@@ -270,8 +275,8 @@ public function generateXml()
270275
protected function getSitemapRow(
271276
$url,
272277
$urlType,
273-
$lastmod = null,
274-
$changefreq = null,
278+
$lastMod = null,
279+
$changeFreq = null,
275280
$priority = null,
276281
$images = null
277282
) {
@@ -281,11 +286,11 @@ protected function getSitemapRow(
281286
$url = $this->convertUrl($url);
282287
}
283288
$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>';
286291
}
287-
if ($changefreq) {
288-
$row .= '<changefreq>' . $changefreq . '</changefreq>';
292+
if ($changeFreq) {
293+
$row .= '<changefreq>' . $changeFreq . '</changefreq>';
289294
}
290295
if ($priority) {
291296
$row .= sprintf('<priority>%.1f</priority>', $priority);
@@ -315,7 +320,7 @@ protected function getSitemapRow(
315320
/**
316321
* Get link collection added by config Additional Links
317322
*
318-
* @param $storeId
323+
* @param int $storeId
319324
*
320325
* @return array
321326
*/
@@ -339,7 +344,7 @@ public function getLinkCollectionAdded($storeId)
339344
/**
340345
* Get category collection
341346
*
342-
* @param $storeId
347+
* @param int $storeId
343348
*
344349
* @return array
345350
*/
@@ -360,7 +365,7 @@ public function _getCategoryCollection($storeId)
360365
/**
361366
* Get page collection
362367
*
363-
* @param $storeId
368+
* @param int $storeId
364369
*
365370
* @return array
366371
*/
@@ -382,9 +387,12 @@ public function _getPageCollection($storeId)
382387
/**
383388
* Get product Collection
384389
*
385-
* @param $storeId
390+
* @param int $storeId
386391
*
387392
* @return array
393+
* @throws LocalizedException
394+
* @throws NoSuchEntityException
395+
* @throws Zend_Db_Statement_Exception
388396
*/
389397
public function _getProductCollection($storeId)
390398
{
@@ -393,9 +401,7 @@ public function _getProductCollection($storeId)
393401
if ($this->_coreProductFactory->create()->load($item->getId())->getData('mp_exclude_sitemap') == 1) {
394402
continue;
395403
}
396-
if ($this->stockItem->load($item->getId(), 'product_id')->getIsInStock() == 0) {
397-
continue;
398-
}
404+
399405
$collection[] = $item;
400406
}
401407

@@ -405,7 +411,7 @@ public function _getProductCollection($storeId)
405411
/**
406412
* Convert Url
407413
*
408-
* @param $url
414+
* @param string $url
409415
*
410416
* @return string
411417
*/
@@ -421,8 +427,8 @@ public function convertUrl($url)
421427
/**
422428
* Remove the link of the CMS page using for homepage.
423429
*
424-
* @param $storeId
425-
* @param $page
430+
* @param int $storeId
431+
* @param Object $page
426432
*
427433
* @return bool
428434
*/

Model/Source/Page.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@ public function __construct(CollectionFactory $pageCollectionFactory)
5151
*/
5252
public function toOptionArray()
5353
{
54-
$options = [];
54+
$options[] = [
55+
'value' => '',
56+
'label' => __('-- Please select --')
57+
];
58+
5559
/** @var Collection $collection */
5660
$collection = $this->_pageCollectionFactory->create();
61+
5762
foreach ($collection as $item) {
5863
$options[] = ['value' => $item->getIdentifier(), 'label' => $item->getTitle()];
5964
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"mageplaza/magento-2-seo-extension": "^4.0.0"
77
},
88
"type": "magento2-module",
9-
"version": "4.0.0",
9+
"version": "4.0.1",
1010
"license": "proprietary",
1111
"authors": [
1212
{

0 commit comments

Comments
 (0)