[ic] Gift Certificates

Ed LaFrance interchange-users@interchange.redhat.com
Tue Apr 9 11:33:59 2002


At 12:14 PM 4/8/2002 -0700, you wrote:
> > I don't, really. Total cost is the sum of subtotal + shipping +
> > handling +
> > salestax. I apply the credit to each of these in turn via using the
> > [assign] tag, until the cert value has been consumed or they have
> > all been
> > reduced to zero. Total cost just becomes a 'report' of the net effect at
> > that point.
> >
> > - Ed L.
>
>Dear Ed,
>
>Sorry for previous bottom quoting, I just read the thread on that and will
>change my ways.
>
>Can you send some code on how you do this?  The code I'm using is below, and
>it requires multiple checks.  I was afraid to try doing that with four
>numbers, instead of just the subtotal.  FYI, I'm currently using a serial
>gift certificate number, with a second code for a password.  Could probably
>reduce it to just the password as the G.C. code.
>
>Thanks,
>
>Russ
>
>[del big ol' nasty code block]

Russ - you didn't mention where you placed your code - I'm guessing the 
checkout page. I opted to process the gift cert on page in the special_page 
directory. The user enters their giftcert key on checkout.html clicks a 
"Redeem" button, which sends processing through the special_page and then 
back to checkout.

The code for giftcert processing is rather lengthy, but here is a brief 
overview in psuedocode (unorthodox to be sure, I hope it isn't too confusing):

if (total-cost == 0) {
         return with "we need an order total to start...";
}
elsif (not a giftcert) {
         return with "that ain't no giftcert";
}
elsif (giftcert is used) {
         return with "sorry, that giftcert has been used in full";
}
elsif (giftcert is pending) {
         return with "sorry, that giftcert has not been activated yet";
}
else {
         # set perl vars to current giftcert amount,
         # subtotal, salestax, shipping and handling here
         foreach (subtotal salestax shipping handling) {
                 if (giftamount >= $_) {
                         assign $_ 0;
                         giftamount -= $_;
                 else {
                         assign $_ $_ - giftamount;
                         giftamount = 0;
                         return;
                 }
         }
}


The other things I do in the same code are: return on success with a 
message saying the amount from the giftcert which will be applied to the 
order and the amount of cert credit which will remain; capture the values 
of subtotal, shipping, handling and salestax before the giftcert was 
applied for display and transactions recording purposes. Finally, I present 
a button which allows the user to unapply the giftcert if they do not plan 
to checkout immediately.

- Ed L.



===============================================================
New Media E.M.S.               Software Solutions for Business
463 Main St., Suite D          eCommerce | Consulting | Hosting
Placerville, CA  95667         edl@newmediaems.com
(530) 622-9421                 http://www.newmediaems.com
(866) 519-4680 Toll-Free       (530) 622-9426 Fax
===============================================================