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

Commit

Permalink
clean code & update composer
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinichi69 committed Sep 14, 2021
1 parent 3ef26a8 commit 345b748
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
50 changes: 29 additions & 21 deletions Model/Sitemap.php
Original file line number Diff line number Diff line change
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 @@ -403,7 +411,7 @@ public function _getProductCollection($storeId)
/**
* Convert Url
*
* @param $url
* @param string $url
*
* @return string
*/
Expand All @@ -419,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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
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 345b748

Please sign in to comment.