Empty Cart Function

Completed modifications to the NOP Shopping Cart. Additions, modifications, and more.

Moderators: Koibito, Stefko, Randy, Rosey

Empty Cart Function

Postby Steven Nyland » Tue Jan 28, 2003 2:37 am

Below, please find a little snipplet that you can add to you managecart.html page (e.g. next to the checkout image/button). On click, it deletes all items in the shopping cart (empties the cart) and reloads the managecart.html page.

The snipplet comes in two flavors:

Empty Cart (Graphic) :
Code: Select all
<a href="managecart.html" onClick="SetCookie ('NumberOrdered', 0, null, '/')"><img src="your_image.gif" alt="[ empty shoppingcart ]" border="0"></a>


Empty Cart (Button) :
Code: Select all
<input name="Empty" type="button" value="  Empty Cart  " onClick="SetCookie ('NumberOrdered', 0, null, '/');document.location=('managecart.html')">


When using the "Graphic" version, change the path & name of your image to whatever you wish to use.

Steven
[ If it ain't Dutch ... it ain't Much ]
Steven Nyland
Guru
 
Posts: 274
Joined: Thu Jan 02, 2003 1:20 pm
Location: Still here ...

great

Postby smiler2k » Wed Jan 29, 2003 11:31 am

thanks mate i have been racking my brains for a week, and have just posted a message with that problem


Smiler
smiler2k
 

Postby jgraphis » Thu Jan 30, 2003 4:06 pm

I actually used the same method on a link, but I needed to get the order FIRST and give the customer the option to pay AFTER they had checked out... I cleared the cart this way
Code: Select all
echo "If you would like to pay for your order by credit card now, ";
echo "<A HREF=\"https://www.yourpaymentprocessorhere?variables&morevariables=$cartvariable\" target=_top onClick=\"SetCookie ('NumberOrdered', 0, null, '/');\">Please click here</A>";


You can also put it on the return URL link.
jgraphis
 
Posts: 1
Joined: Thu Jan 30, 2003 3:45 pm

Postby Steven Nyland » Thu Jan 30, 2003 10:48 pm

Scott actually posted an even better solution:

On your 'Thank Page' that is displayed after the order has been processed by the pl/php script include the following code:

Code: Select all
<script>
<!-- Killcart
SetCookie ('NumberOrdered', 0, null, '/');
-->
</script>


Make sure to include the nopcart script & language script as well else it will render an error message.

Steven
[ If it ain't Dutch ... it ain't Much ]
Steven Nyland
Guru
 
Posts: 274
Joined: Thu Jan 02, 2003 1:20 pm
Location: Still here ...

Postby Bolderrush » Wed Feb 05, 2003 12:03 pm

Thanks steven for these great mod's. you guys make the cart a great succes!!
Bolderrush
 

Postby Steven Nyland » Wed Feb 05, 2003 2:36 pm

Thanks!
[ If it ain't Dutch ... it ain't Much ]
Steven Nyland
Guru
 
Posts: 274
Joined: Thu Jan 02, 2003 1:20 pm
Location: Still here ...

Postby LCAngela » Tue Oct 07, 2003 1:06 pm

Steven Nyland wrote:Scott actually posted an even better solution:

On your 'Thank Page' that is displayed after the order has been processed by the pl/php script include the following code:

Code: Select all
<script>
<!-- Killcart
SetCookie ('NumberOrdered', 0, null, '/');
-->
</script>


Make sure to include the nopcart script & language script as well else it will render an error message.


I've included this in my checkout.pl-generated "thank you" page, but it doesn't seem to be working. I've included all my script references correctly, and when I C&P the generated page code to my HTML editor, it works fine...it clears my offline cart contents without a hitch.

You can go all the way through my cart process at
{edit} (link removed) {/edit}
and then view the source of the generated "thank you" page after clicking the PayPal button on the checkout page. (Yes, it'll send me an email, but I don't care...I'm still trying to get it all working properly.)

Any advice would be appreciated... :)

=====

UPDATE: My cart is up and running now, so please don't place "test" orders! Thanks! :D
Last edited by LCAngela on Sun Feb 01, 2004 9:45 am, edited 2 times in total.
LCAngela
WebMaster
 
Posts: 10
Joined: Sun Oct 05, 2003 5:25 pm

Empty Cart upon checkout -

Postby sawyervision » Tue Jan 27, 2004 7:43 am

Well, from category of I hate myself for having gotten so angry, here is the solution to clear the blast'd cart after checkout: Make your checkout page call for the SetCookie. That's it. That's all there is to it. The example is below:

<form name="myForm" action="http://yourdomain.com/cgi-bin/checkout.pl" method="POST" onLoad="return CheckForm(this);" onSubmit="SetCookie ('NumberOrdered', 0, null, '/');document.location=('managecart.html')">

The above goes on your checkout.html page. Technically, the last thing it does when you hit submit is clear the cart after doing the math.

So, why do I feel like another shoe is yet to fall. :oops:

Oh, and would dearly love to know how why when I have the...
print "<script nopcart.js></script>"
line in checkout.pl am getting error

Looks like I'm nearly done with this deli menu page. Contains tons of functioning scripts and will put a link up when completed.

Thanks for the collective fragments of assistance.
sawyervision
 
Posts: 14
Joined: Tue Jan 13, 2004 9:40 am

Re: Empty Cart upon checkout -

Postby LCAngela » Tue Jan 27, 2004 9:42 am

sawyervision wrote:Oh, and would dearly love to know how why when I have the...
print "<script nopcart.js></script>"
line in checkout.pl am getting error

Shouldn't you be referencing nopcart.js with a "src=" and a full URL? In my CGI scripts, I always use a full URL when referencing any other file on the server...
Code: Select all
<script src="http://my.domain.com/scripts/nopcart.js"></script>

If I've ever gotten an error or had something not display properly (or at all), 9 times out of 10, it's because my "src" attribute wasn't correctly formatted. :) Give it a shot, and let us know if that fixes the problem for you...
LCAngela
WebMaster
 
Posts: 10
Joined: Sun Oct 05, 2003 5:25 pm

So why are my cookies still there?

Postby Jim Lane » Wed Apr 21, 2004 6:50 am

I've tried each suggestion listed and I can't clear my cookies.

Here's the code I copied and am using.

<FONT CLASS="checkout">

<P ALIGN=CENTER>

<form name="myForm" action="http://www.berriesandmore.com/cgi-bin/checkout.pl" method="POST" onLoad="return CheckForm(this);" onSubmit="SetCookie ('NumberOrdered', 0, null, '/');document.location=('managecart.html')">

<SCRIPT>
CheckoutCart();
</SCRIPT>
</P>

<INPUT TYPE=HIDDEN NAME="Submit" VALUE="">

<div align="center">

<center>

<p> <font class="checkout">

<input type="submit" value="Submit order">

<input type="reset" value="Clear Form" name="reset">


Jim Lane
Phoenix, AZ
Jim Lane
 
Posts: 27
Joined: Tue Nov 19, 2002 5:12 am
Location: Surprise, AZ

Re: So why are my cookies still there?

Postby Randy » Wed Apr 21, 2004 3:58 pm

Jim Lane wrote:<form name="myForm"
action="http://www.berriesandmore.com/cgi-bin/checkout.pl" method="POST"
onLoad="return CheckForm(this);"
onSubmit="SetCookie ('NumberOrdered', 0, null, '/');document.location=('managecart.html')">

<SCRIPT>
CheckoutCart();
</SCRIPT>


This is what you are asking to be done:
onLoad CheckForm (this) calls the function to see if the customer has filled in all the required fields in the form...billing name, address etc.
Which of course he hasn't because the page just loaded, and had the alert box in his face before he could blink.
Then as soon as he presses the submit button the cart is emptied, and the form is not checked again...so the customer could checkout without filling in the required billing fields, and none the wiser...only to be thrown back to an empty managecart page.
You will never know if that happens, because of a quirk in JavaScript that cancells the submition of a form if another command follows the submit command.

I see by your form action, you are using checkout.pl.
Checkout.pl should send you and your customer email confirmation of the order, and may write to your order database csv file, and finally instruct the browser to load a thank-you page.

It is this thank-you page that has the onLoad=="SetCookie ('NumberOrdered', 0, null, '/')";
and a link to send them to your index.html page...now with an empty cart.

Hope that helps
Randy
Randy
Guru
 
Posts: 1511
Joined: Tue Apr 22, 2003 12:21 pm
Location: Thunder Bay, Ontario

Thanks

Postby Jim Lane » Thu Apr 22, 2004 4:45 am

Your answer was very well stated and very informative. What I ended up doing was using the onclick= function of the submit button. I tried to follow your lead, but my checkout.pl file was changed so much from the original. I couldn't figure out where to place the onload= since my checkout.pl file makes the thank you page using html. But I got it working. Once you explained why it wasn't working, it was just a matter of figuring out where to place it so it would.

Long answer for a grateful thank you.

Thanks for the advice and lesson.

jim
Jim Lane
 
Posts: 27
Joined: Tue Nov 19, 2002 5:12 am
Location: Surprise, AZ

Postby paperlion » Fri Jun 11, 2004 5:32 am

Randy wrote (Apr 22, 03):

I see by your form action, you are using checkout.pl.
Checkout.pl should send you and your customer email confirmation of the order, and may write to your order database csv file, and finally instruct the browser to load a thank-you page.

It is this thank-you page that has the onLoad=="SetCookie ('NumberOrdered', 0, null, '/')";
and a link to send them to your index.html page...now with an empty cart.


Although an existing html thankyou.htm page exists on my server and is specified at the allotted area near the top of checkout.pl; the page that comes up to confirm an emailed order, is a generated one from checkout.pl.

I saw the sticky on how to format this page, but I still have two questions:
1) is it possible to place the clear cart function right into the checkout.pl code, or otherwise get it to occur when using this type of confirmation?

2) When would a separate thankyou page be used, and if calling it from within the checkout.pl file doesn't call it, how should it be called?

Thanks everyone.
if it ain't broke, you can fidget with it.
paperlion
 
Posts: 21
Joined: Mon Jun 02, 2003 4:50 am

Postby goffenhiemer » Mon Jun 14, 2004 11:53 am

How would you add this code to a checkout.pl file? I'm new to perl and I'm not sure which characters need a "\" before them and which ones don't.

All I do know is when I add any of these codes to checkout.pl I get a server error.
goffenhiemer
 
Posts: 21
Joined: Wed Jun 09, 2004 1:43 pm

Postby paperlion » Mon Jun 14, 2004 12:03 pm

That one's easy. There's a boxed legend near the top of the checkout.pl file that shows examples of which entries take slashes, etc.
if it ain't broke, you can fidget with it.
paperlion
 
Posts: 21
Joined: Mon Jun 02, 2003 4:50 am

Next

Return to Modifications

Who is online

Users browsing this forum: No registered users and 0 guests