Orders and line items are not multilingual, they exist in only one language at a time.
At the same time, products, discounts, shipping rates are multilingual.
To guard against data changes, the $line_item->title receives the product title when the product is added to cart.
So this means that the line item ends up with a specific translation (FR if the site/product was viewed in french, for example).
Suggestion:
$order->langcode holds the order language. Selected on the order add form, or created by the CartProvider.
This language is used when copying any multilingual data. Once an order is completed in french, the line items stay in french.
Does that make sense? It's potentially weird if the customer views the site in a different language the next time, but the line items stay in the old language, but I don't see a way around that if we want to keep the line item title copying (and we do, cause EU laws require invoices and orders to be unchanged after they are placed).
Comment | File | Size | Author |
---|---|---|---|
#13 | anonymous-checkout-language-mail-D8-2603482-1.patch | 1.57 KB | nicothezulu |
Comments
Comment #2
pcambraAs for a conversation with bojanz on IRC.
Option #1 is having the line item title/label stored as it is using the order language. No further modifications once order moves away from cart statuses.
Option #2 is to provide some sort of tool to extend what a line item label is, probably a formatter that can be overriden by custom code and "stuff" whatever is relevant (attributes, id?) for a given store in that label.
Comment #3
harings_rob CreditAttribution: harings_rob at Harings.be commentedComment #4
harings_rob CreditAttribution: harings_rob at Harings.be commentedPR: https://github.com/drupalcommerce/commerce/pull/352
Comment #5
mglamanKicking back to needs work because PR has conflicts, and not sure what the exact steps forward are going to be.
Comment #6
harings_rob CreditAttribution: harings_rob at Harings.be commentedI rerolled onto 8.x-2.x latest codebase.
Comment #7
willeaton CreditAttribution: willeaton commentedHi, I've arrived here because I'm trying to figure out the language of an order to be able to send the confirmation email in the correct language. My issues are:
For me, a very basic piece of information, that has been available since drupal 5, is now missing. Is there a quick fix to set order language based on interface language on cart creation? At least then I can choose a different template file per language (awful solution but nevertheless a solution for my client) based on the order language.
Comment #8
bojanz CreditAttribution: bojanz at Centarro commentedJust wanted to link to https://www.drupal.org/project/commerce/issues/2981193#comment-12660271, which clarifies our reasoning
Comment #9
willeaton CreditAttribution: willeaton commentedHi @Bojanz, that makes sense for labels, but what about storing the order language for order related events that occur later on? An example is emails triggered by admin events (order status change). You can't use "current language" as the admin language is independent from the user language, and you currently have no idea what the order language is, just labels set in stone. Would it take that much to create an order language field?
Comment #10
bojanz CreditAttribution: bojanz at Centarro commented@willeaton
The whole point of this issue is to add an order language field.
Comment #11
mglamanReviewing this alongside #3020615: Emails sent by Commerce Order ignore user language wishes
Comment #12
CaptainPinkey CreditAttribution: CaptainPinkey commentedHave there been any changes here?
While the system respects the user language, this doesn't account for anonymous orders on an multilang site and emails that are sent on order transitions. (No user to get the lang from and the current lang would be the preferred language of the admin)
So a field representing the active language during the placement of the order would be helpful.
Comment #13
nicothezulu CreditAttribution: nicothezulu commentedObviously there shall be a better way to solve this,
but if you use the attached patch and create a field at
admin/commerce/config/order-types/default/edit/fields
with the machine name of field_checkout_language it will work.
I suspect a feature like this will be included in future commerce releases,
and needles to say, I use this with the feature together from here: Send order receipt email once an order is placed or validated, depending on the workflow used.
p.s. This will apply for anonymous checkouts
- I did not use DI for the LanguageManager, sorry ;_)
Comment #15
splash112 CreditAttribution: splash112 as a volunteer commentedIn my use case I would really want to be able to save an order in multiple languages, add a variable to the order with the customer checkout language.
Comment #16
Tom_VDB CreditAttribution: Tom_VDB commentedI needed the language the user used to create the order.
I resorted to enabling the
langcode
field oncommerce_order
.In a custom module:
This hold the current langcode when the order is first created.
After which it is accessible with
$order->langcode()