Skip to content

Commit 796e9f6

Browse files
committed
Fix repository
1 parent 34ad5f0 commit 796e9f6

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

src/EntityRepository/ProductVariantRepository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function findOneByOptionValue(ProductOptionValueInterface $productOptionV
4141
->where(':optionValue MEMBER OF o.optionValues')
4242
->setParameter('optionValue', $productOptionValue)
4343
->getQuery()
44+
->setMaxResults(1)
4445
->getOneOrNullResult()
4546
;
4647

src/Form/Type/ChoiceMapper/ProductOptionsMapper.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,38 @@
1212

1313
namespace BitBag\SyliusElasticsearchPlugin\Form\Type\ChoiceMapper;
1414

15+
use BitBag\SyliusElasticsearchPlugin\Formatter\StringFormatterInterface;
1516
use Sylius\Component\Product\Model\ProductOptionInterface;
1617
use Sylius\Component\Product\Model\ProductOptionValueInterface;
1718

1819
final class ProductOptionsMapper implements ProductOptionsMapperInterface
1920
{
21+
/**
22+
* @var StringFormatterInterface
23+
*/
24+
private $stringFormatter;
25+
26+
/**
27+
* @param StringFormatterInterface $stringFormatter
28+
*/
29+
public function __construct(StringFormatterInterface $stringFormatter)
30+
{
31+
$this->stringFormatter = $stringFormatter;
32+
}
33+
2034
/**
2135
* {@inheritdoc}
2236
*/
2337
public function mapToChoices(ProductOptionInterface $productOption): array
2438
{
25-
$optionValues = array_map(function (ProductOptionValueInterface $productOptionValue): ?string {
26-
return $productOptionValue->getValue();
27-
}, $productOption->getValues()->toArray());
39+
$productOptionValues = $productOption->getValues()->toArray();
40+
$choices = [];
41+
42+
array_walk($productOptionValues, function (ProductOptionValueInterface $productOptionValue) use (&$choices) {
43+
$value = $productOptionValue->getValue();
44+
$choices[$value] = $this->stringFormatter->formatToLowercaseWithoutSpaces($value);
45+
});
2846

29-
return array_combine($optionValues, $optionValues);
47+
return $choices;
3048
}
3149
}

src/PropertyBuilder/OptionBuilder.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace BitBag\SyliusElasticsearchPlugin\PropertyBuilder;
1414

15+
use BitBag\SyliusElasticsearchPlugin\Formatter\StringFormatterInterface;
1516
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface;
1617
use Elastica\Document;
1718
use FOS\ElasticaBundle\Event\TransformEvent;
@@ -24,12 +25,19 @@ final class OptionBuilder extends AbstractBuilder
2425
*/
2526
private $optionNameResolver;
2627

28+
/**
29+
* @var StringFormatterInterface
30+
*/
31+
private $stringFormatter;
32+
2733
/**
2834
* @param ConcatedNameResolverInterface $optionNameResolver
35+
* @param StringFormatterInterface $stringFormatter
2936
*/
30-
public function __construct(ConcatedNameResolverInterface $optionNameResolver)
37+
public function __construct(ConcatedNameResolverInterface $optionNameResolver, StringFormatterInterface $stringFormatter)
3138
{
3239
$this->optionNameResolver = $optionNameResolver;
40+
$this->stringFormatter = $stringFormatter;
3341
}
3442

3543
/**
@@ -65,7 +73,7 @@ private function resolveProductOptions(ProductInterface $product, Document $docu
6573
}
6674

6775
$reference = $document->get($index);
68-
$value = $productOptionValue->getValue();
76+
$value = $this->stringFormatter->formatToLowercaseWithoutSpaces($productOptionValue->getValue());
6977
$reference[] = $value;
7078

7179
$document->set($index, array_unique($reference));

src/Resources/config/services/form.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ services:
3838

3939
bitbag_sylius_elasticsearch_plugin.form.type.choice_mapper.product_options:
4040
class: BitBag\SyliusElasticsearchPlugin\Form\Type\ChoiceMapper\ProductOptionsMapper
41+
arguments:
42+
- "@bitbag.sylius_elasticsearch_plugin.string_formatter"
4143

4244
bitbag_sylius_elasticsearch_plugin.form.type.choice_mapper.product_attributes:
4345
class: BitBag\SyliusElasticsearchPlugin\Form\Type\ChoiceMapper\ProductAttributesMapper

src/Resources/config/services/property_builder.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ services:
1414
class: BitBag\SyliusElasticsearchPlugin\PropertyBuilder\OptionBuilder
1515
arguments:
1616
- "@bitbag_sylius_elasticsearch_plugin.property_name_resolver.option"
17+
- "@bitbag.sylius_elasticsearch_plugin.string_formatter"
1718
tags:
1819
- { name: kernel.event_subscriber }
1920

0 commit comments

Comments
 (0)