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

Commit

Permalink
Merge pull request #17 from mageplaza/2.4-develop
Browse files Browse the repository at this point in the history
2.4-develop
  • Loading branch information
Shinichi69 committed Sep 14, 2021
2 parents f46d447 + 345b748 commit 40dd206
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 34 deletions.
21 changes: 13 additions & 8 deletions Block/Sitemap.php
Expand Up @@ -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;
}

/**
Expand All @@ -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());
}

/**
Expand Down
54 changes: 30 additions & 24 deletions Model/Sitemap.php
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -202,24 +206,25 @@ 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) {
$xml = $this->getSitemapRow(
$itemChild->getUrl(),
$urlType,
$itemChild->getUpdatedAt(),
$changefreq,
$changeFreq,
$priority,
$itemChild->getImages()
);
Expand Down Expand Up @@ -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
*
Expand All @@ -270,8 +275,8 @@ public function generateXml()
protected function getSitemapRow(
$url,
$urlType,
$lastmod = null,
$changefreq = null,
$lastMod = null,
$changeFreq = null,
$priority = null,
$images = null
) {
Expand All @@ -281,11 +286,11 @@ protected function getSitemapRow(
$url = $this->convertUrl($url);
}
$row = '<loc>' . htmlspecialchars($url) . '</loc>';
if ($lastmod) {
$row .= '<lastmod>' . $this->_getFormattedLastmodDate($lastmod) . '</lastmod>';
if ($lastMod) {
$row .= '<lastmod>' . $this->_getFormattedLastmodDate($lastMod) . '</lastmod>';
}
if ($changefreq) {
$row .= '<changefreq>' . $changefreq . '</changefreq>';
if ($changeFreq) {
$row .= '<changefreq>' . $changeFreq . '</changefreq>';
}
if ($priority) {
$row .= sprintf('<priority>%.1f</priority>', $priority);
Expand Down Expand Up @@ -315,7 +320,7 @@ protected function getSitemapRow(
/**
* Get link collection added by config Additional Links
*
* @param $storeId
* @param int $storeId
*
* @return array
*/
Expand All @@ -339,7 +344,7 @@ public function getLinkCollectionAdded($storeId)
/**
* Get category collection
*
* @param $storeId
* @param int $storeId
*
* @return array
*/
Expand All @@ -360,7 +365,7 @@ public function _getCategoryCollection($storeId)
/**
* Get page collection
*
* @param $storeId
* @param int $storeId
*
* @return array
*/
Expand All @@ -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)
{
Expand All @@ -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;
}

Expand All @@ -405,7 +411,7 @@ public function _getProductCollection($storeId)
/**
* Convert Url
*
* @param $url
* @param string $url
*
* @return string
*/
Expand All @@ -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
*/
Expand Down
7 changes: 6 additions & 1 deletion Model/Source/Page.php
Expand Up @@ -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()];
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -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": [
{
Expand Down

0 comments on commit 40dd206

Please sign in to comment.