Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jmaver-plume
Copy link
Contributor

Resolves #63
Impact: minor
Type: feature

Issue

Currently all emails are sent based on language (field in mongodb) of the shop account belongs to. This means users cannot specify which language emails they want to receive. Similar for anonymous purchases.

Solution

With this solution:

  • Users can set their profile language
  • All emails which are sent to accounts (not anonymous) are in language of their profile
  • Anonymous Orders can accept optional field language and then emails are sent based on this order email

Overview

If user / order does not have specified account it still looks at shop language to find template.

  • Added language field in Accounts.profile document
  • Added language field in Order document
  • Add graphQL query, mutation, resolvers to set and get language of account
  • Modify getTemplate and getSubject to accept additional parameter language
  • Modify functions where getTemplate and getSubject are used to get language for the email

Breaking changes

There are no breaking changes.

Testing

TBD

Jaka Maver added 30 commits May 9, 2019 10:27
…before setting it in orders

Signed-off-by: Jaka Maver <[email protected]>
Signed-off-by: Jaka Maver <[email protected]>
Signed-off-by: Jaka Maver <[email protected]>
Signed-off-by: Jaka Maver <[email protected]>
Signed-off-by: Jaka Maver <[email protected]>
Copy link
Contributor

@aldeed aldeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work here. I haven't tested yet, but I reviewed the code and the approach seems solid. There are a few changes necessary for style reasons, but we should be able to test and merge this after that.

"""
shopId: String!

language: String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All fields must have a description and should be alphabetized

"The date and time at which this order was last updated"
updatedAt: DateTime!

language: String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All fields must have a description and should be alphabetized

@@ -1,4 +1,5 @@
import SimpleSchema from "simpl-schema";
import R from "ramda";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single character variables are not allowed by Reaction style rules. I'd recommend just using the standard array .find in this case, though.


// set to undefined value so order language will not be set
if (!shopLanguage) {
language = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing a helpful error would be better so they aren't confused why the language they specified isn't set.

* @summary Sets users profile language
* @returns {Object} Account document
*/
export default function setProfileLanguage(languageCode, accountId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to a non-Meteor mutation function in /imports/plugins/core/accounts/server/no-meteor/mutations/setProfileLanguage.js and call it as const updatedAccount = await context.mutations.setProfileLanguage(context, languageCode, dbAccountId); in the resolver. Using callMeteorMethod is deprecated and soon going away.

optional: true
},
"history.$": History,
"language": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be more specifically named, maybe ordererPreferredLanguage?

@janus-reith
Copy link
Collaborator

Sending the current language per order seems to be a resonable solution to me.

In a typical scenario I'd expect the storefront to offer multiple languages - The currently used language would then be part of the order, regardless if it was placed anonymously or by an existing account.

Storing a language field on the account makes sense to me aswell, although I wouldn't treat that as specific for emails, but also to set defaults for whatever i18n provider is used in the frontend, if that account language might differ from the one requested by the browser.

First I was unsure about the part where the account language is used to determine the email language, as we can send it only with the order, regardless if we have an account or anonymous users.
But after rethinking this, it probably makes sense to use the account. A user might place an order in one language, later change the language and expect follow ups to that order like a shipping notice to also use that new language setting.

The last things missing for me:

  • Where would an account get its inital language from?

We could make the storefront determine the language and send it over to the idp register form as part of the url query. The Login IDP shouldn't check language on its own, as the user might have set a different language in the storefront than the browser default.

  • How would the currently used storefront language affect the account language?

One option would be to just to give the user the choice like a dropdown for the current display language. Now every time the user selects a language here that differs from the account language a dialog could be shown asking if the default should be changed. The profile page could still have a seperate language preference field regardless of that, or do the same thing vice versa and ask if the current display language should be changed accordingly to avoid any confusion for users.

@aldeed
Copy link
Contributor

aldeed commented Aug 5, 2019

@janus-reith Reaction 1.x had such a language select which would set profile.language on Account. So the field is technically already supported, but it hasn't been ported over to GraphQL. If this PR is merged, setting the account language would once again be possible, so you could add back a language select to your storefront UI.

It would be nice to eventually tie it in with IDP and new account registration, but that can be done later, and it's a separate concern since the goal is to eventually make IDP+auth a third-party component.

@aldeed
Copy link
Contributor

aldeed commented Aug 5, 2019

@jm18457 Will you have time to address the comments?

@aldeed aldeed changed the base branch from master to develop August 5, 2019 21:56
@jmaver-plume
Copy link
Contributor Author

@jm18457 Will you have time to address the comments?

I will be busy for a certain period of time right now, but I will see if I can address them over the weekend or next weekend.

@janus-reith
Copy link
Collaborator

It would probably be easier to redo this PR from scratch with the new meteor-free sendEmail function on context that is used now.

@jmaver-plume
Copy link
Contributor Author

Hello, I will close this pull request and create a new pull request, since updated changes are in different repository.
I will also create a new issue in this repository with type feature so they are linked.

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.

4 participants