Unique Order/Invoice Number Mod

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

Moderators: Koibito, Stefko, Randy, Rosey

Unique Order/Invoice Number Mod

Postby Steven Nyland » Thu Jan 30, 2003 10:47 am

Unique Order/Invoice Number Mod
(modification for the perl script / NOP Cart verion 4.4.0)

It is possible to have NOP Cart create a order/invoice nr for each order submitted (and processed by the Perl script). There are two different way's of doing this. Option one is the 'date trick' where the order number will be created based on the date & time of the order. Option two is a custom order number database that can be tweaked fully. Let's start with option 1:

*********************************
Order/Invoice Number - Option 1
*********************************

  • Step 1 : Open your checkout.pl file in a Perl Script editor (e.g. PCE - free download at http://www.perlvision.com)
  • Step 2 : Find the following line:

    print MAIL "Order Date: $months[$month] $day, $year $hour:$min:$sec \n"; (line 506)

    Below this line, copy & paste the following line:

    print MAIL "Order Number: $OrdNum \n";
  • Step 3 : Find the following line:

    print CSVF "\""; (line 316)

    Below this line, copy & paste the following lines:

    print CSVF "$OrdNum";
    print CSVF "\",\"";

  • Step 4 : Find the following line:

    print MAIL "Order Date: $months[$month] $day, $year $hour:$min:$sec \n"; (line 259)

    Below this line, copy & paste the following line:

    print MAIL "Order Number: $OrdNum \n";
  • Step 5 : Find the following line:

    if( $mode eq "BOTH" || $mode eq "EMAIL") { (line 250)

    Above this line, copy & paste the following line:

    $OrdNum = timegm($sec,$min,$hour,$mday,$mon,$year,$wday,$yday);
Above code creates an ordernumber based on the date & time (miliseconds) then writes the created order number on both e-mail confirmations (to you and to the customer) and finally it writes the order to the CSV file.

*********************************
Order/Invoice Number - Option 2
*********************************
  • Step 1 : Create a new txt (e.g. with Notepad) file and name it ordernbr.dat,
  • Step 2 : initialize the ordernbr.dat file by entering 000000 as the first line,
  • Step 3 : Save the ordernbr.dat file,
  • Step 4 : Upload the ordernbr.dat file to your CGI-BIN directory and set file permissions to 766 (CHMOD 766).
    (The ordernbr.dat file should be in the same directory as your checkout.pl script),
  • Step 5 : Open your checkout.pl file in a Perl Script editor (e.g. PCE - free download at http://www.perlvision.com)
  • Step 6 : Find the following line:

    print MAIL "Order Date: $months[$month] $day, $year $hour:$min:$sec \n"; (line 506)

    Below this line, copy & paste the following line:

    print MAIL "Order Number: $this_Nbr \n";
  • Step 7 : Find the following line:

    print CSVF "\""; (line 316)

    Below this line, copy & paste the following lines:

    print CSVF "$this_Nbr";
    print CSVF "\",\"";

  • Step 8 : Find the following line:

    print MAIL "Order Date: $months[$month] $day, $year $hour:$min:$sec \n"; (line 259)

    Below this line, copy & paste the following line:

    print MAIL "Order Number: $this_Nbr \n";
  • Step 9 : Find the following line:

    if( $mode eq "BOTH" || $mode eq "EMAIL") { (line 250)

    Above this line, copy & paste the following code snipplet:

    ## BEGIN Custom Order Number
    $orderNbr_Data = 'ordernbr.dat';

    if (open(SEQUENCE, "<$orderNbr_Data")) { # Open file for reading (output)
    @lines = <SEQUENCE>; # Read first line
    close(SEQUENCE); # Close file
    @nbr_Info = split(/\|/, $lines[0]); # Separate variables
    $last_Nbr = $nbr_Info[0]; # Read variable
    }

    if (defined $last_Nbr) {
    $this_Nbr = $last_Nbr + 1; # Increment Order Nbr by 1
    open(SEQUENCE, ">$orderNbr_Data"); # Open the file for writing (input)
    print SEQUENCE "$this_Nbr\n"; # Write to file
    close(SEQUENCE); # Close the file
    }

    ## END Custom Order Number

Option two creates an ordernumber based on the initial value as defined in the file order_nbr.dat. It increments the number with '1', writes the created order number on both e-mail confirmations (to you and to the customer) and finally it writes the order to the CSV file.

Good luck,

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 ...

No worky for me

Postby caranddriver » Wed Feb 26, 2003 10:37 am

:shock:

I tried using the Option 1 "Unique Order Number"
and each time I add the code it breaks my checkout.pl file

I can remove all the lines and I am back in business.

The "print" lines look fine, is there a prob with the variable line, the last snip? Yes, I did put it ahead of line 250.

Thanks
caranddriver
 
Posts: 8
Joined: Tue Feb 25, 2003 12:40 pm
Location: Washington State

Postby john_mac » Thu Mar 06, 2003 4:05 pm

TOP TIP! I would recommend using the date/time method rather than the consecutive number method if you don't want your competitors knowing your business!

If you use consecutive order numbers, you may find that your competitors will proceed with a dummy order as far as the payment page in order to see how many orders have been placed since last time they checked. Not only does this reveal info that you may want to keep to yourself, it also messes up your conversion stats.
John Mac
john_mac
 
Posts: 25
Joined: Fri Sep 27, 2002 7:16 pm
Location: Ireland

TimeStamp working Yet?

Postby Michael » Sat Apr 19, 2003 12:39 pm

Has anyone answered why the timestamp version (Option 1) breaks the checkout.pl, because I just tried it and couldn't get it to work. Looks like I'll have to go down the *.dat route for now.

:?
http://www.sterling-bond.com - Escrow merchant accounts. Creating A World Of Trust.
"/" Stroke, what you do to make a woman happy.
"\" Backstroke, what you do to a woman after you've made her happy.
Michael
 
Posts: 80
Joined: Fri Aug 09, 2002 10:18 pm
Location: UK

Half an answer

Postby Michael » Sat Apr 19, 2003 3:23 pm

Well, I'm not really expert in perl but from a quick browse around the net I've found that the timegm() function is dependent on loading an external library to work.
No idea how, or whether it'd be supported by my isp. I did make one attempt based on some advice picked up on reading the net, but no-go.
Unless someone can offer an idiot-proof guide to how you do it?
:P
http://www.sterling-bond.com - Escrow merchant accounts. Creating A World Of Trust.
"/" Stroke, what you do to make a woman happy.
"\" Backstroke, what you do to a woman after you've made her happy.
Michael
 
Posts: 80
Joined: Fri Aug 09, 2002 10:18 pm
Location: UK

Postby WebRecka » Thu Apr 24, 2003 12:34 am

Bah looks like its time for webrecka to save the day.

If your having trouble using the top method do the following:

SIMPLE METHOD
replace what he said this:
Code: Select all
$OrdNum = timegm($sec,$min,$hour,$mday,$mon,$year,$wday,$yday);


With this
Code: Select all
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);

$OrdNum=qq~$day, $mday of $month, $year at $hour:$min:$sec~;


Or if you want to format the time yourself, simply rearrange the vars in the second half of the code i posted, names are self explanitory mday=month day= 1-31
wday=1-7
mon=1-12
END SIMPLE METHOD

ADVANCED(harder) METHOD

If youde like FULL TIME CONVERSION, from numbers to words (like monday january etc.) do the following:

1. Go through the code looking for this:
sub populateDateVar { (around line 205)

2. If you find that go down a bit make sure you find this :
$todaysdate = "$months[$month] $day, $year $hour:$min:$sec";

If not add it about 30 lines down before the }.

If and ONLY if you dont find sub populateDateVar then add this anywere:

Code: Select all

sub populateDateVar {
   @months = ();
   push(@months,"January");
   push(@months,"February");
   push(@months,"March");
   push(@months,"April");
   push(@months,"May");
   push(@months,"June");
   push(@months,"July");
   push(@months,"August");
   push(@months,"September");
   push(@months,"October");
   push(@months,"November");
   push(@months,"December");
   @days = ();
   push(@days,"Sunday");
   push(@days,"Monday");
   push(@days,"Tuesday");
   push(@days,"Wednesday");
   push(@days,"Thursday");
   push(@days,"Friday");
   push(@days,"Saturday");
   ($sec,$min,$hour,$day,$month,$year,$day2) =
   (localtime(time))[0,1,2,3,4,5,6];
   if ($sec < 10) { $sec = "0$sec"; }
   if ($min < 10) { $min = "0$min"; }
   if ($hour < 10) { $hour = "0$hour"; }
   if ($day < 10) { $day = "0$day"; }
   $year += "1900";
   chomp($year);
   $todaysdate = "$months[$month] $day, $year $hour:$min:$sec";
}


3. After you have both those things add this in replace of $OrdNum = timegm($sec,$min,$hour,$mday,$mon,$year,$wday,$yday); (originally posted code) [NOTE: This goes in the same spot that the original code would have]


Code: Select all
&populateDateVar;
$OrdNum=$todaysdate;


END ADVANCED METHOD

If your REALLY confused right now, scroll up and do the simple method



Good luck, Web
Last edited by WebRecka on Thu Apr 24, 2003 12:41 am, edited 2 times in total.
WebRecka
Guru
 
Posts: 37
Joined: Sat Mar 15, 2003 7:58 pm

Second Option is best

Postby Michael » Thu Apr 24, 2003 5:18 am

You're right about the second option - and it's been staring me in the face for the last week!
:roll:

If you want to keep the current date format then just copy all the code that generates and formats the date and alter to create a unique s/n out of it.

I know for certain the date code works...

sub populateDateVar {
@months = ();
push(@months,"January");
push(@months,"February");
.....

so just replace the names of weeks and months for their numbers and play around with the output to get your desired s/n

.....
sub populateDateVar {
@months = ();
push(@months,"01"); # jan.
push(@months,"02"); # feb.
.....

S/N: $year$months[$month]$day$hour$min:$sec
.....

Thanks for reminding me.
:lol:
http://www.sterling-bond.com - Escrow merchant accounts. Creating A World Of Trust.
"/" Stroke, what you do to make a woman happy.
"\" Backstroke, what you do to a woman after you've made her happy.
Michael
 
Posts: 80
Joined: Fri Aug 09, 2002 10:18 pm
Location: UK

Unique order number for PHP script file??

Postby mezza » Mon Apr 28, 2003 11:43 pm

Hello World!!

What about a unique order number for PHP file?
How do i go about doing it?

Mezza
I am learning. Please teach me
mezza
 
Posts: 18
Joined: Sun Mar 30, 2003 12:38 am
Location: Singapore

Modify Date Function

Postby Michael » Wed Apr 30, 2003 6:53 pm

Can you copy and modify the date function in the php version as I've suggested for the pl version?

:P
http://www.sterling-bond.com - Escrow merchant accounts. Creating A World Of Trust.
"/" Stroke, what you do to make a woman happy.
"\" Backstroke, what you do to a woman after you've made her happy.
Michael
 
Posts: 80
Joined: Fri Aug 09, 2002 10:18 pm
Location: UK

Postby sparkiii » Fri May 02, 2003 4:34 am

Thanks once again, it works a treat
sparkiii
WebMaster
 
Posts: 35
Joined: Thu Feb 20, 2003 2:18 pm
Location: Australia

Unable to find Line 250

Postby Maree » Mon May 12, 2003 2:52 pm

I can do all the steps but Step 9, as I cannot fine the line if ( $mode etc
Could some tell me what it should come after so that I can add it

Thanks

Maree :?
Maree
 
Posts: 18
Joined: Sat May 10, 2003 9:40 am
Location: Australia

Heads for the print MAIL

Postby Michael » Mon May 12, 2003 6:57 pm

That line -Step 9 - if (mode ..... may not be on line 250 - it's the instruction that begins each print MAIL or the CSV output function - so just look for the beginning of the print MAIL commands and you ought to find it there.
8)
http://www.sterling-bond.com - Escrow merchant accounts. Creating A World Of Trust.
"/" Stroke, what you do to make a woman happy.
"\" Backstroke, what you do to a woman after you've made her happy.
Michael
 
Posts: 80
Joined: Fri Aug 09, 2002 10:18 pm
Location: UK

Missing Line

Postby Maree » Tue May 13, 2003 4:43 am

Thanks Michael

I found the line


Maree :D
Maree
 
Posts: 18
Joined: Sat May 10, 2003 9:40 am
Location: Australia

Postby Carl » Sat Aug 16, 2003 6:49 am

Is it possible for WebRecka to save the day again?

Could someone please re-write the mod to work in ASP?

Thanks in advance!

Carl.
Don't take candy from strangers unless they offer you a ride.
Carl
 
Posts: 25
Joined: Sat Apr 19, 2003 7:20 am
Location: Behind you...

Option 1 and Option2

Postby krismcewan » Wed Aug 27, 2003 11:13 am

I have managed to integrate option1 and option2 order numbers.

Add
"Order Number: $OrdNum-$this_Nbr \n";
into the mail/csv parts and add in the
$OrdNum part to the option 2 code just before the
## END Custom Order Number


I alsoplayed around with the order of the date and time number to make it neater.

You can see this as below.


## BEGIN Custom Order Number
$orderNbr_Data = 'ordernbr.dat';

if (open(SEQUENCE, "<$orderNbr_Data")) { # Open file for reading (output)
@lines = <SEQUENCE>; # Read first line
close(SEQUENCE); # Close file
@nbr_Info = split(/\|/, $lines[0]); # Separate variables
$last_Nbr = $nbr_Info[0]; # Read variable
}

if (defined $last_Nbr) {
$this_Nbr = $last_Nbr + 1; # Increment Order Nbr by 1
open(SEQUENCE, ">$orderNbr_Data"); # Open the file for writing (input)
print SEQUENCE "$this_Nbr\n"; # Write to file
close(SEQUENCE); # Close the file
}
#($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);

$OrdNum=qq~$year$hour$min$day$month~;

## END Custom Order Number

if( $mode eq "BOTH" || $mode eq "EMAIL") {
# Send email order to you...
open (MAIL,"|$mailprogram");
print MAIL "To: $youremail\n";
print MAIL "From: $b_email\n";
print MAIL "Subject: New Online Order\n";
print MAIL "\n\n";
print MAIL "A new order has been received. A summary of this order appears below.\n";
print MAIL "\n";
print MAIL "Order Date: $months[$month] $day, $year $hour:$min:$sec \n";
print MAIL "Order Number: $OrdNum-$this_Nbr \n";


produces

a new order has been received. A
summary of this order appears below.

Order Date: August 27, 2003 12:04:42
Order Number: 20031204277-6


Hopr this is usefull for someone
krismcewan
 
Posts: 13
Joined: Mon Aug 25, 2003 6:02 am
Location: Scotland

Next

Return to Modifications

Who is online

Users browsing this forum: No registered users and 0 guests

cron