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

Add to cart with attributes stop working #502

Closed
rjsmazevedo opened this issue Jun 24, 2020 · 3 comments
Closed

Add to cart with attributes stop working #502

rjsmazevedo opened this issue Jun 24, 2020 · 3 comments

Comments

@rjsmazevedo
Copy link

Please note:
Hello,

When adding the plug-in, or the add to cart link, stop working with the translated attribute. But disable the plugin or get back to working again. Some help? Did the translation or "attribute_pa_ac" change you?

LINK: cart/?add-to-cart=9038&quantity=1&attribute_pa_ac=00

What product versions and settings are you using when this issue occurs?

  • PHP: 7.2
  • WordPress: 5.4.2
  • WooCommerce: 4.2.2
  • Polylang: Polylang
  • Hyyan WooCommerce Polylang Integration:
  • Browser: Chrome
@Jon007
Copy link
Contributor

Jon007 commented Jun 28, 2020

Hi, I can see there are a couple of issues with the code here, I'll submit proposed changes shortly.

Firstly, the attribute parameters are only tested for Post not for Get usage.
Secondly, the code for handling various not found is incorrect in several ways:

  • if there is no variation found, function returns silently without error (l.311 return)
  • function only tests for missing attributes if variation is already found, it should be doing the opposite.

testing with WP5.4.2 woo4.2.2 polylang 2.7.3 php7.4.2 and urls like:
language/es/basket-es/?add-to-cart=472&quantity=1&attribute_pa_color=negro

the variation matching by attribute is WooCommerce native functionality in
find_matching_product_variation() in class-wc-product-data-store-cpt.php which matches by slug.
In Polylang context the attribute value slug should be the correct slug for the current language.
Then this plugin attempts to determine what to do if a matching variation is not found.

@Jon007
Copy link
Contributor

Jon007 commented Jun 28, 2020

addToCartHandlerVariable() in this plugin originated as a version of the WooCommerce function add_to_cart_handler_variable() in class-wc-form-handler.php

It appears that the customisation added had the intention of handling situations where add-to-cart is called with product in a different language from the current user interface language.
On examination, the customisation does not appear to handle the original intention well, and introduces other problems and compatibility issues with other plugins which may also hook items added to cart.

I suggest therefore removing the customisation from this plugin which you could try in your local version by commenting out lines 45-46 of woo-poly-in tegration/src/Hyyan/WPI/Product/Cart.php

@Jon007
Copy link
Contributor

Jon007 commented Jun 28, 2020

@decarvalhoaa let me know if you see any issue removing addToCartHandlerVariable() added by you in 2016 in
841f623

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
2 participants