[Solved] Product multiple "minimum quantity"

  • Posts: 101
  • Thank you received: 12
11 years 8 months ago #90314

Hi,

Let's say we have a product called PENCIL RAINBOW and the "product min per order" is 20.
What we'd like to achieve is that when you change the quantity that only the multiples of 2O are possible like 20, 40, 60, 80 and so on.
21 for instance is not allowed.

Is there to do this and perhaps show a message like:
PENCIL RAINBOW Quantity has to be divisible by the minimum quantity: 20

Thanks,

SG

subscription: HikaShop Business

Last edit: 11 years 8 months ago by SG.

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

  • Posts: 82796
  • Thank you received: 13356
  • MODERATOR
11 years 8 months ago #90515

Hi,

You can use a quantity field override in your template to change the input field for the quantity into a dropdown.
We have some documentation about that here:
www.hikashop.com/en/support/documentatio...tation.html#override
and an example here:

<?php
function hikashop_quantity_render($html,$i,$max_quantity,$min_quantity){

return '<select name="quantity"><option value="20">20</option><option value="40">40</option></select>'.$html;
}

The following user(s) said Thank You: SG

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

  • Posts: 101
  • Thank you received: 12
11 years 8 months ago #90683

Hi,

At first I didn't think to use dropdown but just use a textfield and show a message when someone fills in something wrong.
But with the dropdown it works.

Here you can see it with 20 times the min quantity. So a dropdown with 20 numbers is shown.
And it's dynamic in the way that it uses the $min_quantity so it can be used for all products.

<?php function hikashop_quantity_render($html,$i,$max_quantity,$min_quantity){ 

$ret1 = '<select id="hikashop_product_quantity_field_'.$i.'" name="quantity">';
$ret2 = "";

$jmax = $min_quantity*10;

for($j=1; $j<=20; $j++) { 
	$multiple_min_quantity = $min_quantity * $j; 
	$ret2= $ret2 . '<option value="'.$multiple_min_quantity.'">'.$multiple_min_quantity.'</option>';
}

return $ret1 . $ret2 . '</select>'.$html; }


Thanks for helping me get there.

How could I do this for the checkout?
Can I use similar code some where?


Greets.

SG

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

  • Posts: 13201
  • Thank you received: 2322
11 years 8 months ago #90812

Hi,

For the checkout, you can edit the view "checkout / cart" and use the previous code, you should just have to change the variables called.

The following user(s) said Thank You: SG

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

  • Posts: 101
  • Thank you received: 12
11 years 8 months ago #90901

Hi,

Thank you for your reply, which helped a lot. (I do have some questions below)

This is the result that I came up with.
Maybe it can still be made easier, so anyone feel free to make it cleaner and shorter. (I don't mind)
Oh yes, I added a if-statement to be able to select(selected="selected") the right value ($row->cart_product_quantity).

<select id="hikashop_checkout_quantity_<?php echo $row->cart_product_id; ?>" name="item[<?php echo $row->cart_product_id;?>]" class="hikashop_product_quantity_field_dropdown">
                <?php
                $min_quantity = $row->product_min_per_order;
                $cart_product_quantity = $row->cart_product_quantity;
                $jmax = $min_quantity*10;
                for($j=1; $j<=20; $j++) {
                  $multiple_min_quantity = $min_quantity * $j;
                  
                  if ($multiple_min_quantity == $cart_product_quantity) {
                  ?>
                  <option value="<?php echo $multiple_min_quantity; ?>" selected="selected" onchange="var qty_field = document.getElementById('hikashop_checkout_quantity_<?php echo $row->cart_product_id;?>'); if (qty_field){<?php echo $input; ?>}"> <?php echo $multiple_min_quantity; ?></option>
                  <?php }
                  else {
                  
                  ?>
                  <option value="<?php echo $multiple_min_quantity; ?>" onchange="var qty_field = document.getElementById('hikashop_checkout_quantity_<?php echo $row->cart_product_id;?>'); if (qty_field){<?php echo $input; ?>}"> <?php echo $multiple_min_quantity; ?></option>
                  <?php
                  }
                }
                  
                ?>

                </select>



I changed the class name of the select into .hikashop_product_quantity_field_dropdown and added the following in the frontend_custom.css
.hikashop_product_quantity_field_dropdown{
	float:left;
}


Some related questions:

1) Does the onchange in the option value do something. I'm not sure what $input is used for and what is happening.
Can you elaborate in what this does and whether it makes a difference if it's there or not?
I mean this code:
onchange="var qty_field = document.getElementById('hikashop_checkout_quantity_<?php echo $row->cart_product_id;?>'); if (qty_field){<?php echo $input; ?>}"

2) STANGE BEHAVIOUR: I didn't change anything in the delete button but when I click on it, it jumps step 2.
This is the code which I didn't touch:
<?php if($this->params->get('show_delete',1)){ ?>
                  <div class="hikashop_cart_product_quantity_delete">
                    <a href="<?php echo hikashop_completeLink('product&task=updatecart&product_id='.$row->product_id.'&quantity=0&return_url='.urlencode(base64_encode(urldecode($this->params->get('url'))))); ?>" onclick="var qty_field = document.getElementById('hikashop_checkout_quantity_<?php echo $row->cart_product_id;?>'); if(qty_field){qty_field.value=0; <?php echo $input; ?> qty_field.form.submit();} return false;" title="<?php echo JText::_('HIKA_DELETE'); ?>">
                      <img src="<?php echo HIKASHOP_IMAGES . 'delete2.png';?>" border="0" alt="<?php echo JText::_('HIKA_DELETE'); ?>" />
                    </a>
                  </div>
                <?php } ?>

Thanks

Last edit: 11 years 8 months ago by SG. Reason: removed the 3rd question

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

  • Posts: 82796
  • Thank you received: 13356
  • MODERATOR
11 years 8 months ago #91107

1. It doesn't do anything so you don't need to have it on the checkout cart. It's used for other quantity fields like the ones on products listings, on the product page...

2. The piece $this->params->get('url') on that code should be the current URL of the page ( so that the system redirects back to the current page once the product is removed ). Isn't that the case ? If not, as a quick fix, you can directly put the URL of the step with the cart in there and that should help it stay on the current step.

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

  • Posts: 101
  • Thank you received: 12
11 years 8 months ago #91188

Hi,

About Question 2:
I forgot to say something important.
It's not that it just jumps to the next page.
It's that it doesn't delete the product and just jumps to the next page.

(Sorry I forgot the important part about that it doesn't delete the product :blush: )

I think it has to do with the following code but I might be wrong:

onclick="var qty_field = document.getElementById('hikashop_checkout_quantity_<?php echo $row->cart_product_id;?>'); if(qty_field){qty_field.value=0; <?php echo $input; ?> qty_field.form.submit();} return false;" title="<?php echo JText::_('HIKA_DELETE'); ?>">

So somehow because I changed the input into a select field (dropdown) the delete button doesn't work.

I really can't figure out why the product is not deleted and just jumps to the second page.


EDIT:
I searched further and I found this post:
http://www.hikashop.com/en/forum/4-how-to/77189-delete-item-in-cart-is-linked-to-register-page.html#84540
Here Xavier says the following to the person:

The problem is that you have customize the quantity input for a product, but the value 0 is missing, so the script take the first value which is 5, that's why the product is not removed in the cart.


So I think I have the same problem. But how can I resolve it?





Thanks

Last edit: 11 years 8 months ago by SG. Reason: Added an EDIT part

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

  • Posts: 101
  • Thank you received: 12
11 years 8 months ago #91191

Hi,

Ok I think I got a simple solution :)

I've just added the following:

<option value="0">0</option>

Now it works and deletes the product.

So if understand correctly it wasn't working because qty_field.value=0; couldn't be excuted because there was no 0 value in de dropdownlist.
Did the code then stop and didn't execute <?php echo $input; ?> qty_field.form.submit();}

I'm trying to understand what happened before without the 0.
And what does the echo $input; do here?

Thanks

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

  • Posts: 26152
  • Thank you received: 4027
  • MODERATOR
11 years 8 months ago #91290

Hi,

Right !

If your dropdown does not contains "0", it is not possible for the javascript to select the "0" value into.
So, it does not change the value of the list and it submit the exact same cart with the same quantities.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: SG

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

Time to create page: 0.054 seconds
Powered by Kunena Forum