Hey there!

Sooo I came across an interesting bug today just before deploying a project. I was wondering if I have configured something incorrectly or if this is a bug.

Basically, I have...

* Products (with english titles)
* Product Displays in French / English linking to Products

If I am in the French interface and add a French Product Display and then head over to my cart the title displays in English. Now I believe that's b/c it's actually using the line item title not my product display title. Interesting, the link to the actual product is correct (to the french product!)

I tried changing around the display a bunch of different ways to add more relationships and other things but still scratching my head...

Ideas?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rszrama’s picture

Category: bug » support
Status: Active » Postponed (maintainer needs more info)

What you've described is expected behavior to me, but I do have a follow-up question: are you translating product titles at all?

The issue here is that the Add to Cart form connects the resultant line item to its display context, which in your case is language specific. I ask the follow-up question, because I don't know if it would actually use a French product title if you were translating to French and the site was being viewed in that language.

ShaneOnABike’s picture

Status: Postponed (maintainer needs more info) » Needs work

Yep I have product nodes in both languages which are linked through translations.

Why it's an issue is that at checkout it displays only the English product name (product type) not the referenced product node name (French or English).

Am I missing some reference that should be made cause I don't see how to do this in views. My thoughts on this is the following...

* Users don't care what the internal name is (but we are using that at checkout and in emails sent out)
* Users should see a listing of names based on the language they are in (regardless of internal product name)

Just so I articulated this well..

* Product Node: Title, Body, blah blah
* Product Type: (From store) SKU, Weight, etc

ShaneOnABike’s picture

Status: Needs work » Active

Wrong state sorry

ShaneOnABike’s picture

Issue tags: +i18n, +shopping cart, +product language

Would it not be possible somehow to run each entity through the entity translation functionality? It's not clear to me how to get this working but I might have time to resolve it if given some guidance. But having one language products seems odd... especially in the shopping cart. Since my impression of your work on Commerce was to make it to have a frontend Display so it should just choose the proper language for that I would imagine...

dustinbrunson’s picture

I am having exact same issue, all translations for product display work great except the title of the product in shopping cart. Has anyone found a solution to the problem?

dustinbrunson’s picture

Actually, I have not been able to find how to add translation to the product itself, only the display product, so when added to shopping cart there is no translation. So how to add translation to product types?

adiatis’s picture

We have Commerce products and multiple Products displays (for each language a node).

The title in the shopping cart is not correct for the current language (at the moment the product is added to the cart).

I found function 'commerce_product_line_item_title' in commerce/modules/product_reference/commerce_product_reference.module.

/**
 * Returns an appropriate title for this line item.
 */
function commerce_product_line_item_title($line_item) {
  // Currently, just return the product's title.  However, in the future replace
  // this with the product preview build mode.
  if ($product = entity_metadata_wrapper('commerce_line_item', $line_item)->commerce_product->value()) {
    return check_plain($product->title);
  }
}

In the 'line_item' object there is a entity reference in [data] [context] [entity]
We have the entity_type and the entity_id. Is it possible to load the title of that entity? This would solve the problem for me. How can I overwrite 'commerce_product_line_item_title'

We have also a problem in 'commerce_cart_rules_add_to_cart_message'. The title of the product is not correct in this function:

/**
 * Rules action: displays a the default translatable Add to Cart message.
 */
function commerce_cart_rules_add_to_cart_message($product) {
  drupal_set_message(t('%title added to <a href="!cart-url">your cart</a>.', array('%title' => $product->title, '!cart-url' => url('cart'))));
}

The 'product' object has the wrong title. How can we overwrite this function?

ShaneOnABike’s picture

Well I have ye to solve the issue with the Rules message... BUT you can change all the views for the cart & order pages include the entity. I used that to display the title rather then the product itself. You'll need the relationship of items that reference the actual entity.

muschpusch’s picture

Yep i can conform that #8 is working:

You need to set 2 relations:

1.) Set a relation to: (Line Item) Commerce Line item: Product
2.) Commerce Product: Node referencing products from field_product

I needed to disable sql rewrite in query settings too since that one views bug when setting relations between products and product 'nodes'

ShaneOnABike’s picture

Also for the drupal cart message here's a patch for that. Basically it queries the entity for the node id and then from there loads the node to get the title. If this all fails it still uses the product title instead.

I **really** think that this should be applied to the commerce module.

rszrama’s picture

I could see something like that going in but not as written. We already have in the line item the display context for the product, so there's really no reason to make a blind load of the node like that.

ShaneOnABike’s picture

Well I'm all ears if you want to suggest how I could do this different?

READ: A little bit more guidance code wise

ayalas’s picture

There are three approaches to tackle this issue (C is the best, in my case).

A) Enable Commerce Backoffice Product, and use content translation for nodes and completely disparate variations per product language.

B) Disable Commerce Backoffice Product (if using Commerce Kickstart at all), so variation types are cancelled and the product type can have "Entity Translation" enabled, as is suggested here.

C) Enable Commerce Backoffice Product with #2203317: Support Entity Translation for Commerce Product and use a single node and Entity Translation enabled variation types. Apply #2203383: Pass user langauge to entity_view() in Rendered product formatter so the rendered product displayed in the "Shoping Car Form" view will get translated. Enable entity translation (field-level translation) for both the product display node and the variation types used. The product reference field should not be translateable.

For approaches A & C:

  1. Apply the patch #1545896: Add Entity Translation integration for the Inline Entity Form module and get latest dev version of Entity Translation, to include #1865244: Allow multiple translation handlers on the same form.

For A:

  1. Configure the product content type multilingual support as Enabled, with translation (the multiple nodes approach).
  2. In your product content type's product reference field (field_product in the "Product display" content type) mark "Users may translate all occurrences of this field". This is necessary so after the first save, clicking "Translation" will open the translation form with no variation types already in the form, so they have to be filled for each language anew and not synchronized across translations.

As far as I saw, commerce_product_line_item_title() is called but has no effect on the display of the cart, at least not with the Commerce Kickstart default configuration. The title that is eventually displayed in the cart is the product variation's title, through the "Rendered product" formatter. #2203383: Pass user langauge to entity_view() in Rendered product formatter fixes this formatter.

Arne Slabbinck’s picture

Patch #10 helped me out translating the product titles in the 'add to cart' mesage, thanks! (Drupal Commerce 7.x-1.11 / 2015-01-16)

1kubik’s picture

Hi there!
Thanks for the Patch.
Now a Notice pops up

Notice: Only variables should be passed by reference в функции commerce_cart_rules_add_to_cart_message() (строка 209 в файле /commerce/modules/cart/commerce_cart.rules.inc).

i did a tiny change in the patch to fix this

sabbaghian’s picture

With Automatic Entity Label module title field in product variation could be customized and also it will be auto-translatable. In my commerce kickstart site, I checked "Automatically generate the label and hide the label field" under "Auto label" tab of my product variation and used [commerce-product:field-product-node:0:title] as Pattern for the title.
In shopping cart form views "Commerce Line Item: Title" is selected for displaying auto-translated title.
By this approach add to cart message is also translated.
Don't forget to uncheck "Auto generate the product title" in field_product of product content type.