eXtropia: the open web technology company
Technology | Support | Tutorials | Development | About Us | Users | Contact Us
Development resources
 ::   WebWare 2.1 (Perl)
 ::   WebWare 2.0 (Java)
 ::   Cool hacks
Radical Hacks
Continuing a Browser Session  
sent in the following hack...

This is my addition to the Woodruff Cookies Hack, this allows user to end the browser session and come back later to finish ordering. This will set the expiration of the cookie to the set number of days to hold the cart. Here's the code:

##############Step 1
##############find these lines in the woodruff hack

&assign_a_unique_shopping_cart_id; 	#Get new cart 
&SetCookies('cart_id',"$cart_id"); 		#Set cookie as the cart_id 

###########change to:

&assign_a_unique_shopping_cart_id; 	#Get new cart 
                    $expiredate=&get_expire_date;
			  &SetCookieExpDate($expiredate);
			  &SetCookies('cart_id',"$cart_id"); 		#Set cookie as the cart_id 

###########Step 2  Add this subroutine to the cookies library

#################################################################
#                      get_expire_date Subroutine                 ####   jb 6-10-01 ##
#################################################################
# get expire date string  formatted as: Wdy, DD-Mon-YYYY HH:MM:SS GMT,
# get_expire_date is used to get the current date 
##add the sc_number_of_days_keep_old_carts  and
# format it into a readable form.  The subroutine takes no
# arguments and is called with the following syntax:
#
# $expiredate = &get_expire_date;
#
# It will return the value of the current date plus user defined number of days to hold
# must assign it to a variable in the calling routine if
# you are going to use the value.

sub get_expire_date
  {

# The subroutine begins by defining some local working
# variables

  local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$date,$holddays,$totalmonthdays);
  local (@days, @months); 
 
  @days = ('Sun','Mon','Tue','Wed','Thu',
           'Fri','Sat');
  @months = ('Jan','Feb','Mar','Apr','May','Jun','Jul',
             'Aug','Sep','Oct','Nov','Dec');

##this is where you asign the number of days to hold the cookie
###$sc_number_days_keep_old_carts MUST NOT contain decimals or be greater than 28

$holddays=$sc_number_days_keep_old_carts;

# Next, it uses the localtime command to get the current
# time, from the value returned by the time
# command, splitting it into variables.




########use Date::Calc; ###### it would be nice if i could do this 6-11-01
#########$expiredate= &DateCalc($expiredate,"+7 days");


 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time); 

######6-12-01 jb######### simple patch  for up to 28 days

$mday += $holddays;

if (($mon == 3)||($mon == 5)||($mon == 8)||($mon == 10))
	{$totalmonthdays = 30;}
if  ($mon == 1)
	{
		if (($year == 104)||($year == 108)||($year == 112)||($year == 116))
			{$totalmonthdays = 29;}
		else {$totalmonthdays = 28;}
	}
else {$totalmonthdays = 31;}

if ($mday > $totalmonthdays)
	{
	      $mday -= $totalmonthdays;
		$mon += 1;
		if ($mon > 11)	
			{$mon -= 11;$year += 1;}
 	}  ####that should do it , now the date is advanced the set amount of days up to 28


		# Then the script formats the variables and assign them to
		# the final $date variable.  Note that $sc_current_century
		# is defined in web_store.setup.  Since the 20th century
		# is really 1900-1999, we'll need to subtract 1 from this
		# value in order to format the year correctly.

  if ($hour < 10) 
    { 
    $hour = "0$hour"; 
    }
  if ($min < 10) 
    { 
    $min = "0$min"; 
    }
  if ($sec < 10) 
    { $sec = "0$sec"; 
    }
  $year += 1900;

# expiredate Should be defined as: Wdy, DD-Mon-YYYY HH:MM:SS GMT 

  $expiredate = "$days[$wday], $mday-$months[$mon]-$year $hour\:$min\:$sec GMT";
  return $expiredate;
  }       

#######################