diff --git a/docs/book/products/attributes.rst b/docs/book/products/attributes.rst index 960c21824ef..3972e9942a6 100644 --- a/docs/book/products/attributes.rst +++ b/docs/book/products/attributes.rst @@ -34,6 +34,16 @@ What these types may be useful for? - datetime - accurate date and time of an event - select - genre(s) of a book. one or more of them can be selected +Non-translatable attribute +-------------------------- + +Some attributes (dates, author name) don't need a different value in each locale. For those attributes, we introduced the possibility to disable translation. +Shop Owner declares values only once and regardless of the chosen locale customer will see a proper attribute value. + +Warning + +Once the attribute has disabled translatability it will erase attribute values in all locales for this attribute. + How to create an Attribute? --------------------------- diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductAttributeExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductAttributeExampleFactory.php index abc00bbce9e..42d9dda886d 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductAttributeExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductAttributeExampleFactory.php @@ -83,9 +83,7 @@ protected function configureOptions(OptionsResolver $resolver): void return $words; }) - ->setDefault('translatable', function(Options $options): bool { - return true; - }) + ->setDefault('translatable', true) ->setDefault('code', function (Options $options): string { return StringInflector::nameToCode($options['name']); }) diff --git a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductExampleFactory.php b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductExampleFactory.php index d8fd6afab2b..82156afab5e 100644 --- a/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductExampleFactory.php +++ b/src/Sylius/Bundle/CoreBundle/Fixture/Factory/ProductExampleFactory.php @@ -365,14 +365,15 @@ private function setAttributeValues(array $productAttributes): array Assert::notNull($productAttribute, sprintf('Can not find product attribute with code: "%s"', $code)); - if ($productAttribute->isTranslatable()) { - foreach ($this->getLocales() as $localeCode) { - $productAttributesValues[] = $this->configureProductAttributeValue($productAttribute, $localeCode, $value); - } - } else { + if (!$productAttribute->isTranslatable()) { $productAttributesValues[] = $this->configureProductAttributeValue($productAttribute, null, $value); + + continue; } + foreach ($this->getLocales() as $localeCode) { + $productAttributesValues[] = $this->configureProductAttributeValue($productAttribute, $localeCode, $value); + } } return $productAttributesValues;