Gossamer Forum
Home : Products : DBMan : Customization :

Shopping cart mod?

(Page 2 of 3)
> > > >
Quote Reply
Re: Shopping cart mod? In reply to
Lordy me, I must be getting tired, it's late in the day.

This :
<<<<otherwise I get a screen that tell me what link the problem is and in what file.>>>

Should have read <<otherwise I get a screen that tells me what line the problem is and in what file>>>>

Kylie
Quote Reply
Re: Shopping cart mod? In reply to
o Grain,

Hi, it's going well! lol NOT -- I had to replace our html.pl with the long/short friendly html.pl so have to start formatting the html.pl again once I get this working.

I've got your mod in but I've run into a problem with it -- I think I'm missing something.

I'm getting an error (below) when I fill in the details for the initial preparation of the order and click Prepare your Order.

- - - - -
Error Message : fatal error: Undefined subroutine &main::fatal_error called at /opt2/spiltmil/httpd/cgi-bin/bp/recipes/db.cgi line 1350.

Script Location : /opt2/spiltmil/httpd/cgi-bin/bp/recipes/db.cgi
Perl Version : 5.00404
Setup File : default.cfg

- - - -

So I'm obviously missing a subroutine that I'm meant to have. I counted down the lines at my db.cgi doesn't even run 1350 lines long so I don't know what I'm missing here.

I've added your mod as far as I can tell exactly from your files -- I can't spot an error. I'm wondering, does this mod need another one in order for it to work? Maybe I need a mod I haven't got in there yet in order for this to work.

I loaded up my files to my server in case you can spot a problem right off.

http://www.boxplanet.com.au/recipes/dbcgi.txt

http://www.boxplanet.com.au/recipes/defaultcfg.txt

http://www.boxplanet.com.au/recipes/htmlpl.txt

I'm running off all the default layout for html.pl because I didn't want to edit it before I get this working to make it easier to spot problems.

Kylie
Quote Reply
Re: Shopping cart mod? In reply to
Oh forget me O Grain, I'm a goose! lol

It would have helped had I actually created the orders directory! HA, no flames please, I already confess to being a fool.

Kylie
Quote Reply
Re: Shopping cart mod? In reply to
O grain,

OK, I mostly have it working -- just one question. I don't need the address or zip code details or name. Only the email adress.

How do I remove the need for those other fields in the Prepare for Order?

Kylie
Quote Reply
Re: Shopping cart mod? In reply to
Hello Kylie,

Sorry I didn't answer you earlier since I went away for the weekend,
Thursday -
Friday as it comes here in the Emirates.

Well it seems I was to blame since I had forgot to explicitly state in the
description that the orders directory had to be created and read/writeable. But
obvioulsy you are a clever girl to realize it anyway. Sorry about the extra time you spent!

To remove unwanted user input you need to do this:

1. In sub html_create_order_form find the second print qq| statement. There you find the five requested parameters. Keep only the first one (order_mail) and remove the others.

2. Do the same thing in sub html_rectify_order_form

3. In sub html_create_order at the top there is the input check (unless ($in{'order_mail'}) { ...code ...} etc). Remove the four bottom unless statements and keep only the part that says

Code:
unless ($in{'order_mail'}) {
$message = "<LI>You MUST enter your email address<BR>";
$order_error += 1;
}
else {
unless ($in{'order_mail'} =~ /.+\@.+\..+/) {
$message .= "<LI>The email address that you have entered seem to be invalid.";
$order_error += 1;
}
}

4. Finally, in db.cgi, in sub sub create_order remove the lines that have the input data that you dont need. Customize the first print FILE statment to your greeting to your hungry customer Wink

I think that covers it?
Quote Reply
Re: Shopping cart mod? In reply to
O grain,

Thanks, sounds simple enough -- another job for Monday. Please don't apologise for taking time to get back to me, you're helping me so much!

I've just realised yesterday that I have one other problem that I can't figure out.

When they click "Add more recipes" (that's my $merchandise) it takes them back to the search page which is great but we still have the footer on all the pages and if they click to go to the homepage or to add a recipe it looses their email address in the URL and therefor they have to prepare their order again.

Is there anyway to code the Home link and Add a Recipe link so that the order mail travels with them to those pages too? I tried but failed miserably.

On our pages we will have the links to the categories hardcoded the same URL as a search shows for them and I think I have them right for the ordeer mail to travel with them but I can't be sure because I need to get back to the homepage to test it.

It's listing the recipes funny in the "Show Order" but I want to try to work that out myself Smile

Kylie
Quote Reply
Re: Shopping cart mod? In reply to
Ah, Kylie, yes of course, your customers must be able to add records. The way have I have set the mod up the complete database is to be uploaded when it's time for a revision.

I think that if the customer leaves DBman (e.g. to go to HOME) it is no point in passing the email address there, since it will be lost at the home page (unless that also is dbman driven).If it is not, maybe it would be better to remove the HOME link altogether from the bottom bar?

For you to pass along the email address do this: in sub html_footer add $in {'order_mail'} like this:
Code:
print qq!| <A HREF="$db_script_link_url&add_form=1&order_mail=$in{'order_mail'}"><b>Register</b></A> ! if ($per_add);
print qq!| <A HREF="$db_script_link_url&view_search=1&order_mail=$in{'order_mail'}"><b>Search</b></A> ! if ($per_view);
print qq!| <A HREF="$db_script_link_url&delete_search=1&order_mail=$in{'order_mail'}"><b>Delete</b></A> ! if ($per_del);
print qq!| <A HREF="$db_script_link_url&modify_search=1&order_mail=$in{'order_mail'}"><b>Modify</b></A> ! if ($per_mod);
print qq!| <A HREF="$db_script_link_url&view_records=1&$db_key=*&order_mail=$in{'order_mail'}"><b>List All</b></A> ! if ($per_view);

Maybe you also want to do the same in sub html_cleared_footer?

When do you want the email address (i.e. order_mail) to be cleared? As it is now it is erased once the email is sent to the customer in sub html_cleared_footer, which is called in sub html_cancel order and sub
html_send_order.

Since I haven't though about adding records at all there might well be other add bugs. Smile
Maybe you should insert the extra line as decribed below for sub html_view_failure in all applicapable subs?


Hi Dan!

Thanks for proofing! I admit I didn't test the failed search nor the keyword search thoroughly.

For the failed search: in sub html_view_failure:

# add after
Code:
<input type=hidden name="uid" value="$db_uid">
# this line:
Code:
<input type=hidden name="order_mail" value="$in{'order_mail'}">

For the keyword search (that accidently Smile ) can be done after a failed search add in sub html_record_long a second condition: && ($in{'keyword'} eq '' at the very top:

Code:
if (($in{$db_key} gt 0) && ($in{'keyword'} eq '')) {
%rec = &get_record($in{$db_key});
}
(I'm sure you note the extra bracket Smile )

Drowdown menu for number of items is a good idea, I´ll take that:
In sub html_record_long replace
Code:
<$fieldtxtcolor2><B>Antal: </B><input type="antal" name="antal" size="2" value="1">
with
Code:
<$font><B>Number of items: </B>
<SELECT SIZE=1 NAME="antal">
<OPTION value=" 1">1
<OPTION value=" 2">2
<OPTION value=" 3">3
<OPTION value=" 4">4
<OPTION value=" 5">5
<OPTION value=" 6">6
<OPTION value=" 7">7
<OPTION value=" 8">8
<OPTION value=" 9">9
<OPTION value="10">10
</SELECT>

About deletion of files: I don´t want to use cookies because some people have cookies disabled. So the administrator will from time to time have clean up the orders directory. For this I have made a hack in FileMan, which I will soon (?) put for demo, but I first want to password protect the
directory.

What was it with the missing price? Have you added records and set a price that doesn't show up?

Oh, about calculation and display of cents I don't know how to do that yet Smile



[This message has been edited by O grain (edited May 13, 2000).]

[This message has been edited by O grain (edited May 13, 2000).]
Quote Reply
Re: Shopping cart mod? In reply to
O grain,

Thank you for taking the time to put together this mod. I've been playing with it for a couple of days to see if I can get it to do what I would like, and so far it looks pretty promising. A few items I have noticed and either have not yet figured out or haven't looked into fully:

- If you do a search for more products after ordering something, and there are no search results, it seems to clear the user info.

- After doing a keyword search and clicking on the resulting record name in the long results, it is brought to a blank record. The URL in the long results link looks like:

/db.cgi?db=default&uid=default&order_mail=&ID=&Title=&Author=&Date=&Category=---&Description=&Price=&keyword=soy&sb=---&so=ascend&view_recor ds=Search+Products&nh=2&mh=1

whereas the same URL in the long results of a List All (as opposed to keyword search) looks like:

/db.cgi?db=default&uid=default&view_records=1&ID=*&order_mail=&nh=2&mh=1

I haven't previously used the short/long mod, so I'm not sure if this is a general probelm or if it's related to my installation with your shopping cart.

- Clearing the order deletes the temp user file. I understand why this is done, but few users will... I think cookies would be a better method for storing the order, only requiring their info on checkout.

- Related to the one above, temp user files are not deleted if the person doesn't either submit the order or clear it.

- Cents (US $) are not calculated in the order total if equal to zero (i.e. $8.00 shows as $8.) -- not a big deal, just aesthetic.

- Only integers should be allowed for # of products ordered, something like ^[\d]{0,2}$ although I was thinking of replacing the text box with a dropdown list of 1 to 10 products.

I have one very strange record that the price will not be included in the order total, although it shows up everywhere else fine. I can't see what it is about that record that's wrong... Everything before and after it calculates just fine. I must be missing something simple.

Thanks again,
Dan
Quote Reply
Re: Shopping cart mod? In reply to
Thanks, those fixes worked quite nicely.

I figured out the price calculation problem. It turned out to be much different than what I was looking for... The one record that wasn't getting it's price included in the $total_sum calculation had a hyphen in its name, which threw off the array in:

@this_item = split(/-/,$line);
$this_sum = scalar($this_item[2]);

Maybe another character would be better than the hyphen to split it up?
Quote:
Oh, about calculation and display of cents I don't know how to do that yet
Good answer! Smile

A few other things I haven't gotten working yet:

- Getting $total_sum to show up in the confirmation email(s) seems harder than I would have expected...

- How do you pass the order_mail info to the main menu? The following results in an error:

$db_script_link_url&order_mail=$in{'order_mail'}

- Did you set things up with the intent of not using the admin area? The reason I ask is that some features like delete don't work and the order screen is incorporated into several of the admin steps. Probably not too hard to clean up.

Thanks!
Dan
Quote Reply
Re: Shopping cart mod? In reply to
Hello Dan,

Yes, I have set up things with the intention to neither use the Admin facilities nor the Add, Modify and Delete functions. The guy who I am making this application for will from time to time update the complete database by uploading a new one (exported from Excel). He will use the FileMan hack which is now available on the demo site. (I have disabled the upload function <img src="/images/forum/icons/smile.gif">).

To avoid characters that might confuse the split in sub sum_up_order I have introduced a variable $currency:

Add to default.cfg

# the currency for the prices if the items
$currency = "US$";

(Note that I use $currency = "SEK" in the demo.)

In sub html_record_long replace the last hyphen with $currency in $order:

$order = "$rec{'Artikelnr'} - $rec{'Artist'} - $rec{'Titel'} <b>$currency</b> $rec{'Pris'}";

In sub html_send_order and check_order add $currency:

Totally $total_items of $merchandise - Total sum <b>$currency</b> $total_sum.

Make the bold marked changes to sub sum_up_order

sub sum_up_order {
open (FILE, "<$orders_dir/$in{'order_mail'}.txt") || &fatal_error("Can't open $orders_dir/$in{'order_mail'}.txt.");
@lines = <FILE>;
close (FILE);


$total_sum = 0;
$total_items = 0;
foreach $line (@lines) {
<b>@this_item = split(/$currency/,$line);
$this_sum = scalar($this_item[1]);
@this_item = split(/-/,$line);</b>
$these_items = $this_item[0];
$these_items =~ s/\*//;
$these_items =~ s/pcs//;
$number_items = scalar($these_items);
$this_sum = scalar($number_items) * scalar($this_sum);
$total_sum += $this_sum;
$total_items += $number_items;
}

}
<b>@zero_check = split(/./,$total_sum);
if ($zero_check[1] eq '') {
$total_sum = $total_sum .".00";</b>
}
}


The last three code lines should also take care of the missing 00 cents <img src="/images/forum/icons/wink.gif">

Now, for getting the summing up also in the confirmation email you have to re shuffle a bit in sub html_send_order:

Remove the lines

&sum_up_order;

print qq|
<P>
Totally $total_items of $merchandise - Total sum $currency $total_sum.
<p>
|;

print qq|
<CENTER>
<$font><A HREF=$home_url>Home</A></font></p>
</CENTER>
|;


and add at the top, between
$rec{$db_key} =~ s/<?.B>//g;
and
<i>&send_order;


the following



&sum_up_order;
open (FILE, ">>$orders_dir/$in{'order_mail'}.txt") || &fatal_error("Can't open $orders_dir/$in{'order_mail'}.txt.");
print FILE "\n\n--------------------------------------------------------\n\n";
print FILE "Totally $total_items of $merchandise - Total sum $currency $total_sum.\n\n";
close (FILE);


Well, I think I got it right also in this posting, but it's late ....

Oh, [bleep!], the Forum was taken down just as I was writing this...

(Edited for the new forum, but can't get the hang of it, yet)
Quote Reply
Re: Shopping cart mod? In reply to
Hi O Grain,

Thanks for giving that another stab. Some of it worked, some didn't.

The currency variable is a good addition. I was doing that manually. However, I wasn't able to get it to split the line correctly and calculate the total with the $currency variable in place of the hyphen.

As far as adding the cents to the end of the total, it seems to append .00 regardless of the total, although I can't figure out why from the logic.

I did add a simple shipping and handling snippet, in this case $6 for orders less than $50 and $9 for orders over $50:

add:

$shipping = 6;

above:

$total_sum = 0;

in sub sum_up_order of db.cgi. Then, after the foreach loop, add:

if ($total_sum > '50') {
$shipping = '9';
}

$total_sum += $shipping;

And wherever you have $total_sum showing up in html.pl, add something like (Includes \$ $shipping shipping).

Another thing I did was put JPDeni's category list mod at the top of the search page, as I couldn't figure out how to pass the order_mail value to the main page (which resulted in a cancelled order). I then set the default to go straight to the Search page and removed links to the main page.

The addition to get the total in the confirmation/order emails works fine. I had added it into the confirmation email directly in db.cgi's sub send_order, but your method is much cleaner.

Thanks,
Dan

Quote Reply
Re: Shopping cart mod? In reply to
Here's a very quick way to maintain admin edit/add/delete (some worked before, but the order screen interfered in places due to no order_mail being passed) features without affecting the user interface:

In sub html_record_long, find the line:

if (!$in{'order_mail'}) {

Just before it, add:

if ($db_userid eq "default") {

and be sure to add the corresponding closing bracket after the order form section:

</FORM>
</CENTER>
|;

}

That will use the order screen for default users but skip past it for anyone logged in, i.e. the admin. It might need to be modified if you have people other than admin log in that need to see the order forms.

Dan

Quote Reply
Bug with BACK on browser fixed In reply to
Like I said in the beginning this mod was not quite finalized! Wink

It has been possible to use the browsers BACK button once you have sent the order and then add more items and send again. (Thanks Serge for trying Wink! ) To prevent this, the extension of the order file is changed from .txt to .TXT once the order is sent. And in the subs html_add_order, html_send_order, html_check_order, html_edit_order and html_cancel_order there is a check that the original order file still exists.
So in each of these subs add this check at the top, just after

$rec{$db_key} =~ s/<?.B>//g;

add the following

# Check that the order file is still there ....

if (!open(FILE, "<$orders_dir/$in{'order_mail'}.txt")){
$page_title = "Unfortunately the order could not be added.";

&html_page_top;

print qq|
<$font>The prepared order seems to have disappeared.

Maybe you have already sent or cancelled the order and by mistake used the
browsers back button?
<p><CENTER>
<A HREF=$home_url>Home</A></p>
</CENTER>
</font>

|;

}
else {


Then put the closing else bracket just before
&html_footer;
&html_page_bottom;

so it becomes

} # end else order exists
&html_footer;
&html_page_bottom;

Change the word added to sent, displayed ,edited or cancelled in the appropriate subs

In sub html_send_order there are several changes:
1. If the order is empty the user is returned to the search_form
2. The orginal order file is renamed with the extension .TXT

I think it is better to display the whole sub than to verbally describe the changes Smile


sub html_send_order {
# --------------------------------------------------------
# This sub routine mails the order to the shop keeper and displays
# the entire order as a confirmation. Then it either deletes the order
# file or renames it.

my (%rec) = @_;

$rec{$db_key} =~ s/<?.B>//g;

# Check that the order file is still there ....

if (!open(FILE, "<$orders_dir/$in{'order_mail'}.txt")){
$page_title = "Unfortunately the order could not be sent.";

&html_page_top;

print qq|
<$font>The prepared order seems to have disappeared.

Maybe you have already sent or cancelled the order and by mistake used the
browsers back button?</font>

<p><CENTER>
<A HREF=$home_url>Home</A></p>
</CENTER>
|;

}
else {

# Check that the order is not empty
&sum_up_order;

if (!$total_items) { # Nothing to order!!
# Return to the search-form

$empty_order =1;
&html_view_search;
return;
}
else {

open (FILE, ">>$orders_dir/$in{'order_mail'}.txt") || &fatal_error("Can't open $orders_dir/$in{'order_mail'}.txt.");
print FILE "\n\n--------------------------------------------------------\n\n";

print FILE "Totally $total_items of $merchandise - Total sum $currency $total_sum.\n\n";
close (FILE);


&send_order;
$page_title = "The following order has been sent to $shop";

&html_page_top;


open (FILE, "<$orders_dir/$in{'order_mail'}.txt") || &fatal_error("Can't open $orders_dir/$in{'order_mail'}.txt.");
@lines = <FILE>;

close (FILE);

foreach $line (@lines) {
if ($line =~ /^\*/) {
print $line;
print "
";
}
else {
print "<$font>";
print $line;
print "</font>
";
}
}

} # end else not empty so send

print qq|
<p><CENTER>
<$font><A HREF=$home_url>Home</A></font></p>
</CENTER>
|;

} # end else order exists

&html_order_cleared_footer;
&html_page_bottom;

$order_file = "$in{'order_mail'}.txt";
$in{'order_mail'} = '';

if ($auto_delete) {
system('rm',"$orders_dir/$order_file");
}
else {
# First append tracing data to file
open (FILE, ">>$orders_dir/$order_file") || &fatal_error("Can't open $orders_dir/$order_file.");
@this_order = <FILE>;
print FILE "\n\nRemote Host: $ENV{REMOTE_HOST}\n";
print FILE "Remote Addr: $ENV{'REMOTE_ADDR'}\n";
$server_time = localtime(time());
print FILE "Server time: $server_time";
close (FILE);

# Then rename the file so the user cant use the back button in the browser to
# add more things...
$archive_file = "$order_file";
$archive_file =~ s/txt/TXT/;
system ('mv',"$orders_dir/$order_file","$orders_dir/$archive_file");

}

}


To take care of a detected empty order there is a small change in the top of
sub html_view_search

if (!$in{'order_mail'}) {
$page_title= "Search in $html_title";
}
else {
if ($empty_order) {
$page_title = "Sorry, your order was empty. Search and add $merchandise";
}
else {

$page_title = "Search for more $merchandise";
}
}

The $shipping costs is a good idea. I'll include that too Smile.

The mod description file is updated.

(This post edited to clearify where to put the ending else bracket)
Quote Reply
Re: Bug with BACK on browser fixed In reply to
It's quite possible I missed a step in your directions, but it appears that &html_page_bottom; gets left out of the addition to the five subs:

html_add_order
html_send_order
html_check_order
html_edit_order
html_cancel_order

Rather than try to sort through the multitude of brackets, if's, and else's, I added it at the top:


if (!open(FILE, "<$orders_dir/$in{'order_mail'}.txt")){
$page_title = "Unfortunately the order could not be added.";
&html_page_top;
print qq|
<$font>Your order information appears to have been removed from the system. Maybe you have already
sent or cancelled the order and accidentally used the back button on your browser?
<p><CENTER><A HREF=$auth_logoff>New Product Search</A></p></CENTER></font>
|;
&html_page_bottom;
} else {


Seems to work fine. The only reason I noticed it was missing is that I have right side and bottom table information in the footer that wasn't being included. Other than that, IE doesn't have a problem loading unclosed tables...

Thanks for all the work! This looks to be a very useful mod for small to medium size shopping carts.

Dan

Quote Reply
Re: Bug with BACK on browser fixed In reply to
Hello Dan,

I was really a bit unclear. I wrote

Then put the closing else bracket just before

} # end else order exists
&html_footer;
&html_page_bottom;


when I should have put it:

Then put the closing else bracket just before

&html_footer;
&html_page_bottom;

so it becomes



} # end else order exists

&html_footer;
&html_page_bottom;

(I will edit the previous posting Blush)

(This posting edited with colors to clarify further!)
Quote Reply
Re: shipping costs In reply to
Hello Dan

I found the bug for the trailing zero cents: If I had escaped the split pattern (the dot) it would have worked already Smile. Correction marked in red below.

Now I have taken the liberty to a bit of elaboration on your addition of shipping costs:

In default.cfg add
Code:

$shipping1 = 21.00;
$shipping1_limit = 500.00;
$shipping2 = 10.00;
$shipping2_limit = 1000.00;
$shipping3 = 0;
Then at the end of the sub sum_up_order
sub sum_up_order add after the foreach loop the bold marked

Code:

foreach $line (@lines) {
....
}

if ($total_sum < $shipping1_limit) {
$shipping = $shipping1;
}
elsif (( $total_sum > $shipping1_limit) && ( $total_sum
< $shipping2_limit)) {
$shipping = $shipping2;
}
else {
$shipping = $shipping3;
}

@zero_check = split(/\./,$total_sum);
if ($zero_check[1] eq '') {
$total_sum = $total_sum .".00";
}
$grand_total = $total_sum + $shipping;
@zero_check = split(/\./,$grand_total);
if ($zero_check[1] eq '') {
$grand_total = $grand_total .".00";
}

To display the shipping costs and the grand total add in
sub html_send_order the bold lines
Code:

print FILE "Totally $total_items of $merchandise - Total sum $currency $total_sum.\n";
print FILE "Shipping: $currency $shipping.\n\n";
print FILE "Grand total: $currency $grand_total";

close (FILE);
Likewise in sub html_check_order
Code:

Totally $total_items of $merchandise - Total sum $currency $total_sum.

Shipping: $currency $shipping.
<p>
Grand total: $currency $grand_total

<p>
Quote Reply
Re: shipping costs In reply to
Hi O Grain,

Very nice! That certainly fixed the cents problem. Thanks. I like your approach for the shipping. I did it a tiny bit different, and I added in the zero check for the shipping value:

$shipping = $shipping1;
if (( $total_sum > $shipping1_limit) && ( $total_sum < $shipping2_limit)) {
$shipping = $shipping2;
}
if ( $total_sum > $shipping2_limit) {
$shipping = $shipping3;
}
@zero_check = split(/\./,$shipping);
if ($zero_check[1] eq '') {
$shipping = $shipping .".00";
}
@zero_check = split(/\./,$total_sum);
if ($zero_check[1] eq '') {
$total_sum = $total_sum .".00";
}
$grand_total = $total_sum + $shipping;
@zero_check = split(/\./,$grand_total);
if ($zero_check[1] eq '') {
$grand_total = $grand_total .".00";
}


If I'm not mistaken, your method will set the shipping value to zero if the $total_sum = $shipping1. I figured it would be safest to always start it with the value of $shipping1 and adjust need be based on the order total. Other than that, it works great!

Going back to your previous post (} # end else order exists), it sure looks to me like you wrote the same thing before and after the edit??? Did I miss something?

Thanks,
Dan

p.s. I'm glad you found my suggestion worthy of taking the liberty with. Smile

Quote Reply
Re: shipping costs In reply to
Hi Dan,

Good observation about $shipping! Thanks!

About the "clarification" on the closing bracket: There is a small difference before and after my edit, and now when the EDIT function works I made the clarification in the posting blue. No big deal, but it was meant to clearify that the closing bracket should be put before the line &html_page_bottom. Or shouldn't it? Wink

Quote Reply
Re: shipping costs In reply to
Hi Dan,

I've noticed that the check for lost zeros in the summing up did not handle a lost single zero, so the the zero_check should be modified:

in db.cgi, sub sum_up_order
change to the red marked code

Code:

else {
$shipping = $shipping3;
}


@zero_check = split(/\./,$shipping);
if (length($zero_check[1]) == 0) {
$shipping = $shipping .".00";
}
elsif (length($zero_check[1]) == 1) {
$shipping = $shipping ."0";
}



@zero_check = split(/\./,$total_sum);


if (length($zero_check[1]) == 0) {
$total_sum = $total_sum .".00";
}
elsif (length($zero_check[1]) == 1) {
$total_sum = $total_sum ."0";
}


$grand_total = $total_sum + $shipping;
@zero_check = split(/\./,$grand_total);


if (length($zero_check[1]) == 0) {
$grand_total = $grand_total .".00";
}
elsif (length($zero_check[1]) == 1) {
$grand_total = $grand_total ."0";
}

A bit better ...Smile

Quote Reply
Re: Confirmation of address + help file added In reply to
Another stab...

Via a private mail I've been asked to have a confirmation of the given address details and also include a help function.

Now the user has to confirm the address and a help file can be reached from the bottom link bar.

In db.cgi
Insert the red code lines in the main menu in sub main:
Code:

elsif ($in{'create_order'}) { &html_create_order; }

elsif ($in{'verify_address'}) { &html_create_order; }
elsif ($in{'address_OK'}) { &html_create_order; }

elsif ($in{'add_order'}) { &html_add_order; }
In sub html_page_top add the javascript for the help window (red code lines)
Code:

<html><head><title>$html_title: $page_title</title>


<SCRIPT LANGUAGE="JavaScript">
< !-- Hide code

function Help(){

link = "http://yourdomain.com/dbman/help.html";
popupWin=window.open(link, "helpwin","height=300,width=300,left=600,top=80,scrollbars=yes,toolbar=no,resizable=no,location=no,directories=no,status=no");

popupWin.focus();

}
// End hide -- >
</SCRIPT>

At the end of sub html_footer add the link for the help file
Code:

print qq!| <A HREF="javascript:Help()"><b>Help</b></A> !;

print qq!|</font></p>!;

in sub html_create order form

after
<input type=hidden name="$db_key" value="$rec{$db_key}">

add
<input type=hidden name="verify_address" value="verify">



in sub html_create_order

after
if ($order_error < 1) {

add the following red marked lines
Code:

if(($in{'verify_address'} eq "Rectify Address") || ($in{'verify_address'} eq "verify")) {

$page_title = "Please verify your address";

&html_page_top;

# < -- Start page text -- >
print qq|
<$font>Is the address below correct?

In that case just press <b>Address OK</b>.

Otherwise correct your address and the press <b>Rectify Address</b>
<UL>
Email:<b> $in{'order_mail'}</b>

Name:<b> $in{'order_name'}</b>

Address:<b> $in{'order_address'}</b>

Zip code:<b> $in{'order_zipcode'}</b>

Postal address:<b> $in{'order_city'}</b>

</UL>
</font>
|;
# < -- End page text -->

&html_rectify_order_form;
}

else {
&create_order;
$page_title = "Your order has been prepared";
&html_page_top;

# < -- Start page text -- >
print qq|
<$font>Now you can start adding $merchandise to your order:</font></p>
|;
# < -- End page text -->

if ($in{'create_order'} || $in{'address_OK'}) {
&html_record_long(&get_record($in{$db_key}));
}
elsif ($in{'add_order'}) {
&html_view_search;
}
}
&html_footer;
&html_page_bottom;
}
else {
$page_title = "The form has not been filled in correctly";
In sub html_rectify_order_form

after
$submit_create_order= "Prepare your Order";

add

$submit_OK = "Address OK";
$submit_rectify ="Rectify Address";


and replace

<input type=hidden name="ID" value="$in{'ID'}">

with

<input type=hidden name="$db_key" value="$in{$db_key}">



and finally change the bottom part according to the red code
</TR>
</TABLE>
<CENTER>

Code:

|;

if(($in{'verify_address'}) && (!$order_error)){
print qq|
<input type="submit" name="address_OK" value="$submit_OK">
<input type="submit" name="rectify_address" value="$submit_rectify">
|;
}
else {
print qq|

<input type="submit" name="create_order" value="$submit_create_order">
|;
}

print qq|

</CENTER>
</FORM>



The help file should be put at http://yourdomain.com/dbman/help.html (or whatever you put in sub html_page_top). There is an example of the help file at the demo page:
http://tangokites.org/dbman/ called help_html.txt

I hope I got it all transferred right Smile. Anyway, the mod descripition is also updated.

Quote Reply
Re: Confirmation of address + help file added In reply to
Hi O Grain,

Thanks for catching the trailing zeros part, I didn't test it on items ending with a single zero. That works quite well now.

I did something similar for viewing the user info (address), but I didn't want to print everything back to the screen like credit card info. (It's on a secure server with encryption.) What I ended up doing was following your example of looking for lines beginning with an asterisk (*) for a product calculation and placed a hyphen in front of the user info lines that I wanted displayed in the order display and confirmation. I did this in sub create_order where it prints to the file. Then, in html.pl, I added:

foreach $line (@lines) {
if ($line =~ /^\-/) {
print "<$font_color>";
print $line;
print "</font>
";
}
els
if ($line =~ /^\*/) {
print $line;
print "
";
}


in sub html_check_order and sub html_send_order for displaying only those lines.

Cheers,
Dan


Quote Reply
Bug with call to non-existing sub fixed In reply to
There was a call to a sub fatal-error for failed opening of files. Since the sub fatal_error was not included and sub cgierr does more or less the same job, the call to fatal_error has been replaced with a call to sub cgierr in the following subs:

sub create_order
sub add_to_order
sub sum_up_order
sub send_order
sub html_add_order
sub html_send_order (3 times)
sub html_check_order
sub html_edit_order
sub html_change_order (2 times)

(Global replace would do the job Wink )

The address confirmation parts and the shipping cost calculations have also been improved. Instead of putting all new code here, I refer to the demo site where the updated mod description is available (with change history Smile ). Some color definition parameters that were missing in the mod description has been included.

Demo of ORDERnary: http://tangokites.org/dbman/

Quote Reply
Re: Confirmation of address + help file added In reply to
Hi Every Body,

I just came with an idea, why not use dbman as for database management and use another equally easy to setup script as a shopping a cart.

The Idea :

Put links in every porduct, when the link is clicked it adds or posts to a shoppingcart.cgi and the cart adds it as to a .txt database using cookies and when the person needs to checkout, he simply clicks on the check Out link which takes him to shopping cart 2.cgi which adds up all his cookies contents and prints out a goog looking, feture heavy ordr form !

Well I am on an e-commerce course and learning to perl & cgi !

I have downlaoded a few scripts, such as orderform managers ans complete shopping carts,

Now i'll try to make my own thing,

The results will be available in a two weeks time !

If any one can help me, or would like to share his experience, you are welcome to

Your's Truly

Rai Umair

This Post Comes form Rai !
Quote Reply
Can't Implement Order Mod In reply to
Hi,

i've implemented the user friendly html, short long display, and tested the script and everything works fine. however when I try to implement the order mod found at tangokites, the script stops working, saying that an internal error has occurred and that i should enable the debugging feature (which it already was).

I'm certain that i've followed the mod to the letter. would it have anything to do with the fact that i'm on a win2000 server? (sorry i'm a bit of newbie)

i stress that everything was working prior to implementing the mod changes.

i'll be eagerly awaiting a reply,

Quote Reply
Re: Can't Implement Order Mod In reply to
Hi Christopher,

I am pretty sure that there is nothing in the mod the would be machine specific, but I am a bit of a Perl newbie myself so I can't really tell.

=================================
Correction 2000-11-20:
Obviously there are a few things that don't work well on e.g. a win2000 system (like sendmail and system calls) Blush. I will try to ínclude such information in the mod description together with the alternative code that anyone provides.)
=================================

Is there no other message than to enable the debugging feature? What is the exakt error printout?

Could be a missing bracket...

Oh, BTW, just a few minutes ago I made a change to the mod and updated the description: The order file is now (after sending the order) renamed with a random extension which makes it possible to keep several orders from the same customer. (Thanks to youngjo of Bremen!)

This is at the end of sub html_send_order:
Code:

# Then rename the file with a random extension so the user can't use
# the back button in the browser to add more things...

srand;
$extension = rand;
$extension =~ s/0\.//;

$archive_file = "$order_file";
$archive_file =~ s/.txt/_$extension/;
system ('mv',"$orders_dir/$order_file","$orders_dir/$archive_file");
O grain

> > > >