Skip to content

Commit

Permalink
[Doc] add info about non-translatable attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
SirDomin committed Jan 18, 2021
1 parent adfda63 commit 25df06c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
10 changes: 10 additions & 0 deletions docs/book/products/attributes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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?
---------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 25df06c

Please sign in to comment.