diff --git a/src/Form/Provider/AttributeOptionsProvider.php b/src/Form/Provider/AttributeOptionsProvider.php index a7b8f5d..b45076f 100644 --- a/src/Form/Provider/AttributeOptionsProvider.php +++ b/src/Form/Provider/AttributeOptionsProvider.php @@ -29,13 +29,18 @@ class AttributeOptionsProvider implements AttributeOptionsProviderInterface /** @var RepositoryInterface */ private $productAttributeRepository; + /** @var string */ + private $localeCode; + public function __construct( ProductAttributeValueRepository $productAttributeValueRepository, - RepositoryInterface $productAttributeRepository + RepositoryInterface $productAttributeRepository, + string $localeCode ) { $this->productAttributeValueRepository = $productAttributeValueRepository; $this->productAttributeRepository = $productAttributeRepository; + $this->localeCode = $localeCode; } public function provideOptionsByAttributeCode(string $code): array @@ -49,7 +54,7 @@ public function provideOptionsByAttributeCode(string $code): array $qb->andWhere('av.attribute = :attribute'); $qb->andWhere('av.localeCode = :localeCode'); $qb->setParameter(':attribute', $attribute->getId()); - $qb->setParameter(':localeCode', 'en_US'); + $qb->setParameter(':localeCode', $this->localeCode); $choices = []; foreach($qb->getQuery()->getResult() as $value) { diff --git a/src/Matcher/SizeChartValidator.php b/src/Matcher/SizeChartValidator.php index 8c8eaf4..b7153ca 100644 --- a/src/Matcher/SizeChartValidator.php +++ b/src/Matcher/SizeChartValidator.php @@ -22,6 +22,16 @@ final class SizeChartValidator implements SizeChartValidatorInterface { + /** @var string */ + private $localeCode; + + public function __construct( + string $localeCode + ) + { + $this->localeCode = $localeCode; + } + public function isValidForTheProduct(SizeChartInterface $sizeChart, ProductInterface $product): bool { $criteria = $sizeChart->getCriteria(); @@ -32,7 +42,7 @@ public function isValidForTheProduct(SizeChartInterface $sizeChart, ProductInter foreach($attributeCodes as $attributeCode) { /** @var string $value */ $value = $criteria['attribute' . $attributeCode ] ?? ''; - $productAttributeValue = $product->getAttributeByCodeAndLocale($attributeCode, 'en_US'); + $productAttributeValue = $product->getAttributeByCodeAndLocale($attributeCode, $this->localeCode); if (!$productAttributeValue || $productAttributeValue->getValue() !== $value) { return false; diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 7f05740..984bb21 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -12,7 +12,10 @@ Architects of this package: @author Piotr Lewandowski --> - + + @@ -26,7 +29,10 @@ Architects of this package: - + + %locale% + diff --git a/src/Resources/config/services/forms.xml b/src/Resources/config/services/forms.xml index 06e98bf..020414e 100644 --- a/src/Resources/config/services/forms.xml +++ b/src/Resources/config/services/forms.xml @@ -8,6 +8,7 @@ class="Madcoders\SyliusSizechartPlugin\Form\Provider\AttributeOptionsProvider"> + %locale%