Skip to content

Commit 3ce67cc

Browse files
Extract static source fields into their own dedicated provider
The product/category slug fields aren't tied to attributes or options, they don't belong in ProductAttributeSourceFieldProvider either.
1 parent e738e5e commit 3ce67cc

3 files changed

Lines changed: 51 additions & 12 deletions

File tree

src/Indexer/Provider/ProductAttributeSourceFieldProvider.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Sylius\Component\Resource\Repository\RepositoryInterface;
2020

2121
/**
22-
* Gally source field provider for Sylius product attributes, plus the plugin's static fields.
22+
* Gally source field provider for Sylius product attributes.
2323
*/
2424
class ProductAttributeSourceFieldProvider extends AbstractSourceFieldProvider
2525
{
@@ -39,16 +39,5 @@ public function provide(): iterable
3939
foreach ($this->productAttributeRepository->findAll() as $productAttribute) {
4040
yield $this->buildSourceField('product', $productAttribute);
4141
}
42-
43-
// Static fields are not tied to attributes or options, kept here to avoid a third provider.
44-
$staticSourceField = [
45-
'product' => ['slug' => 'text'],
46-
'category' => ['slug' => 'text'],
47-
];
48-
foreach ($staticSourceField as $entity => $fields) {
49-
foreach ($fields as $code => $type) {
50-
yield new SourceField($this->getMetadata($entity), $code, $this->getGallyType($type), $code, []);
51-
}
52-
}
5342
}
5443
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* DISCLAIMER
4+
*
5+
* Do not edit or add to this file if you wish to upgrade Gally to newer versions in the future.
6+
*
7+
* @package Gally
8+
* @author Stephan Hochdörfer <S.Hochdoerfer@bitexpert.de>, Gally Team <elasticsuite@smile.fr>
9+
* @copyright 2022-present Smile
10+
* @license Open Software License v. 3.0 (OSL-3.0)
11+
*/
12+
13+
declare(strict_types=1);
14+
15+
namespace Gally\SyliusPlugin\Indexer\Provider;
16+
17+
use Gally\Sdk\Entity\Metadata;
18+
use Gally\Sdk\Entity\SourceField;
19+
20+
/**
21+
* Gally source field provider for the plugin's built-in fields, not tied to any Sylius attribute or option.
22+
*/
23+
class StaticSourceFieldProvider implements ProviderInterface
24+
{
25+
public function getEntity(): string
26+
{
27+
return 'sourceField';
28+
}
29+
30+
/**
31+
* @return iterable<SourceField>
32+
*/
33+
public function provide(): iterable
34+
{
35+
$staticSourceField = [
36+
'product' => ['slug' => 'text'],
37+
'category' => ['slug' => 'text'],
38+
];
39+
40+
foreach ($staticSourceField as $entity => $fields) {
41+
$metadata = new Metadata($entity);
42+
foreach ($fields as $code => $type) {
43+
yield new SourceField($metadata, $code, $type, $code, []);
44+
}
45+
}
46+
}
47+
}

src/Resources/config/services/indexers.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
<argument type="service" id="sylius.context.locale" />
1010
<tag name="gally.dataprovider" entity="catalog"/>
1111
</service>
12+
<service id="Gally\SyliusPlugin\Indexer\Provider\StaticSourceFieldProvider">
13+
<tag name="gally.dataprovider" entity="sourceField"/>
14+
</service>
1215
<service id="Gally\SyliusPlugin\Indexer\Provider\ProductAttributeSourceFieldProvider">
1316
<argument type="service" id="Gally\SyliusPlugin\Indexer\Provider\CatalogProvider"/>
1417
<argument type="service" id="sylius.repository.product_attribute" />

0 commit comments

Comments
 (0)