Skip to content
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

Merged
merged 3 commits into from
Oct 18, 2017

Conversation

GSadee
Copy link
Member

@GSadee GSadee commented Oct 5, 2017

Q A
Branch? 1.0
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets partially fixes #8220
License MIT

@GSadee GSadee added the Bug Fix label Oct 5, 2017
@GSadee GSadee added this to the 1.0 milestone Oct 5, 2017
@GSadee GSadee force-pushed the diplaying-attributes-in-channels branch from d222d21 to 8c45747 Compare October 6, 2017 10:42
Copy link
Contributor

@pamil pamil left a 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.

@GSadee GSadee force-pushed the diplaying-attributes-in-channels branch from 8c45747 to e552c6b Compare October 10, 2017 10:34
@GSadee
Copy link
Member Author

GSadee commented Oct 10, 2017

@pamil I've added some specs for test this behaviour

return false;
}

if (empty($attributeValue->getValue())) {
Copy link
Contributor

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)

Copy link
Contributor

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 in fr_FR but true in pl_PL
  • integer attribute has 0 value in fr_FR but 1 in pl_PL

$this
->getAttributesByLocale('pl_PL', 'en_US')
->toArray()
->shouldReturn([$attributeValuePL->getWrappedObject()])
Copy link
Contributor

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()])
Copy link
Contributor

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()])
Copy link
Contributor

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]);

@GSadee GSadee force-pushed the diplaying-attributes-in-channels branch from e552c6b to 29c6dd0 Compare October 10, 2017 20:43
UPGRADE-1.0.md Outdated
@@ -1,3 +1,11 @@
# UPGRADE FROM 1.0.0 to 1.0.1
Copy link
Contributor

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)

@GSadee GSadee force-pushed the diplaying-attributes-in-channels branch from 29c6dd0 to cb931cd Compare October 16, 2017 13:13
@pamil
Copy link
Contributor

pamil commented Oct 17, 2017

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. getAttributeByCodeAndLocale behaviour stays the same if the third parameter is not passed.

What do you think about targeting master branch with this PR? Some parts can be still merged to 1.0, like the first two Behat scenarios and specs that does not call that method with the thrid parameter, but it's not necessary.

@GSadee
Copy link
Member Author

GSadee commented Oct 17, 2017

@pamil IMO this is a bug fix, because even if the behaviour of getAttributeByCodeAndLocale has not been changed, adding the third parameter in twig template on shop fixes the behaviour of displaying attributes there.

And these behat scenarios cannot be merge to 1.0 without changing the getAttributeByCodeAndLocale, because they will fail 💥

@pamil
Copy link
Contributor

pamil commented Oct 18, 2017

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 :)

@GSadee
Copy link
Member Author

GSadee commented Oct 18, 2017

I can't 100% agree because this PR fixes the scenario:

  • the base locale is en_US
  • the product has attribute with values in en_US and pl_PL locales
  • this product is in channel with default locale fr_FR
  • in the shop, product is displaying in locale pl_PL

Before: the attribute woldn't be shown at all and it isn't a standard behaviour for translatable entities for me :)
After: the attribute would be shown in pl_PL

Copy link
Member

@lchrusciel lchrusciel left a 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
Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor

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).

@pamil pamil merged commit 1bbf5e0 into Sylius:1.0 Oct 18, 2017
@pamil
Copy link
Contributor

pamil commented Oct 18, 2017

Thanks @GSadee for your patience! ☮️

@GSadee GSadee deleted the diplaying-attributes-in-channels branch October 18, 2017 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants