-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ProductAttribute] Fix displaying attributes depending on locales and channels #8775
Conversation
GSadee
commented
Oct 5, 2017
•
edited
Loading
edited
Q | A |
---|---|
Branch? | 1.0 |
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Related tickets | partially fixes #8220 |
License | MIT |
d222d21
to
8c45747
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some unit tests for getAttributesByLocale
method? It feels complicated enough not to rely only on Behat.
8c45747
to
e552c6b
Compare
@pamil I've added some specs for test this behaviour |
return false; | ||
} | ||
|
||
if (empty($attributeValue->getValue())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we do not want it to be an empty
call.
The following things are considered to be empty:
- "" (an empty string)
- 0 (0 as an integer)
- 0.0 (0 as a float)
- "0" (0 as a string)
- NULL
- FALSE
- array() (an empty array)
- $var; (a variable declared, but without a value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid we're missing the tests for attributes that have values existing in base locale, but these values are considered empty (especially for booleans or integers).
Like with base locale fr_FR
and current locale pl_PL
and boolean attribute, what happens if:
- boolean attribute has
false
value infr_FR
buttrue
inpl_PL
- integer attribute has
0
value infr_FR
but1
inpl_PL
$this | ||
->getAttributesByLocale('pl_PL', 'en_US') | ||
->toArray() | ||
->shouldReturn([$attributeValuePL->getWrappedObject()]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add another one which is testing the same call but returning the attribute from the fallback locale.
$this | ||
->getAttributesByLocale('pl_PL', 'en_US', 'fr_FR') | ||
->toArray() | ||
->shouldReturn([$attributeValueEN->getWrappedObject()]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add another ones which are testing the same call but:
- returning the attribute from
$localeCode
locale - returning the attribute from
$baseLocaleCode
locale
$this | ||
->getAttributesByLocale('pl_PL', 'en_US') | ||
->toArray() | ||
->shouldReturn([$attributeValuePL->getWrappedObject()]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw. instead of $this->getAttributesByLocale(...)->toArray()->shouldReturn([$mock->getWrappedObject()]);
you can use $this->getAttributesByLocale(...)->shouldIterateAs([$mock]);
e552c6b
to
29c6dd0
Compare
UPGRADE-1.0.md
Outdated
@@ -1,3 +1,11 @@ | |||
# UPGRADE FROM 1.0.0 to 1.0.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no additional action needed, so I think it's not needed to mention that (and it's 1.0.1 -> 1.0.2 now anyway)
29c6dd0
to
cb931cd
Compare
I've been thinking for some time whether to classify this as a bug fix or a new feature, but it looks like it is the latter. What do you think about targeting |
@pamil IMO this is a bug fix, because even if the behaviour of And these behat scenarios cannot be merge to |
From my POV the current attributes behaviour is like for any other translatable resources: try to fetch a translation for current locale, if not found - try fallback locale. This PR adds a new feature, which is including also attributes in base locale. As for Behat, the first two scenarios should pass, the other two are describing new features. Anyway, it might be helpful to hear some other opinions than ours :) |
I can't 100% agree because this PR fixes the scenario:
Before: the attribute woldn't be shown at all and it isn't a standard behaviour for translatable entities for me :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems for me to be rather a bug fix, but as @pjedrzejewski said in #8220 (comment) we should probably merge it to the master
And I should also see the product attribute "T-shirt details" with value "Banana is a very good material." | ||
|
||
@ui | ||
Scenario: Viewing a detailed page with product's attribute for current channel in different locale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of this scenario should have it is name changed with the scenario above. This one is using a default locale
public function getAttributesByLocale( | ||
string $localeCode, | ||
string $fallbackLocaleCode, | ||
?string $baseLocaleCode = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could start adding TODO messages with the information, that from 2.0 the third parameter would be mandatory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we intend to make it required then E_USER_DEPRECATED
error should be triggered if value was not passed. To be honest, I'd rather make fallback locale code optional as well (there's no method to get product attributes values in given locale only now).
Thanks @GSadee for your patience! ☮️ |