Skip to content

Commit

Permalink
Merge pull request #99 from lruozzi9/patch-2
Browse files Browse the repository at this point in the history
Use current attribute option value if it is not translatable
  • Loading branch information
maximehuran committed Jun 30, 2023
2 parents 2f0058f + 16b6ba4 commit 7ef3aba
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/Model/Documentable/DocumentableProductTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use MonsieurBiz\SyliusSearchPlugin\generated\Model\Taxon as DocumentTaxon;
use MonsieurBiz\SyliusSearchPlugin\Model\Document\Result;
use MonsieurBiz\SyliusSearchPlugin\Model\Document\ResultInterface;
use Sylius\Component\Attribute\AttributeType\SelectAttributeType;
use Sylius\Component\Attribute\Model\AttributeValueInterface;
use Sylius\Component\Core\Model\Channel;
use Sylius\Component\Core\Model\Image;
Expand Down Expand Up @@ -173,17 +174,27 @@ protected function addTaxonsInDocument(ResultInterface $document, string $locale
*/
protected function addAttributesInDocument(ResultInterface $document, string $locale): ResultInterface
{
/** @var AttributeValueInterface $attribute */
foreach ($this->getAttributesByLocale($locale, $locale) as $attribute) {
$attributeValues = [];
if (isset($attribute->getAttribute()->getConfiguration()['choices'])) {
foreach ($attribute->getValue() as $value) {
$attributeValues[] = $attribute->getAttribute()->getConfiguration()['choices'][$value][$locale];
/** @var AttributeValueInterface $attributeValue */
foreach ($this->getAttributesByLocale($locale, $locale) as $attributeValue) {
$productAttributeValues = [];
$attribute = $attributeValue->getAttribute();
if ($attribute === null) {
continue;
}
if ($attribute->getType() === SelectAttributeType::TYPE) {
// Add all the selected values in the current locale if it exists, otherwise use the current value
foreach ($attributeValue->getValue() as $value) {
if (isset($attribute->getConfiguration()['choices'][$value][$locale])) {
$productAttributeValues[] = $attribute->getConfiguration()['choices'][$value][$locale];

continue;
}
$productAttributeValues[] = $value;
}
} else {
$attributeValues[] = $attribute->getValue();
$productAttributeValues[] = $attributeValue->getValue();
}
$document->addAttribute($attribute->getCode(), $attribute->getName(), $attributeValues, $attribute->getLocaleCode() ?? $locale, 1);
$document->addAttribute($attributeValue->getCode(), $attributeValue->getName(), $productAttributeValues, $attributeValue->getLocaleCode() ?? $locale, 1);
}

return $document;
Expand Down

0 comments on commit 7ef3aba

Please sign in to comment.