Skip to content

Commit

Permalink
feat: Add sitemap category html in sitemap.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
kpitn committed Apr 18, 2024
1 parent 8fcbd8b commit 322e192
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Model/Sitemap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace Web200\Seo\Model;

use Magento\Sitemap\Model\ItemProvider\ItemProviderInterface;
use Magento\Sitemap\Model\SitemapItemInterfaceFactory;
use Web200\Seo\Provider\SitemapConfig;

/**
* Class Sitemap
*
* @package Web200\Seo\Model
* @author Web200 <contact@web200.fr>
* @copyright 2024 Web200
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://www.web200.fr/
*/
class Sitemap implements ItemProviderInterface
{
/**
* @param SitemapItemInterfaceFactory $itemFactory
* @param SitemapConfig $sitemapConfig
*/
public function __construct(
protected SitemapItemInterfaceFactory $itemFactory,
protected SitemapConfig $sitemapConfig
) {
}

/**
* {@inheritdoc}
*/
public function getItems($storeId)
{
if ($this->sitemapConfig->isCategoryActive()) {
return [
$this->itemFactory->create([
'url' => $this->sitemapConfig->getCategoryUrlKey(),
'priority' => 0.5,
'changeFrequency' => 'weekly',
])
];
}

return [];
}
}
7 changes: 7 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@
<plugin name="display_canonical_preference_product_store"
type="Web200\Seo\Plugin\DisplayCanonicalPreferenceProductStore"/>
</type>
<type name="Magento\Sitemap\Model\ItemProvider\Composite">
<arguments>
<argument name="itemProviders" xsi:type="array">
<item name="seoProvider" xsi:type="object">Web200\Seo\Model\Sitemap</item>
</argument>
</arguments>
</type>
</config>

0 comments on commit 322e192

Please sign in to comment.