Skip to content

Commit

Permalink
Skip not defined locales in ImmutableSlugValueHandler (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmenozzi committed Jul 23, 2021
1 parent fe78de5 commit ed92821
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/ValueHandler/ImmutableSlugValueHandlerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,16 @@ function it_avoid_to_set_duplicated_slug_on_product_translation(

$productTranslation->setSlug(self::SLUGIFIED_VALUE . '-2')->shouldHaveBeenCalled();
}

function it_skips_locales_not_specified_in_sylius(
ProductVariantInterface $productVariant,
ProductInterface $product,
ProductTranslationInterface $productTranslation
) {
$productVariant->getProduct()->willReturn($product);

$this->handle($productVariant, self::AKENEO_ATTRIBUTE, [['locale' => 'es_ES', 'scope' => null, 'data' => 'New value']]);

$productTranslation->setSlug(Argument::type('string'))->shouldNotHaveBeenCalled();
}
}
5 changes: 5 additions & 0 deletions src/ValueHandler/ImmutableSlugValueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public function handle($subject, string $attribute, array $value): void

continue;
}

if (!in_array($localeCode, $this->translationLocaleProvider->getDefinedLocalesCodes(), true)) {
continue;
}

$productTranslation = $this->getOrCreateNewProductTranslation($product, $localeCode);
if ($productTranslation->getSlug()) {
continue;
Expand Down

0 comments on commit ed92821

Please sign in to comment.