- Posts: 131
- Thank you received: 7
hikashopUpdateVariant not setting the variant!
- bonzomedia
-
Topic Author
- Offline
Less
More
9 years 2 months ago - 9 years 2 months ago #273501
by bonzomedia
hikashopUpdateVariant not setting the variant! was created by bonzomedia
-- HikaShop version -- : 3.1.1
-- Joomla version -- : 3.7.1
-- PHP version -- : 7.1.2
-- Browser(s) name and version -- : chrome/safari latest on mac
-- Error-message(debug-mod must be tuned on) -- : no error
I have a customised view (which is working fine on a live hikashop 2.x site).
In this view I am automatically setting a variant's value via a Javascript call (depending on where the user is in the site).
Basically, I use the following logic:-
1. I check to see if the page is in the section of the site where I need to set the variant.
2. If it is:-
I get the specific characteristic element (hikashop_product_characteristic_5)
I get the specific characteristic container and hide it (as I'm setting it automatically)
I set the variant using:-
And then call hikashopupdatevariant with the SetFragrance option
I have checked and double checked my logic (which is working on 2.5) but when I click the Add to Cart button the variant is not set, and it adds the product with the last variant option in the list.
I've convinced myself that there has been a change in the way that the Hikashop add to cart code works!
Any help or pointers you can provide would be useful! Have shared the front end URL in private - happy to provide back end access.
Thanks!
-- Joomla version -- : 3.7.1
-- PHP version -- : 7.1.2
-- Browser(s) name and version -- : chrome/safari latest on mac
-- Error-message(debug-mod must be tuned on) -- : no error
I have a customised view (which is working fine on a live hikashop 2.x site).
In this view I am automatically setting a variant's value via a Javascript call (depending on where the user is in the site).
Basically, I use the following logic:-
1. I check to see if the page is in the section of the site where I need to set the variant.
2. If it is:-
I get the specific characteristic element (hikashop_product_characteristic_5)
Code:
var SetFragrance = document.getElementById("hikashop_product_characteristic_5");
I set the variant using:-
Code:
SetFragrance.value = the_characteristic_option_id;
Code:
hikashopUpdateVariant(SetFragrance);
I have checked and double checked my logic (which is working on 2.5) but when I click the Add to Cart button the variant is not set, and it adds the product with the last variant option in the list.
I've convinced myself that there has been a change in the way that the Hikashop add to cart code works!
Any help or pointers you can provide would be useful! Have shared the front end URL in private - happy to provide back end access.
Thanks!
Last edit: 9 years 2 months ago by bonzomedia.
Please Log in or Create an account to join the conversation.
9 years 2 months ago #273528
by nicolas
Replied by nicolas on topic hikashopUpdateVariant not setting the variant!
Hi,
The problem is not with that code.
We didn't change anything regarding that since HikaShop 2.5 and your code still works.
The problem is that the hidden variants data is inside the form of the page on your link while it should normally be outside. So because of that, regardless of what you select in the dropdowns, the last variant listed in the hidden data is the one added to the cart when you use the add to cart button.
The problem is not with that code.
We didn't change anything regarding that since HikaShop 2.5 and your code still works.
The problem is that the hidden variants data is inside the form of the page on your link while it should normally be outside. So because of that, regardless of what you select in the dropdowns, the last variant listed in the hidden data is the one added to the cart when you use the add to cart button.
Please Log in or Create an account to join the conversation.
Time to create page: 0.139 seconds