Author Topic: [SOLVED] Item added twice (sometimes) through "buy now" button  (Read 909 times)

jdani

  • Beginner
  • *
  • Posts: 6
[SOLVED] Item added twice (sometimes) through "buy now" button
« on: December 30, 2011, 17:53:11 pm »
The title is quite descriptive. Sometimes, when I click on "Buy Now", the item is added twice. The behaviour use to be one of these:
1. After clicking on "Buy now", you go to the cart page normally, but when go to other page (front page, for example), you can see TWO items in the cart without any message.
2. After clicking on "Buy now", you are redirected to the cart page with two items added to the cart and the info message: Item quantity quantity have been updated.


I couldn't make it happen in firefox... Just IE8 and Chrome.


Any ideas?

Thanks a lot.

jdani

  • Beginner
  • *
  • Posts: 6
Re: Item added twice (sometimes) through "buy now" button
« Reply #1 on: January 03, 2012, 12:28:14 pm »
Now I know how to reproduce the error, and Its occur only with IE and Chrome, now for sure.

  • Add to cart or "Buy now" any item
  • Delete that item from cart
  • BUY NOW the item again. The item will be added twice to the cart


At first I thought this error was related to the user session, but with firefox everything run as expected, so this is not an error with the session...


Ideas? :)

jdani

  • Beginner
  • *
  • Posts: 6
Re: Item added twice (sometimes) through "buy now" button
« Reply #2 on: January 03, 2012, 15:27:38 pm »
Now it's the same with FF....   :-X

jdani

  • Beginner
  • *
  • Posts: 6
Re: Item added twice (sometimes) through "buy now" button [SOLVED]
« Reply #3 on: January 05, 2012, 10:10:58 am »
The error was in the code I used to add the "Buy now" button. In the file "addtocart_form.tpl.php", I added this code:

Code: [Select]
<input type="submit" class="<?php echo $button_cls ?>" value="<?php echo $button_lbl_buy_now ?>" title="<?php echo $button_lbl_buy_now ?>"  onclick='submit()' />

The type of the input object is wrong, it must be button, cause the form is being submitted on every onclick event. The right is this:

Code: [Select]
<input type="button" class="<?php echo $button_cls ?>" value="<?php echo $button_lbl_buy_now ?>" title="<?php echo $button_lbl_buy_now ?>"  onclick='submit()' />