diff --git a/README.md b/README.md
index a375fd7d..28e8a147 100644
--- a/README.md
+++ b/README.md
@@ -48,6 +48,10 @@ Get a full list of configuration: `bin/console config:dump-reference sitemap`
```yaml
sitemap:
+ providers:
+ products: true
+ taxons: true
+ static: true
template: '@SitemapPlugin/show.xml.twig'
index_template: '@SitemapPlugin/index.xml.twig'
exclude_taxon_root: true
@@ -60,6 +64,7 @@ sitemap:
### Feature switches
+* `providers`: Enable/disable certain providers to be included in the sitemap. Defaults are true.
* `exclude_taxon_root`: Often you don't want to include the root of your taxon tree as it has a generic name as 'products'.
* `absolute_url`: Whether to generate absolute URL's (true) or relative (false). Defaults to true.
* `hreflang`: Whether to generate alternative URL versions for each locale. Defaults to true. Background: https://support.google.com/webmasters/answer/189077?hl=en.
diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php
index 8abd9004..17522ede 100644
--- a/src/DependencyInjection/Configuration.php
+++ b/src/DependencyInjection/Configuration.php
@@ -31,6 +31,14 @@ private function addSitemapSection(ArrayNodeDefinition $node): void
{
$node
->children()
+ ->arrayNode('providers')
+ ->addDefaultsIfNotSet()
+ ->children()
+ ->booleanNode('products')->defaultTrue()->end()
+ ->booleanNode('taxons')->defaultTrue()->end()
+ ->booleanNode('static')->defaultTrue()->end()
+ ->end()
+ ->end()
->scalarNode('template')
->defaultValue('@SitemapPlugin/show.xml.twig')
->end()
diff --git a/src/DependencyInjection/SitemapExtension.php b/src/DependencyInjection/SitemapExtension.php
index c3312c02..9a05fb14 100644
--- a/src/DependencyInjection/SitemapExtension.php
+++ b/src/DependencyInjection/SitemapExtension.php
@@ -28,5 +28,14 @@ public function load(array $config, ContainerBuilder $container)
$container->setParameter('sylius.sitemap_absolute_url', $config['absolute_url']);
$container->setParameter('sylius.sitemap_hreflang', $config['hreflang']);
$container->setParameter('sylius.sitemap_static', $config['static_routes']);
+
+ foreach ($config['providers'] as $provider => $setting) {
+ $parameter = sprintf('sylius.provider.%s', $provider);
+ $container->setParameter($parameter, $setting);
+
+ if ($setting === true) {
+ $loader->load(sprintf('services/providers/%s.xml', $provider));
+ }
+ }
}
}
diff --git a/src/Resources/config/services/providers/products.xml b/src/Resources/config/services/providers/products.xml
new file mode 100644
index 00000000..14cb8926
--- /dev/null
+++ b/src/Resources/config/services/providers/products.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Resources/config/services/providers/static.xml b/src/Resources/config/services/providers/static.xml
new file mode 100644
index 00000000..18c04d1a
--- /dev/null
+++ b/src/Resources/config/services/providers/static.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+ %sylius.sitemap_static%
+
+
+
+
diff --git a/src/Resources/config/services/providers/taxons.xml b/src/Resources/config/services/providers/taxons.xml
new file mode 100644
index 00000000..34d42c37
--- /dev/null
+++ b/src/Resources/config/services/providers/taxons.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+ %sylius.sitemap_exclude_taxon_root%
+
+
+
+
diff --git a/src/Resources/config/services/sitemap.xml b/src/Resources/config/services/sitemap.xml
index 22bb08b5..6fb41007 100644
--- a/src/Resources/config/services/sitemap.xml
+++ b/src/Resources/config/services/sitemap.xml
@@ -48,32 +48,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- %sylius.sitemap_exclude_taxon_root%
-
-
-
-
-
-
-
- %sylius.sitemap_static%
-
-
-
diff --git a/tests/DependencyInjection/Compiler/SitemapParameterTest.php b/tests/DependencyInjection/Compiler/SitemapParameterTest.php
new file mode 100644
index 00000000..3cec7ccf
--- /dev/null
+++ b/tests/DependencyInjection/Compiler/SitemapParameterTest.php
@@ -0,0 +1,110 @@
+
+ */
+class SitemapParameterTest extends AbstractExtensionTestCase
+{
+ /**
+ * @test
+ * @dataProvider providers
+ */
+ public function it_has_providers_enabled_by_default_with_parameter(
+ array $config,
+ bool $products,
+ bool $taxons,
+ bool $static
+ ) {
+ $this->load($config);
+
+ $this->assertContainerBuilderHasParameter(sprintf('sylius.provider.%s', 'products'), $products);
+ $this->assertContainerBuilderHasParameter(sprintf('sylius.provider.%s', 'taxons'), $taxons);
+ $this->assertContainerBuilderHasParameter(sprintf('sylius.provider.%s', 'static'), $static);
+
+ if ($products) {
+ $this->assertContainerBuilderHasService('sylius.sitemap_provider.product', \SitemapPlugin\Provider\ProductUrlProvider::class);
+ $this->assertContainerBuilderHasServiceDefinitionWithTag('sylius.sitemap_provider.product', 'sylius.sitemap_provider');
+ }
+ else {
+ $this->assertContainerBuilderNotHasService('sylius.sitemap_provider.product');
+ }
+
+ if ($taxons) {
+ $this->assertContainerBuilderHasService('sylius.sitemap_provider.taxon', \SitemapPlugin\Provider\TaxonUrlProvider::class);
+ $this->assertContainerBuilderHasServiceDefinitionWithTag('sylius.sitemap_provider.taxon', 'sylius.sitemap_provider');
+
+ }
+ else {
+ $this->assertContainerBuilderNotHasService('sylius.sitemap_provider.taxon');
+ }
+
+ if ($static) {
+ $this->assertContainerBuilderHasService('sylius.sitemap_provider.static', \SitemapPlugin\Provider\StaticUrlProvider::class);
+ $this->assertContainerBuilderHasServiceDefinitionWithTag('sylius.sitemap_provider.static', 'sylius.sitemap_provider');
+
+ }
+ else {
+ $this->assertContainerBuilderNotHasService('sylius.sitemap_provider.static');
+ }
+ }
+
+ /**
+ * @return array
+ */
+ public function providers(): array
+ {
+ return [
+ [
+ ['providers' => [
+ 'products' => true,
+ 'taxons' => true,
+ 'static' => true,
+ ]],
+ true,
+ true,
+ true
+ ],
+ [
+ ['providers' => []],
+ true,
+ true,
+ true,
+ ],
+ [
+ ['providers' => [
+ 'products' => false,
+ 'taxons' => false,
+ 'static' => false,
+ ]],
+ false,
+ false,
+ false
+ ],
+ [
+ ['providers' => [
+ 'products' => true,
+ 'taxons' => false,
+ 'static' => true,
+ ]],
+ true,
+ false,
+ true,
+ ],
+ ];
+ }
+
+ /**
+ * @return array
+ */
+ protected function getContainerExtensions()
+ {
+ return array(
+ new SitemapExtension()
+ );
+ }
+}