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

Commit 6f843cb

Browse files
authored
Merge pull request #20 from mageplaza/2.4-develop
2.4 develop
2 parents 40dd206 + c2a9ca7 commit 6f843cb

File tree

12 files changed

+372
-149
lines changed

12 files changed

+372
-149
lines changed

Block/Sitemap.php

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Magento\CatalogInventory\Helper\Stock;
3131
use Magento\Cms\Model\Page;
3232
use Magento\Cms\Model\ResourceModel\Page\Collection as PageCollection;
33+
use Magento\Framework\Data\Tree\Node\Collection as TreeCollection;
3334
use Magento\Framework\Exception\NoSuchEntityException;
3435
use Magento\Framework\View\Element\Template;
3536
use Magento\Framework\View\Element\Template\Context;
@@ -129,6 +130,7 @@ public function __construct(
129130

130131
/**
131132
* Get product collection
133+
*
132134
* @return mixed
133135
*/
134136
public function getProductCollection()
@@ -150,15 +152,16 @@ public function getProductCollection()
150152

151153
/**
152154
* Get category collection
153-
* @return \Magento\Framework\Data\Tree\Node\Collection
155+
*
156+
* @return TreeCollection
154157
*/
155158
public function getCategoryCollection()
156159
{
157160
return $this->_categoryHelper->getStoreCategories(false, true);
158161
}
159162

160163
/**
161-
* @param $categoryId
164+
* @param int $categoryId
162165
*
163166
* @return string
164167
* @throws NoSuchEntityException
@@ -178,7 +181,7 @@ public function getPageCollection()
178181
{
179182
$excludePages = $this->_helper->getExcludePageListing();
180183
$pageCollection = $this->pageCollection->addFieldToFilter('is_active', Page::STATUS_ENABLED)
181-
->addStoreFilter($this->_storeManager->getStore());
184+
->addStoreFilter($this->_storeManager->getStore()->getId());
182185

183186
if ($this->_helper->isEnableExcludePage() && !empty($excludePages)) {
184187
$pageCollection->addFieldToFilter('identifier', [
@@ -191,6 +194,7 @@ public function getPageCollection()
191194

192195
/**
193196
* Get excluded pages
197+
*
194198
* @return array
195199
*/
196200
public function getExcludedPages()
@@ -200,6 +204,7 @@ public function getExcludedPages()
200204

201205
/**
202206
* Get addition link collection
207+
*
203208
* @return mixed
204209
*/
205210
public function getAdditionLinksCollection()
@@ -220,8 +225,8 @@ public function getAdditionLinksCollection()
220225
/**
221226
* Render link element
222227
*
223-
* @param $link
224-
* @param $title
228+
* @param string $link
229+
* @param string $title
225230
*
226231
* @return string
227232
*/
@@ -230,11 +235,12 @@ public function renderLinkElement($link, $title)
230235
return '<li><a href="' . $link . '">' . __($title) . '</a></li>';
231236
}
232237

238+
// phpcs:disable Generic.Metrics.NestingLevel
233239
/**
234-
* @param $section
235-
* @param $config
236-
* @param $title
237-
* @param $collection
240+
* @param string $section
241+
* @param bool $config
242+
* @param string $title
243+
* @param Object $collection
238244
*
239245
* @return string
240246
* @throws NoSuchEntityException
@@ -250,15 +256,25 @@ public function renderSection($section, $config, $title, $collection)
250256
foreach ($collection as $key => $item) {
251257
switch ($section) {
252258
case 'category':
253-
$html .= $this->renderLinkElement($this->getCategoryUrl($item->getId()), $item->getName());
259+
$category = $this->categoryRepository->get($item->getId());
260+
if (!$category->getData('mp_exclude_sitemap')) {
261+
$html .= $this->renderLinkElement(
262+
$this->getCategoryUrl($item->getId()),
263+
$item->getName()
264+
);
265+
}
254266
break;
255267
case 'page':
256-
if (in_array($item->getIdentifier(), $this->getExcludedPages())) {
268+
if (in_array($item->getIdentifier(), $this->getExcludedPages())
269+
|| $item->getData('mp_exclude_sitemap')) {
257270
continue 2;
258271
}
259272
$html .= $this->renderLinkElement($this->getUrl($item->getIdentifier()), $item->getTitle());
260273
break;
261274
case 'product':
275+
if ($item->getData('mp_exclude_sitemap')) {
276+
continue 2;
277+
}
262278
$html .= $this->renderLinkElement($this->getUrl($item->getProductUrl()), $item->getName());
263279
break;
264280
case 'link':
@@ -311,6 +327,7 @@ public function renderHtmlSitemap()
311327

312328
/**
313329
* Is enable html site map
330+
*
314331
* @return mixed
315332
*/
316333
public function isEnableHtmlSitemap()

Model/Sitemap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
namespace Mageplaza\Sitemap\Model;
2323

24-
use Exception;
2524
use Magento\Catalog\Model\CategoryFactory;
2625
use Magento\Catalog\Model\ProductFactory;
2726
use Magento\CatalogInventory\Model\Stock\Item;

Model/Source/Boolean.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Mageplaza
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Mageplaza.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://www.mageplaza.com/LICENSE.txt
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Mageplaza
17+
* @package Mageplaza_Sitemap
18+
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
19+
* @license https://www.mageplaza.com/LICENSE.txt
20+
*/
21+
22+
namespace Mageplaza\Sitemap\Model\Source;
23+
24+
use Magento\Framework\Data\OptionSourceInterface;
25+
26+
/**
27+
* Class Boolean
28+
* @package Mageplaza\Sitemap\Model\Source
29+
*/
30+
class Boolean extends \Magento\Eav\Model\Entity\Attribute\Source\Boolean implements OptionSourceInterface
31+
{
32+
/**
33+
* @return array|null
34+
*/
35+
public function getAllOptions()
36+
{
37+
if ($this->_options === null) {
38+
$this->_options = [
39+
['label' => __('No'), 'value' => self::VALUE_NO],
40+
['label' => __('Yes'), 'value' => self::VALUE_YES]
41+
];
42+
}
43+
return $this->_options;
44+
}
45+
}

Model/Source/Page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function toOptionArray()
5757
];
5858

5959
/** @var Collection $collection */
60-
$collection = $this->_pageCollectionFactory->create();
60+
$collection = $this->_pageCollectionFactory->create()->addFieldToFilter('is_active', 1);
6161

6262
foreach ($collection as $item) {
6363
$options[] = ['value' => $item->getIdentifier(), 'label' => $item->getTitle()];
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Mageplaza
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Mageplaza.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://www.mageplaza.com/LICENSE.txt
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Mageplaza
17+
* @package Mageplaza_Sitemap
18+
* @copyright Copyright (c) Mageplaza (http://www.mageplaza.com/)
19+
* @license https://www.mageplaza.com/LICENSE.txt
20+
*/
21+
22+
namespace Mageplaza\Sitemap\Plugin\Model;
23+
24+
use Magento\Cms\Model\GetUtilityPageIdentifiers as CmsGetUtilityPageIdentifiers;
25+
use Mageplaza\Sitemap\Helper\Data;
26+
27+
/**
28+
* Class GetUtilityPageIdentifiers
29+
* @package Mageplaza\Sitemap\Plugin\Model
30+
*/
31+
class GetUtilityPageIdentifiers
32+
{
33+
/**
34+
* @var Data
35+
*/
36+
protected $helperData;
37+
38+
/**
39+
* GetUtilityPageIdentifiers constructor.
40+
*
41+
* @param Data $helperData
42+
*/
43+
public function __construct(
44+
Data $helperData
45+
) {
46+
$this->helperData = $helperData;
47+
}
48+
49+
/**
50+
* @param CmsGetUtilityPageIdentifiers $subject
51+
* @param array $result
52+
*
53+
* @return mixed
54+
*/
55+
public function afterExecute(CmsGetUtilityPageIdentifiers $subject, $result)
56+
{
57+
if (!$this->helperData->isEnableHomepageOptimization() && isset($result[0])) {
58+
unset($result[0]);
59+
}
60+
61+
return $result;
62+
}
63+
}

Setup/UpgradeData.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Mageplaza
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Mageplaza.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://www.mageplaza.com/LICENSE.txt
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Mageplaza
17+
* @package Mageplaza_Sitemap
18+
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
19+
* @license https://www.mageplaza.com/LICENSE.txt
20+
*/
21+
22+
namespace Mageplaza\Sitemap\Setup;
23+
24+
use Magento\Catalog\Model\Product;
25+
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
26+
use Magento\Framework\Setup\ModuleContextInterface;
27+
use Magento\Framework\Setup\ModuleDataSetupInterface;
28+
use Magento\Framework\Setup\UpgradeDataInterface;
29+
use Magento\Eav\Setup\EavSetupFactory;
30+
use Mageplaza\Sitemap\Model\Source\Boolean;
31+
32+
/**
33+
* Class UpgradeData
34+
* @package Mageplaza\Sitemap\Setup
35+
*/
36+
class UpgradeData implements UpgradeDataInterface
37+
{
38+
/**
39+
* @var EavSetupFactory
40+
*/
41+
protected $eavSetupFactory;
42+
43+
/**
44+
* UpgradeData constructor.
45+
*
46+
* @param EavSetupFactory $eavSetupFactory
47+
*/
48+
public function __construct(
49+
EavSetupFactory $eavSetupFactory
50+
) {
51+
$this->eavSetupFactory = $eavSetupFactory;
52+
}
53+
54+
/**
55+
* @param ModuleDataSetupInterface $setup
56+
* @param ModuleContextInterface $context
57+
*/
58+
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
59+
{
60+
$installer = $setup;
61+
$installer->startSetup();
62+
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
63+
64+
if (version_compare($context->getVersion(), '2.0.2', '<')) {
65+
$eavSetup->removeAttribute(Product::ENTITY, 'mp_exclude_sitemap');
66+
$eavSetup->addAttribute(Product::ENTITY, 'mp_exclude_sitemap', [
67+
'type' => 'varchar',
68+
'backend' => '',
69+
'frontend' => '',
70+
'label' => 'Exclude Sitemap',
71+
'note' => 'Added by Mageplaza Sitemap',
72+
'input' => 'select',
73+
'class' => '',
74+
'source' => Boolean::class,
75+
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
76+
'visible' => true,
77+
'required' => false,
78+
'user_defined' => false,
79+
'default' => 0,
80+
'searchable' => false,
81+
'filterable' => false,
82+
'comparable' => false,
83+
'visible_on_front' => false,
84+
'used_in_product_listing' => true,
85+
'unique' => false,
86+
'group' => 'Search Engine Optimization',
87+
'sort_order' => 100,
88+
'apply_to' => '',
89+
]);
90+
}
91+
92+
$installer->endSetup();
93+
}
94+
}

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.1",
9+
"version": "4.1.0",
1010
"license": "proprietary",
1111
"authors": [
1212
{

0 commit comments

Comments
 (0)