Skip to content

Commit 81c4cbc

Browse files
committed
6721-Magefan-Blog-Sitemap
1 parent de62e64 commit 81c4cbc

File tree

3 files changed

+15
-89
lines changed

3 files changed

+15
-89
lines changed

Model/Sitemap.php

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,6 @@
2121
*/
2222
class Sitemap extends \Magento\Sitemap\Model\Sitemap
2323
{
24-
private $state;
25-
26-
public function __construct(
27-
\Magento\Framework\Model\Context $context,
28-
\Magento\Framework\Registry $registry,
29-
\Magento\Framework\Escaper $escaper,
30-
\Magento\Sitemap\Helper\Data $sitemapData,
31-
\Magento\Framework\Filesystem $filesystem,
32-
\Magento\Sitemap\Model\ResourceModel\Catalog\CategoryFactory $categoryFactory,
33-
\Magento\Sitemap\Model\ResourceModel\Catalog\ProductFactory $productFactory,
34-
\Magento\Sitemap\Model\ResourceModel\Cms\PageFactory $cmsFactory,
35-
\Magento\Framework\Stdlib\DateTime\DateTime $modelDate,
36-
\Magento\Store\Model\StoreManagerInterface $storeManager,
37-
\Magento\Framework\App\RequestInterface $request,
38-
\Magento\Framework\Stdlib\DateTime $dateTime,
39-
\Magento\Framework\App\State $state,
40-
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
41-
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
42-
array $data = [],
43-
\Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot $documentRoot = null,
44-
ItemProviderInterface $itemProvider = null,
45-
SitemapConfigReaderInterface $configReader = null,
46-
\Magento\Sitemap\Model\SitemapItemInterfaceFactory $sitemapItemFactory = null
47-
) {
48-
parent::__construct($context, $registry, $escaper, $sitemapData, $filesystem, $categoryFactory, $productFactory, $cmsFactory, $modelDate, $storeManager, $request, $dateTime, $resource, $resourceCollection, $data, $documentRoot, $itemProvider, $configReader, $sitemapItemFactory);
49-
$this->state = $state;
50-
}
51-
5224
/**
5325
* Initialize sitemap items
5426
*
@@ -175,52 +147,4 @@ public function getSitemapPath(): string
175147
}
176148
return $path;
177149
}
178-
179-
public function generateXml()
180-
{
181-
$this->state->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND);
182-
$this->_initSitemapItems();
183-
184-
/** @var $item SitemapItemInterface */
185-
foreach ($this->_sitemapItems as $item) {
186-
$xml = $this->_getSitemapRow(
187-
$item->getUrl(),
188-
$item->getUpdatedAt(),
189-
$item->getChangeFrequency(),
190-
$item->getPriority(),
191-
$item->getImages()
192-
);
193-
194-
if ($this->_isSplitRequired($xml) && $this->_sitemapIncrement > 0) {
195-
$this->_finalizeSitemap();
196-
}
197-
198-
if (!$this->_fileSize) {
199-
$this->_createSitemap();
200-
}
201-
202-
$this->_writeSitemapRow($xml);
203-
// Increase counters
204-
$this->_lineCount++;
205-
$this->_fileSize += strlen($xml);
206-
}
207-
208-
$this->_finalizeSitemap();
209-
210-
if ($this->_sitemapIncrement == 1) {
211-
// In case when only one increment file was created use it as default sitemap
212-
$path = rtrim($this->getSitemapPath(), '/')
213-
. '/'
214-
. $this->_getCurrentSitemapFilename($this->_sitemapIncrement);
215-
$this->setSitemapPath($path);
216-
} else {
217-
// Otherwise create index file with list of generated sitemaps
218-
$this->_createSitemapIndex();
219-
}
220-
221-
$this->setSitemapTime($this->_dateModel->gmtDate('Y-m-d H:i:s'));
222-
$this->save();
223-
224-
return $this;
225-
}
226150
}

Plugin/Magento/Sitemap/AmastySitemapPlugin.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
use Magefan\Blog\Model\CategoryFactory;
1212
use Magefan\Blog\Model\PostFactory;
13-
use Magento\Framework\DataObject;
14-
use Magento\Sitemap\Model\Sitemap;
1513

1614
/**
1715
* Plugin for sitemap generation
@@ -55,17 +53,21 @@ public function __construct(
5553
\Magefan\Blog\Model\SitemapFactory $sitemapFactory,
5654
CategoryFactory $categoryFactory,
5755
PostFactory $postFactory,
58-
$config = null
56+
\Magefan\Blog\Model\Config $config
5957
) {
6058
$this->postFactory = $postFactory;
6159
$this->categoryFactory = $categoryFactory;
6260
$this->sitemapFactory = $sitemapFactory;
63-
64-
$this->config = $config ?: \Magento\Framework\App\ObjectManager::getInstance()
65-
->get(\Magefan\Blog\Model\Config::class);
61+
$this->config = $config;
6662
}
6763

68-
public function afterGenerate(\Amasty\XmlSitemap\Model\XmlGenerator $subject, $result, $sitemap) {
64+
/**
65+
* @param $subject
66+
* @param $result
67+
* @param $sitemap
68+
* @return mixed
69+
*/
70+
public function afterGenerate($subject, $result, $sitemap) {
6971

7072
$sitemapId = $sitemap->getId() ?: 0;
7173
if (in_array($sitemapId, $this->generated)) {
@@ -83,7 +85,7 @@ public function afterGenerate(\Amasty\XmlSitemap\Model\XmlGenerator $subject, $r
8385
}
8486

8587
/* Fix for Amasty\XmlSitemap\Model\Sitemap */
86-
if (get_class($sitemap) === 'Amasty\XmlSitemap\Model\Sitemap') {
88+
if ($sitemap instanceof \Amasty\XmlSitemap\Api\SitemapInterface ) {
8789
if ($sitemap->getFilePath()) {
8890
$filepath = $sitemap->getFilePath();
8991
$pathArray = explode('/', $filepath);
@@ -93,8 +95,8 @@ public function afterGenerate(\Amasty\XmlSitemap\Model\XmlGenerator $subject, $r
9395
$blogSitemap->setSitemapFilename('blog_sitemap.xml');
9496
$blogSitemap->setSitemapPath($blogFilepath);
9597
}
98+
$blogSitemap->generateXml();
9699
}
97-
$blogSitemap->generateXml();
98100

99101
return $result;
100102
}

etc/di.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@
6161
type="Magefan\Blog\Plugin\Magento\Sitemap\SitemapPlugin" sortOrder="10"/>
6262
</type>
6363

64-
<!-- <type name="Amasty\XmlSitemap\Model\Sitemap">-->
65-
<!-- <plugin name="amasty_sitemap_model_sitemap_magefan_blog"-->
66-
<!-- type="Magefan\Blog\Plugin\Magento\Sitemap\SitemapPlugin" sortOrder="10"/>-->
67-
<!-- </type>-->
64+
<type name="Amasty\XmlSitemap\Model\Sitemap">
65+
<plugin name="amasty_sitemap_model_sitemap_magefan_blog"
66+
type="Magefan\Blog\Plugin\Magento\Sitemap\SitemapPlugin" sortOrder="10"/>
67+
</type>
6868

6969
<type name="Amasty\XmlSitemap\Model\XmlGenerator">
7070
<plugin name="amasty_sitemap_model_sitemap_magefan_blog"

0 commit comments

Comments
 (0)