Skip to content

Commit eb87857

Browse files
committed
Add little fixes
1 parent 5994d6e commit eb87857

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ script:
6868

6969
- bin/phpunit
7070
- bin/phpspec run
71-
- bin/behat --strict -vvv --no-interaction || bin/behat --strict -vvv --no-interaction --rerun
71+
- bin/behat
7272

7373
after_failure:
7474
- vendor/lakion/mink-debug-extension/travis/tools/upload-textfiles "${SYLIUS_BUILD_DIR}/*.log"

src/Form/Type/ChoiceMapper/ProductAttributesMapper.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace BitBag\SyliusElasticsearchPlugin\Form\Type\ChoiceMapper;
1414

1515
use BitBag\SyliusElasticsearchPlugin\Formatter\StringFormatterInterface;
16+
use Sylius\Component\Locale\Context\LocaleContextInterface;
1617
use Sylius\Component\Product\Model\ProductAttributeInterface;
1718
use Sylius\Component\Product\Model\ProductAttributeValueInterface;
1819
use Sylius\Component\Product\Repository\ProductAttributeValueRepositoryInterface;
@@ -24,20 +25,29 @@ final class ProductAttributesMapper implements ProductAttributesMapperInterface
2425
*/
2526
private $productAttributeValueRepository;
2627

28+
/**
29+
* @var LocaleContextInterface
30+
*/
31+
private $localeContext;
32+
2733
/**
2834
* @var StringFormatterInterface
2935
*/
3036
private $stringFormatter;
3137

3238
/**
3339
* @param ProductAttributeValueRepositoryInterface $productAttributeValueRepository
40+
* @param LocaleContextInterface $localeContext
3441
* @param StringFormatterInterface $stringFormatter
3542
*/
3643
public function __construct(
3744
ProductAttributeValueRepositoryInterface $productAttributeValueRepository,
45+
LocaleContextInterface $localeContext,
3846
StringFormatterInterface $stringFormatter
39-
) {
47+
)
48+
{
4049
$this->productAttributeValueRepository = $productAttributeValueRepository;
50+
$this->localeContext = $localeContext;
4151
$this->stringFormatter = $stringFormatter;
4252
}
4353

@@ -50,13 +60,18 @@ public function mapToChoices(ProductAttributeInterface $productAttribute): array
5060
$choices = [];
5161
array_walk($attributeValues, function (ProductAttributeValueInterface $productAttributeValue) use (&$choices) {
5262
$value = $productAttributeValue->getValue();
53-
if (is_array($value)) {
63+
$configuration = $productAttributeValue->getAttribute()->getConfiguration();
64+
if (is_array($value)
65+
&& isset($configuration['choices'])
66+
&& is_array($configuration['choices'])) {
5467
foreach ($value as $singleValue) {
55-
$choices[$singleValue] = $this->stringFormatter->formatToLowercaseWithoutSpaces($singleValue);
68+
$choice = $this->stringFormatter->formatToLowercaseWithoutSpaces($singleValue);
69+
$label = $configuration['choices'][$singleValue][$this->localeContext->getLocaleCode()];
70+
$choices[$label] = $choice;
5671
}
5772
} else {
58-
$choiceValue = is_string($value) ? $this->stringFormatter->formatToLowercaseWithoutSpaces($value) : $value;
59-
$choices[$value] = $choiceValue;
73+
$choice = is_string($value) ? $this->stringFormatter->formatToLowercaseWithoutSpaces($value) : $value;
74+
$choices[$value] = $choice;
6075
}
6176
});
6277

src/QueryBuilder/HasPriceBetweenQueryBuilder.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public function __construct(
4444
PriceNameResolverInterface $priceNameResolver,
4545
ConcatedNameResolverInterface $channelPricingNameResolver,
4646
ChannelContextInterface $channelContext
47-
) {
47+
)
48+
{
4849
$this->channelPricingNameResolver = $channelPricingNameResolver;
4950
$this->priceNameResolver = $priceNameResolver;
5051
$this->channelContext = $channelContext;
@@ -55,20 +56,19 @@ public function __construct(
5556
*/
5657
public function buildQuery(array $data): ?AbstractQuery
5758
{
58-
$minPrice = $data[$this->priceNameResolver->resolveMinPriceName()];
59-
$maxPrice = $data[$this->priceNameResolver->resolveMaxPriceName()];
59+
$dataMinPrice = $data[$this->priceNameResolver->resolveMinPriceName()];
60+
$dataMaxPrice = $data[$this->priceNameResolver->resolveMaxPriceName()];
6061

61-
if (!$minPrice || !$maxPrice) {
62-
return null;
63-
}
62+
$minPrice = $dataMinPrice ? $this->getPriceFromString($dataMinPrice) : 0;
63+
$maxPrice = $dataMaxPrice ? $this->getPriceFromString($dataMaxPrice) : PHP_INT_MAX;
6464

6565
$channelCode = $this->channelContext->getChannel()->getCode();
6666
$propertyName = $this->channelPricingNameResolver->resolvePropertyName($channelCode);
6767
$rangeQuery = new Range();
6868

6969
$rangeQuery->setParam($propertyName, [
70-
'gte' => $this->getPriceFromString($minPrice),
71-
'lt' => $this->getPriceFromString($maxPrice),
70+
'gte' => $minPrice,
71+
'lt' => $maxPrice,
7272
]);
7373

7474
return $rangeQuery;

src/Resources/config/services/form.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ services:
4343
class: BitBag\SyliusElasticsearchPlugin\Form\Type\ChoiceMapper\ProductAttributesMapper
4444
arguments:
4545
- "@sylius.repository.product_attribute_value"
46+
- "@sylius.context.locale"
4647
- "@bitbag.sylius_elasticsearch_plugin.string_formatter"

0 commit comments

Comments
 (0)