Skip to main content

How to increase/decrease quantity in cart

More
15 years 7 months ago #9216 by YakNarak
Nicolas,

I'm trying to achieve a feature in the cart view that allows the user to increase/decrease the quantity in steps of 1. Or to delete the product entirely.

I've changed the code to this:


<input id="hikashop_checkout_quantity_<?php echo $row->cart_product_id;?>" type="text" name="item[<?php echo $row->cart_product_id;?>]" class="hikashop_product_quantity_field" value="<?php echo $row->cart_product_quantity; ?>" onchange="this.form.submit(); return false;" />
<?php if($this->params->get('show_delete',1)){ ?>
<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;?>'); qty_field.value=0; qty_field.form.submit(); return false;" ><img src="<?php echo HIKASHOP_IMAGES . 'delete2.png';?>" border="0" title="totally remove from cart" alt="totally remove product" /></a>
<?php } ?>
<?php if($this->params->get('show_delete',1)){ ?>
<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;?>'); qty_field.value=qty_field.value + 1; qty_field.form.submit(); return false;" ><img src="<?php echo HIKASHOP_IMAGES . 'add1.png';?>" border="0" title="add 1 unit to cart" alt="add 1 product" /></a>
<?php } ?>
<?php if($this->params->get('show_delete',1)){ ?>
<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;?>'); qty_field.value=qty_field.value - 1; qty_field.form.submit(); return false;" ><img src="<?php echo HIKASHOP_IMAGES . 'subtract1.png';?>" border="0" title="remove 1 unit from cart" alt="remove 1 product" /></a>

All is showing well and the functions remove completely and subtract work correctly. However when I try to add something strange happens. Suppose the old value of the quantity field is 8. When I press the add button it shortly shows in the quantity field 81 instead of 9 Then the page refreshes and the value shows 10. I've tried this with several numbers. So if the old value was 12 and I press add, it shows 121, then refreshes and shows 10 again.

Any idea what goes wrong here?

Gert.

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

More
15 years 7 months ago #9226 by nicolas
qty_field.value=qty_field.value + 1;

is not correct javascript. It should be:
qty_field.value=parseInt(qty_field.value) + 1;

Otherwise, that will add 1 to the string 10 and you will get 101 instead of 11.

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

More
15 years 7 months ago #9237 by YakNarak
Nicolas,

Once more big thanks. Working now.

Gert.

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

Time to create page: 0.151 seconds
Powered by Kunena Forum