I'm running a multilingual webshop and it seems it's only possible to purchase products in the website's primary language. In my case this is really a problem since some products are essentially the same but have for instance a language-specific logo printed on them.

If I'm looking at a product in german (primary language chosen during installation), then change the language with the language switcher to french (second language, added after installation) and click "add to cart" I get the error "The website encountered an unexpected error. Please try again later."

The same happens if I add a product in a view using the "Product: add to cart" field. This happens only in french, german works. The products are filtered by "Translation language" so only german products appear on the german page and only french products appear on the french page.

I checked the reports, where the following error appears:

Exception: Cannot create a variant of a variant. in _uc_product_get_variant() (Zeile 147 in /modules/ubercart/uc_product/uc_product.module).

In my user profile I changed the default website language to french just to try if this has any effect. That wasn't the case, I still had the same error (in french, german worked normally).

Might this be related with #2856198: Items in cart always in main language?

I'm using Drupal 8.2.7 if that's any help.

Comments

maenjuel created an issue. See original summary.

TR’s picture

Issue summary: View changes
TR’s picture

Title: Adding translated product to cart results in PHP error "Cannot create a variant of a variant" » Adding translated product to cart results in error "Cannot create a variant of a variant"
Priority: Major » Normal
Issue tags: -multilingual

That's not a PHP error, it's an error generated by Ubercart when we detect that the product has already had a variant created. Are you using any contributed modules that operate on products? I will try to reproduce this on a clean website.

maenjuel’s picture

Ah ok, thanks for clarification and editing my issue accordingly.

I have enabled the following contributed modules:

  • Admin Toolbar
  • Admin Toolbar Extra Tools
  • Advanced Link
  • Backup and migrate
  • Chaos tools
  • Colorbox
  • Imce File Manager
  • Linkit
  • Pathauto
  • Token

For ubercart I have activated all core modules.

TR’s picture

Version: 8.x-4.0-alpha5 » 8.x-4.x-dev
Status: Active » Postponed (maintainer needs more info)

I tried to reproduce this problem and I couldn't. Here's what I did:

Set up a site on simplytest.me using Ubercart 8.x-4.x-dev. I chose German as the installation language / primary language.

simplytest.me is currently using Drupal core 8.3.1. I assume you've seen the critical core security advisory https://www.drupal.org/SA-CORE-2017-002 and that you've also upgraded to 8.3.1 by now ...

Installed and enabled all Ubercart modules plus the following:
Advanced Link
Chaos tools
Colorbox
Linkit
Token

I did NOT install these:
Admin Toolbar
Admin Toolbar Extra Tools
Backup and migrate
Imce File Manager
Pathauto

I did not enable any other core or contributed modules.

After installing and enabling modules, I added French as a language (/admin/config/regional/language), then placed the Ubercart cart block and the language switcher block (/admin/structure/block).

Then I created a product with one attribute and three attribute options.

I viewed the product page (in German still), then used the language switcher block to switch to French (which it did), then clicked the add to cart button "Ajouter au panier" button.

The product WAS added to the cart, and I was redirected to the cart page which showed the product in the cart. There were NO errors.

I strongly suggest you upgrade to Ubercart 8.x-4.x-dev and see if this fixes things for you. If it doesn't, I will need you to help figure out what steps are missing in my test. I don't see what more I can do unless you can successfully reproduce the problem with Ubercart 8.x-4.x-dev on simplytest.me and can provide a more detailed list of steps to demonstrate the problem.

maenjuel’s picture

Status: Postponed (maintainer needs more info) » Fixed

I updated Drupal core and all modules to the newest version (still running ubercart 8.x.4.x.-alpha5 and not dev-Version) and the error doesn't appear anymore. Maybe there was some conflict with an old version of a module.

Thank you for your time and help, TR!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.