Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Update cart on checkout


jdvb

Recommended Posts

Posted

Hi,

 

it was annoying me that people were complaining to not be able to update the cart.

What they did was click checkout, before updating the cart.

Eventhough I have update cart buttons on every row of the cart, and the table headers are changed into links including onclick="cart_quantity.submit();".

So here is what I did:

 

in application_top.php a few lines above:

case 'add_product' :

 

change:

tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));

 

into:

tep_redirect(tep_href_link(($HTTP_POST_VARS['docheckout'] == '1'?FILENAME_CHECKOUT_SHIPPING:$goto), tep_get_all_get_params($parameters)));

 

and in shopping_cart.php change:

<?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_SHOPPING_CART, 'action=update_product')); ?>

 

into:

<?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_SHOPPING_CART, 'action=update_product')); ?><input type="hidden" name="afreken" id="docheckout" value="0">

 

and change:

<?php echo '<a href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '">' . tep_image_button('button_checkout.gif', IMAGE_BUTTON_CHECKOUT) . '</a>'; ?>

 

into:

<?php echo '<a href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '" onclick="document.getElementById(\'docheckout\').value = \'1\'; cart_quantity.submit(); return false;">' . tep_image_button('button_checkout.gif', IMAGE_BUTTON_CHECKOUT) . '</a>'; ?>

 

 

what does it do?

If no javascript is executed, it does nothing and the normal operation is unchanged, other then that an additional hidden field is submitted on cart update.

 

If javascript is alowed, on clicking the checkout link, you actually won't checkout, but change the value of "docheckout" and then update the cart.

The update cart function then sees that docheckout is set, and instead of returning you to the shopping cart, it will now redirect to the checkout page, after having updated the cart ofcourse.

 

for those that alow javascript this will be nice, those that disable javascript generally don't have a problem updating the cart anyways.

  • 3 weeks later...
Posted

Your code didn't work for me because $HTTP_POST_VARS['docheckout'] doesn't exist in the submitted form. I had to change the name="afreken" to name="docheckout". I lost a little bit of hair until a friend pointed out the obvious

 

Change the line:

<?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_SHOPPING_CART, 'action=update_product')); ?><input type="hidden" name="afreken" id="docheckout" value="0">

to:

<?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_SHOPPING_CART, 'action=update_product')); ?><input type="hidden" name="docheckout" id="docheckout" value="0">

 

Once I did that the code worked perfectly. I think this is going to solve a lot of problems for my customers, not to mention reduce the burden on us when we have to change the order quantity manually on behalf of someone who couldn't figure out how to hit "update".

 

Thanks for posting this!

  • 3 weeks later...
Posted

Good post, thanks for the code. I added this to my page and now for some reason it directs to the http version of the shipping page instead of the https version. I implemented just like the code you have, any reason why that would link to the non-ssl page?

  • 8 months later...
  • 3 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...