diff --git a/Block/Sitemap.php b/Block/Sitemap.php
index 516b07b..5a996fd 100755
--- a/Block/Sitemap.php
+++ b/Block/Sitemap.php
@@ -170,14 +170,23 @@ public function getCategoryUrl($categoryId)
/**
* Get page collection
- * @return mixed
+ *
+ * @return PageCollection
+ * @throws NoSuchEntityException
*/
public function getPageCollection()
{
- return $this->pageCollection->addFieldToFilter('is_active', Page::STATUS_ENABLED)
- ->addFieldToFilter('identifier', [
+ $excludePages = $this->_helper->getExcludePageListing();
+ $pageCollection = $this->pageCollection->addFieldToFilter('is_active', Page::STATUS_ENABLED)
+ ->addStoreFilter($this->_storeManager->getStore());
+
+ if ($this->_helper->isEnableExcludePage() && !empty($excludePages)) {
+ $pageCollection->addFieldToFilter('identifier', [
'nin' => $this->getExcludedPages()
]);
+ }
+
+ return $pageCollection;
}
/**
@@ -186,11 +195,7 @@ public function getPageCollection()
*/
public function getExcludedPages()
{
- if ($this->_helper->isEnableExcludePage()) {
- return explode(',', $this->_helper->getExcludePageListing());
- }
-
- return ['home', 'no-route'];
+ return explode(',', $this->_helper->getExcludePageListing());
}
/**
diff --git a/Model/Sitemap.php b/Model/Sitemap.php
index 27dfc1d..820a523 100755
--- a/Model/Sitemap.php
+++ b/Model/Sitemap.php
@@ -31,7 +31,10 @@
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Framework\DataObject;
use Magento\Framework\Escaper;
+use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Exception\LocalizedException;
+use Magento\Framework\Exception\NoSuchEntityException;
+use Magento\Framework\Exception\ValidatorException;
use Magento\Framework\Filesystem;
use Magento\Framework\Model\Context;
use Magento\Framework\Model\ResourceModel\AbstractResource;
@@ -45,6 +48,7 @@
use Magento\Sitemap\Model\Sitemap as CoreSitemap;
use Magento\Store\Model\StoreManagerInterface;
use Mageplaza\Sitemap\Helper\Data as HelperConfig;
+use Zend_Db_Statement_Exception;
/**
* Class Sitemap
@@ -202,16 +206,17 @@ public function _initSitemapItems()
}
/**
- * @return $this
- * @throws Exception
+ * @return $this|CoreSitemap
* @throws LocalizedException
+ * @throws FileSystemException
+ * @throws ValidatorException
*/
public function generateXml()
{
$this->_initSitemapItems();
/** @var $sitemapItem DataObject */
foreach ($this->_sitemapItems as $item) {
- $changefreq = $item->getChangefreq();
+ $changeFreq = $item->getChangefreq();
$priority = $item->getPriority();
$urlType = $item->getUrlType();
foreach ($item->getCollection() as $itemChild) {
@@ -219,7 +224,7 @@ public function generateXml()
$itemChild->getUrl(),
$urlType,
$itemChild->getUpdatedAt(),
- $changefreq,
+ $changeFreq,
$priority,
$itemChild->getImages()
);
@@ -258,10 +263,10 @@ public function generateXml()
/**
* Get site map row
*
- * @param $url
- * @param $urlType
- * @param null $lastmod
- * @param null $changefreq
+ * @param string $url
+ * @param int $urlType
+ * @param null $lastMod
+ * @param null $changeFreq
* @param null $priority
* @param null $images
*
@@ -270,8 +275,8 @@ public function generateXml()
protected function getSitemapRow(
$url,
$urlType,
- $lastmod = null,
- $changefreq = null,
+ $lastMod = null,
+ $changeFreq = null,
$priority = null,
$images = null
) {
@@ -281,11 +286,11 @@ protected function getSitemapRow(
$url = $this->convertUrl($url);
}
$row = '' . htmlspecialchars($url) . '';
- if ($lastmod) {
- $row .= '' . $this->_getFormattedLastmodDate($lastmod) . '';
+ if ($lastMod) {
+ $row .= '' . $this->_getFormattedLastmodDate($lastMod) . '';
}
- if ($changefreq) {
- $row .= '' . $changefreq . '';
+ if ($changeFreq) {
+ $row .= '' . $changeFreq . '';
}
if ($priority) {
$row .= sprintf('%.1f', $priority);
@@ -315,7 +320,7 @@ protected function getSitemapRow(
/**
* Get link collection added by config Additional Links
*
- * @param $storeId
+ * @param int $storeId
*
* @return array
*/
@@ -339,7 +344,7 @@ public function getLinkCollectionAdded($storeId)
/**
* Get category collection
*
- * @param $storeId
+ * @param int $storeId
*
* @return array
*/
@@ -360,7 +365,7 @@ public function _getCategoryCollection($storeId)
/**
* Get page collection
*
- * @param $storeId
+ * @param int $storeId
*
* @return array
*/
@@ -382,9 +387,12 @@ public function _getPageCollection($storeId)
/**
* Get product Collection
*
- * @param $storeId
+ * @param int $storeId
*
* @return array
+ * @throws LocalizedException
+ * @throws NoSuchEntityException
+ * @throws Zend_Db_Statement_Exception
*/
public function _getProductCollection($storeId)
{
@@ -393,9 +401,7 @@ public function _getProductCollection($storeId)
if ($this->_coreProductFactory->create()->load($item->getId())->getData('mp_exclude_sitemap') == 1) {
continue;
}
- if ($this->stockItem->load($item->getId(), 'product_id')->getIsInStock() == 0) {
- continue;
- }
+
$collection[] = $item;
}
@@ -405,7 +411,7 @@ public function _getProductCollection($storeId)
/**
* Convert Url
*
- * @param $url
+ * @param string $url
*
* @return string
*/
@@ -421,8 +427,8 @@ public function convertUrl($url)
/**
* Remove the link of the CMS page using for homepage.
*
- * @param $storeId
- * @param $page
+ * @param int $storeId
+ * @param Object $page
*
* @return bool
*/
diff --git a/Model/Source/Page.php b/Model/Source/Page.php
index ee25d42..676b64b 100755
--- a/Model/Source/Page.php
+++ b/Model/Source/Page.php
@@ -51,9 +51,14 @@ public function __construct(CollectionFactory $pageCollectionFactory)
*/
public function toOptionArray()
{
- $options = [];
+ $options[] = [
+ 'value' => '',
+ 'label' => __('-- Please select --')
+ ];
+
/** @var Collection $collection */
$collection = $this->_pageCollectionFactory->create();
+
foreach ($collection as $item) {
$options[] = ['value' => $item->getIdentifier(), 'label' => $item->getTitle()];
}
diff --git a/composer.json b/composer.json
index 7c331a5..fd7ab07 100755
--- a/composer.json
+++ b/composer.json
@@ -6,7 +6,7 @@
"mageplaza/magento-2-seo-extension": "^4.0.0"
},
"type": "magento2-module",
- "version": "4.0.0",
+ "version": "4.0.1",
"license": "proprietary",
"authors": [
{