VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: tjrayner on March 01, 2016, 20:44:17 PM

Title: Initial Step & Min Qty
Post by: tjrayner on March 01, 2016, 20:44:17 PM
Hi, really hoping someone can help. I've amended my template to have the initial value on the products add to cart bar to be 0 this is due to a customisation I've got for adding multiple items at once. The problem I have now is that if you click the + icon it changes the value to 1 rather than the minimum amount (3). If you then add to cart it adds the minimum amount. Is there a way of getting the first step to jump to the minimum amount then the additional steps continue at 1

Hope I've explained it well enough
Title: Re: Initial Step & Min Qty
Post by: PRO on March 01, 2016, 20:59:54 PM
have you setup steps in the product?
Title: Re: Initial Step & Min Qty
Post by: tjrayner on March 01, 2016, 21:03:08 PM
Hi, yes the problem is I need the steps to be 1 as the minimum needs to be 3 but they can have 4, 5, 6 etc if I change step to 3 then they can only order 3, 6, 9 etc. I need the first step to be 3 for example and then revert to 1
Title: Re: Initial Step & Min Qty
Post by: tjrayner on March 01, 2016, 22:02:39 PM
OK I've managed to get the qty to change to the minimum value when clicking in the qty box by adding the following script:

<script>
function checkValue(sender, step)
{
                                   var value = parseInt(sender.value);
                                   
                                    if (value == '' || isNaN(value)) {
                                                  sender.value = step;
                                     } else if (value < step) { sender.value = step; }
                                      else if (value%step != 0 && value > step) {
                                            sender.value = (value - (value%step));
                                     } else {
                                             return sender.value;
                                       }
                      }
</script>


and then at the end of the qty input added the following onclick="<?php echo "checkValue(this, $product->min_order_level)"?>"

However I'm unsure how to continue this with the plus and minus buttons
Title: Re: Initial Step & Min Qty
Post by: PRO on March 01, 2016, 22:09:30 PM
then you set the step to 1
Title: Re: Initial Step & Min Qty
Post by: tjrayner on March 01, 2016, 22:46:42 PM
But then as the initial value is 0 when you click the plus the value goes to 1 not 3
Title: Re: Initial Step & Min Qty
Post by: PRO on March 04, 2016, 14:49:50 PM
in the script you wrote,

increment by the minimum if its not met, then by the step after that