Quantity selector

  • Posts: 446
  • Thank you received: 19
  • Hikashop Business
2 days 1 hour ago #371509

Hi Nicolas,

For the past few days I’ve noticed the following: on a product page, if you select a variant and set the quantity to 2 or more to add to the cart, then switch to another variant using the selector, the quantity field does not reset back to 1. Instead, it keeps the previously selected quantity by default.

Please Log in or Create an account to join the conversation.

  • Posts: 85448
  • Thank you received: 13977
  • MODERATOR
1 day 19 hours ago #371510

Hi,

This behavior is intentional.

This is an improvement we've made with the latest version of HikaShop where the JavaScript that swaps the variant content now saves the quantity value before the swap and restores it right after, so the quantity stays on whatever the customer had typed. We think that is the better default - if a customer has typed "2" and then picks a different size or color, forcing them to re-enter "2" every time adds unnecessary friction, and it is easy for them to miss the reset and end up ordering only one item.

If, in your specific case, you really want the quantity to reset to 1 on every variant change, you can add the following JavaScript snippet to your Joomla template (or to a custom module with JS output):

<script>
document.addEventListener('DOMContentLoaded', function(){
    if(window.Oby && Oby.registerAjax) {
        Oby.registerAjax('hkContentChanged', function(){
            var q = document.querySelector('#hikashop_product_quantity_main .hikashop_product_quantity_field');
            if(q) q.value = 1;
        });
    }
});
</script>

It hooks into the "hkContentChanged" event that is fired right after the variant swap and sets the main quantity field back to 1.

Please Log in or Create an account to join the conversation.

Time to create page: 0.054 seconds
Powered by Kunena Forum