Skip to content

Commit

Permalink
fix product attribute translation import using new locale mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGrimmChester committed Aug 1, 2023
1 parent 1a934ff commit 8059da9
Showing 1 changed file with 8 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,12 @@ public function process(string $attributeCode, array $context = []): void
/** @var AttributeInterface $attribute */
$attribute = $this->productAttributeRepository->findOneBy(['code' => $transformedAttributeCode]);

foreach ($context['data'] as $translation) {
if (null !== $translation['locale'] && false === $this->syliusAkeneoLocaleCodeProvider->isActiveLocale($translation['locale'])) {
continue;
}

if (null === $translation['locale']) {
foreach ($this->syliusAkeneoLocaleCodeProvider->getUsedLocalesOnBothPlatforms() as $locale) {
$this->setAttributeTranslation(
$context['model'],
$attribute,
$context['data'],
$locale,
$attributeCode,
$context['scope'],
);
}

continue;
}

foreach ($this->syliusAkeneoLocaleCodeProvider->getUsedLocalesOnBothPlatforms() as $syliusAkeneo) {
$this->setAttributeTranslation(
$context['model'],
$attribute,
$context['data'],
$translation['locale'],
$syliusAkeneo,
$attributeCode,
$context['scope'],
);
Expand All @@ -109,24 +90,26 @@ private function setAttributeTranslation(
ProductInterface $product,
AttributeInterface $attribute,
array $translations,
string $locale,
string $syliusLocale,
string $attributeCode,
string $scope,
): void {
$akeneoLocale = $this->syliusAkeneoLocaleCodeProvider->getAkeneoLocale($syliusLocale);

$attributeValue = $this->productAttributeValueRepository->findOneBy([
'subject' => $product,
'attribute' => $attribute,
'localeCode' => $locale,
'localeCode' => $syliusLocale,
]);

if (!$attributeValue instanceof ProductAttributeValueInterface) {
/** @var \Sylius\Component\Product\Model\ProductAttributeValueInterface $attributeValue */
$attributeValue = $this->productAttributeValueFactory->createNew();
}

$attributeValue->setLocaleCode($locale);
$attributeValue->setLocaleCode($syliusLocale);
$attributeValue->setAttribute($attribute);
$attributeValueValue = $this->akeneoAttributeDataProvider->getData($attributeCode, $translations, $locale, $scope);
$attributeValueValue = $this->akeneoAttributeDataProvider->getData($attributeCode, $translations, $akeneoLocale, $scope);
$attributeValue->setValue($attributeValueValue);
$product->addAttribute($attributeValue);
}
Expand Down

0 comments on commit 8059da9

Please sign in to comment.