Skip to content

Commit f1baa4b

Browse files
authored
Merge pull request #403 from magefan/5564-Sitemap-Query-Amasty
5564-Sitemap-Query-Amasty
2 parents 5c2e3d6 + a412503 commit f1baa4b

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

Model/Sitemap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function save()
135135
*/
136136
public function getSitemapPath(): string
137137
{
138-
$path = $this->getData('sitemap_path');
138+
$path = (string)$this->getData('sitemap_path');
139139
if ($serverPath = $this->getServerPath()) {
140140
if (!$this->_directory->isDirectory($serverPath)) {
141141
$serverPath = BP . '/' . $serverPath;

Plugin/Magento/Sitemap/SitemapPlugin.php

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,40 @@ public function __construct(
7575
public function afterGenerateXml(\Magento\Framework\Model\AbstractModel $sitemap, $result)
7676
{
7777
if ($this->isEnabled($sitemap)) {
78-
/* if ($this->isMageWorxXmlSitemap($sitemap) || !method_exists($sitemap, 'collectSitemapItems')) { */
79-
$sitemapId = $sitemap->getId() ?: 0;
78+
$sitemapId = $sitemap->getId() ?: 0;
8079
if (in_array($sitemapId, $this->generated)) {
8180
return $result;
8281
}
83-
$this->generated[] = $sitemapId;
82+
$this->generated[] = $sitemapId;
8483

85-
$blogSitemap = $this->sitemapFactory->create();
86-
$blogSitemap->setData(
87-
$sitemap->getData()
88-
);
84+
$blogSitemap = $this->sitemapFactory->create();
85+
$blogSitemap->setData(
86+
$sitemap->getData()
87+
);
8988

90-
$blogSitemap->setSitemapFilename(
91-
'blog_' . $sitemap->getSitemapFilename()
92-
);
89+
if (!$blogSitemap->getSitemapId() && $sitemap->getId()) {
90+
$blogSitemap->setSitemapId($sitemap->getId());
91+
}
92+
93+
/* Fix for Amasty\XmlSitemap\Model\Sitemap */
94+
if ($sitemap->getFolderName()) {
95+
$filename = pathinfo($sitemap->getFolderName());
96+
if (!$blogSitemap->getSitemapFilename()) {
97+
if (isset($filename['basename'])) {
98+
$blogSitemap->setSitemapFilename($filename['basename']);
99+
}
100+
}
101+
if (!$blogSitemap->getSitemapPath()) {
102+
if (isset($filename['dirname'])) {
103+
$blogSitemap->setSitemapPath($filename['dirname']);
104+
}
105+
}
106+
}
93107

94-
$blogSitemap->generateXml();
95-
/* } */
108+
$blogSitemap->setSitemapFilename(
109+
'blog_' . $blogSitemap->getSitemapFilename()
110+
);
111+
$blogSitemap->generateXml();
96112
}
97113
return $result;
98114
}

etc/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
type="Magefan\Blog\Plugin\Magento\Sitemap\SitemapPlugin" sortOrder="10"/>
6161
</type>
6262

63+
<type name="Amasty\XmlSitemap\Model\Sitemap">
64+
<plugin name="amasty_sitemap_model_sitemap_magefan_blog"
65+
type="Magefan\Blog\Plugin\Magento\Sitemap\SitemapPlugin" sortOrder="10"/>
66+
</type>
67+
6368
<type name="Magento\AdminGws\Model\Models">
6469
<plugin name="magefan_blog_plugin_admingws_model_models_plugin" type="\Magefan\Blog\Plugin\Magento\AdminGws\Model\ModelsPlugin" sortOrder="10"/>
6570
</type>

0 commit comments

Comments
 (0)