[Skip to main content](#vessel-content)

#   hikashopUpdateVariant not setting the variant!

##

- **[bonzomedia](/forum/user/1859-bonzomedia "View bonzomedia's Profile")**
- [![bonzomedia's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/1859-bonzomedia "View bonzomedia's Profile") Topic Author
- [ Offline](/forum/user/1859-bonzomedia)

Less More

- Posts: 131
- Thank you received: 7
-
-

9 years 4 months ago -  9 years 4 months ago [\#273501](#273501) by [bonzomedia](/forum/user/1859-bonzomedia "View bonzomedia's Profile")  *[hikashopUpdateVariant not setting the variant!](/forum/31-development/891043-hikashopupdatevariant-not-setting-the-variant#273501 "-- 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&#95;product&#95;characteristic&#95;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!")* was created by *[bonzomedia](/forum/user/1859-bonzomedia "View bonzomedia's Profile")*

-- 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) Code:

var SetFragrance = document.getElementById("hikashop_product_characteristic_5");

I get the specific characteristic container and hide it (as I'm setting it automatically)
I set the variant using:- Code:

SetFragrance.value = the_characteristic_option_id;

And then call hikashopupdatevariant with the SetFragrance option 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 4 months ago by [bonzomedia](/forum/user/1859-bonzomedia "View bonzomedia's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5MTA0My1oaWthc2hvcHVwZGF0ZXZhcmlhbnQtbm90LXNldHRpbmctdGhlLXZhcmlhbnQ/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

9 years 4 months ago [\#273528](#273528) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[hikashopUpdateVariant not setting the variant!](/forum/31-development/891043-hikashopupdatevariant-not-setting-the-variant#273528 "-- 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&#95;product&#95;characteristic&#95;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!")*

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.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5MTA0My1oaWthc2hvcHVwZGF0ZXZhcmlhbnQtbm90LXNldHRpbmctdGhlLXZhcmlhbnQ/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.042 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
