Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

Variable products in different languages ​​are added to the cart separately #361

Closed
Milakrivoruchko opened this issue Aug 30, 2018 · 11 comments
Labels

Comments

@Milakrivoruchko
Copy link

Can you reproduce this issue on default Wordpress theme (eg Storefront)?
yes

Can you reproduce this issue when all other plugins are disabled except WooCommerce, Polylang and Hyyan WooCommerce Polylang Integration?
yes

What product versions and settings are you using when this issue occurs?
PHP: 7.1
WordPress: 4.7.11
WooCommerce: 3.4.4
Polylang: [state if using Polylang PRO] 2.1.5
Hyyan WooCommerce Polylang Integration: 1.2.0
Theme: Impreza (Child Theme)
Browser: Opera, Chrome, any

Steps to Reproduce

Add to cart variable products in different languages (Simple products are added to the cart correctly)

What I Expected
Variable products of the same type were added to the cart in different languages ​as one

Note: Variable products in these versions are translated correctly, in the additional language, data of product variations in the main language are blocked and activated. But duplicated when added to the trash.

What was done before:
There is a site where woo-poly does not work correctly with the translation of variations. Variations were blocked by woo-poly, Polylang combined multilingual versions correctly.
In the cart were various variable products with different variations.
Have installed a different version of WP. The recommendations of Fixes # 187 were implemented (also when updating). Variations are handled correctly, but variable products in different languages ​​are added to the cart several times.

Possible actions, write your own handler add-to-cart-validation and add-to-cart-variable_product. There are doubts.
@Jon007, please, help mine.

@Milakrivoruchko Milakrivoruchko changed the title Variable products in different languages ​​are added to the cart Variable products in different languages ​​are added to the cart separately Aug 30, 2018
@Jon007
Copy link
Contributor

Jon007 commented Aug 30, 2018

Hi,
I don't understand what you mean by

Variable products of the same type were added to the cart in different languages ​as one

what problem are you experiencing?

The plugin doesn't have a with variable products and the cart, this should normally work fine.

  • products are normally shown in the current language, so if you switch languages, the system will find the new language version of the product and display that
  • if the system cannot find a translation for the product (or variation), then, just for the cart screen, the language version originally added to the cart is displayed.

Note:

Some plugins/themes could have code which interferes with the above process

This plugin does have a special link to connect the variation translations, which depends on the variations being created in the shop base language, so if the variations were created when this plugin was not activated, or the shop base language was changed, then the system would have trouble finding the linked translation of the variation.

@Milakrivoruchko
Copy link
Author

Thank @Jon007,

please see how it looks in the cart (as two products)
https://drive.google.com/open?id=1sFtJ-5q-utKhsIoy0rucdd5SBwa7lk1G

Polylang switches products correctly, woo-poly translates the variation from the main language.

Variable products are created with an active woo-poly. Translates variational products correctly, but adds them to the cart two products, as in the screenshot.

I think public function addToCart ($ ID) does not handle variable products. I can not find the reason.

What versions of WP, woo-poly, Polylang do you consider working with variational products? What are your recommendations for the versions?

@Jon007
Copy link
Contributor

Jon007 commented Aug 30, 2018

ok I see what you mean and can reproduce as follows:

  1. add a variation to the cart
  2. switch language
  3. add the same variation to the cart in the new language
  4. the cart now has two items in with different ids, but actually both of them refer to the same item and will show as two copies of the same item

This could be fixed by an extra check when adding to cart, check if the product to be added is a variation and any translation of this variation is already in the cart then increase the cart quantity instead of adding to the cart..

However I am not sure that the current behaviour actually causes any real problem does it?
This only occurs if the user deliberately adds different language versions of the same variation to the cart, which is pretty unusual.... and the user can simply remove one of the items from the cart if they want.

@Milakrivoruchko
Copy link
Author

Milakrivoruchko commented Aug 30, 2018

Yes, as you describe.

Thanks, understood.
This problem can harm if a large online store is connected to an accounting program. For example, when languages ​​are similar and there is a language problem (Russian and Ukrainian).
That is, you need to constantly make a return of the product if he switched between languages and if the client refuses. This is an extra bookkeeping posting, which causes confusion at the accountant.

If I write the handler code, I'll write to the post under my question.

@Jon007
Copy link
Contributor

Jon007 commented Aug 30, 2018

I'm still not exactly sure what the problem is or what solution you are proposing.
Clearly if the user is allowed to check out with different products in different languages they will get different product ids, it doesn't make much difference whether that's on the same order or not.

if it's a book-keeping issue and you need all the orders/postings to refer to one language then that could be added to the book-keeping code (along the same principle as this plugin cart module does).

Some people would prefer the cart module to be turned off for the sake of other plugins also modifying the cart. If we allowed that option, then products would either disappear from the cart when switching languages (you can only check out a product in the language you added it to the cart), or possibly always show the product in original language added to cart, regardless of checkout language.

@0xmaayan
Copy link

0xmaayan commented Sep 3, 2018

Hey, I am having the same issue.

Have 2 languages on the site, any product has only 1 in stock.
when creating a product (let's say in English) and then creating the same product in a different language (let's say in Spanish), I am able to add the English product to the cart and when switching to the Spanish language, I am able to add the Spanish product to the cart. (Although there is only 1 in stock).

I am not sure if this is a bug or I just don't know how to handle it.
Either way, I expect not to be able to add the product to cart if this product has already added to the cart (no matter the language of the site).

Will be great to have suggestions to handle it.

@Jon007
Copy link
Contributor

Jon007 commented Sep 3, 2018

There are issues with stock, see #299

In this case the problem is not so much that the same client could add the product in different languages, the real problem is that a different client could add the stock in another language as the stock is not reserved across all languages.
So any client could buy in Spanish even though the stock is notionally 'reserved' in English. I suggest following that further on #299, as the stock handling is a real bug, and quite a separate issue from this one.

@0xmaayan
Copy link

0xmaayan commented Sep 4, 2018

I looked at #299 and I don't think this is my problem.

I just got an order on the site for the English product. The Spanish product is marked as 'out of stock' and the client is not able to add to cart/purchase this product.

My problem is when the client adding an English item to the cart and on the same session, change the site language to Spanish, the client can add the same product (only in Spanish).

@Jon007
Copy link
Contributor

Jon007 commented Sep 4, 2018

My point is that if the same client can add the same product, then other clients can also add the same product, which is a more likely and troublesome scenario.
If the stock issue is fixed so that no client can add other language versions if the stock is already reserved, then that will also fix the problem for the same client.

@Jon007 Jon007 added the stock label May 6, 2019
@Jon007
Copy link
Contributor

Jon007 commented May 23, 2019

@Msbir according to my tests this should be fixed by a replacement version of the Stock.php file I have checked in here
17e29b9

@Jon007 Jon007 closed this as completed May 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants