Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Display 'delivery by Christmas Eve if ordered by' module

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 11-22-2005, 08:40 PM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default Display 'delivery by Christmas Eve if ordered by' module

Just realized I hadn't posted any mods in a while. Here is my simple Christmas present to everyone this year (sorry I didn't post it early November). I don't know if someone else has already done this or if something similar is included in the Xcart Xmas module, but here you go.

This code requires that you have an extra field (or a custom database column) of some sort with the earliest availability before it ships. For instance, we have a number of products that ship several days, and sometimes weeks, after being ordered due to product customizations. This would go in place of 'YOUR_EXTRA_FIELD' in the code. This code parses plain english time periods in that 'availability' field of the form "24 hours", "2-3 days", "1 week", "5-7 business days" etc. and uses that to calculate the date that the product must be ordered if it is to reach the customer by Christmas Eve. The code is commented throughout so examine that for further information.

Create the file xmas_delivery_time.php in the directory modules and add the code below for either Xcart 3.5 or Xcart 4.0 into that. Add the include statement include($xcart_dir.'/modules/xmas_delivery_time.php'); at the point indicated.

If you have Xcart 3.5 you need to use this first code snippet and add the include statement inside the function func_select_product() right after $product = func_query_first() in the file func.php.

Code:
<?php # $Id: xmas_delivery_time.php,v 1.1.0 2005/11/22 15:55:45 bjoshua Exp $ ############################################################################## ## ## Christmas Delivery Time ## ## ############################################################################## ## Checks if there is enough time to make a delivery by Christmas Eve and ## ## calculates the earliest date needed to receive the product in time. ## ## This code is self-activating year after year. ## ############################################################################## ## Initially Created: 11/13/2005 if (!defined('XCART_START')) { header('Location: ../'); exit('Access Denied!'); } /** * @author bjoshua * @copyright NuAlpha, Inc. * @todo Take timezones into account on the client side to accurately extend order by time to include time of day. */ ### NOTE ### # The constant 'IS_ROBOT' is for Xcart 4's built-in bot detection or if you have implemented my previously # posted "Search Engine Activity Detector" mod: http://forum.x-cart.com/viewtopic.php?p=114696#114696 ### NOTE ### if ($product && !@IS_ROBOT) { $one_day = 24 * 60 * 60; // Define a day in seconds. $current_timestamp = time(); # Get the current year. $current_year = getdate(); $current_year = $current_year['year']; # November is usually when people begin Christmas shopping. $start_of_season = strtotime('1 November '.$current_year); # 6 PM is the average time deliveries stop (between UPS, USPS, FedEx, etc.) $xmas_eve_timestamp = strtotime('24 December '.$current_year.' 6pm'); # Check if Christmas Eve falls on a weekday. $christmas_eve_date = getdate($xmas_eve_timestamp); # Push back the required arrival date if Christmas Eve falls on a weekend. if ($christmas_eve_date['weekday'] == 'Saturday') $xmas_eve_timestamp -= $one_day; elseif ($christmas_eve_date['weekday'] == 'Sunday') $xmas_eve_timestamp -= $one_day * 2; # NOTE: Remove the 'Saturday' checks if your shipping carrier makes standard deliveries or pickups on that day. # Push forward the date if today is not a weekday, assuming shipments aren't made on weekends. if ($current_date['weekday'] == 'Saturday') $current_timestamp += $one_day * 2; elseif ($current_date['weekday'] == 'Sunday') $current_timestamp += $one_day; if ($current_timestamp < $xmas_eve_timestamp && $current_timestamp > $start_of_season) { # Capture the maximum time needed (with optional minimum) to complete and ship the product and the unit of time used. # Change the regular expression below if you need to, but ensure you keep the named captures assigned correctly. if (preg_match('/(?P<min_time>[0-9]*) ?-? ?(?P<max_time>[0-9]+).*?(?P<unit>hour|day|week|month)/i', $product['YOUR_EXTRA_FIELD'], $matches)) { if (empty($matches['min_time'])) $matches['min_time'] = 0; # Convert units to seconds. For instance, "3-5 Business Days" would be converted to 5 days worth of seconds. switch (strtolower($matches['unit'])) { case 'day': $max_time_till_shipped = $matches['max_time'] * $one_day; $min_time_till_shipped = $matches['min_time'] * $one_day; break; case 'week': $max_time_till_shipped = $matches['max_time'] * 7 * $one_day; $min_time_till_shipped = $matches['min_time'] * 7 * $one_day; break; case 'month': $max_time_till_shipped = $matches['max_time'] * 4 * 7 * $one_day; $min_time_till_shipped = $matches['min_time'] * 4 * 7 * $one_day; break; default: // Default to hours. $max_time_till_shipped = $matches['max_time'] * 60 * 60; $min_time_till_shipped = $matches['min_time'] * 60 * 60; # NOTE: Most online stores ship within 24 hours. If you don't have this default defined in the # extra field then change the two $matches['...'] in the switch default above to the number 24. } # It is assumed that work on the product will only be done on business days, so weekends count as lost time. # Change this value to 6 if work is done on Saturdays or simply comment out condition block if work done all week. if ($max_time_till_shipped > 5 * $one_day) { $weeks_remainder = ($max_time_till_shipped / $one_day) % 7; $num_weeks = ($max_time_till_shipped - ($weeks_remainder * $one_day)) / $one_day / 7; $max_time_till_shipped += $num_weeks * 2 * $one_day + ($weeks_remainder > 5 ? $one_day : 0); } $std_max_delivery_time = 7 * $one_day; // Most carriers make standard deliveries in 7 days or less. $exp_max_delivery_time = 3 * $one_day; // Most carriers make expedited deliveries in 3 days or less. $product['xmas_delivery']['time'] = $xmas_eve_timestamp - $max_time_till_shipped - $std_max_delivery_time; $product['xmas_delivery']['method'] = 'standard'; $order_by_date = getdate($product['xmas_delivery']['time']); # Push back the time if the order by date is not a weekday. if ($order_by_date['weekday'] == 'Saturday') $product['xmas_delivery']['time'] -= $one_day; elseif ($order_by_date['weekday'] == 'Sunday') $product['xmas_delivery']['time'] -= $one_day * 2; # Standard delivery won't make it in time. if ($product['xmas_delivery']['time'] < $current_timestamp) { $product['xmas_delivery']['time'] = $xmas_eve_timestamp - $max_time_till_shipped - $exp_max_delivery_time; $product['xmas_delivery']['method'] = 'expedited'; $order_by_date = getdate($product['xmas_delivery']['time']); if ($order_by_date['weekday'] == 'Saturday') $product['xmas_delivery']['time'] -= $one_day; elseif ($order_by_date['weekday'] == 'Sunday') $product['xmas_delivery']['time'] -= $one_day * 2; } # Expedited delivery also won't make it in time. Maybe with min time needed for turnaround. if ($product['xmas_delivery']['time'] < $current_timestamp && $min_time_till_shipped > 0) { $product['xmas_delivery']['time'] = $xmas_eve_timestamp - $min_time_till_shipped - $exp_max_delivery_time; $product['xmas_delivery']['method'] = 'maybe_expedited'; $order_by_date = getdate($product['xmas_delivery']['time']); if ($order_by_date['weekday'] == 'Saturday') $product['xmas_delivery']['time'] -= $one_day; elseif ($order_by_date['weekday'] == 'Sunday') $product['xmas_delivery']['time'] -= $one_day * 2; } # Even with the minimum time needed, expedited delivery still isn't fast enough. if ($product['xmas_delivery']['time'] < $current_timestamp) { $product['xmas_delivery']['time'] = 0; $product['xmas_delivery']['method'] = 'none'; } } } } ?>

If you have Xcart 4.0 you need to use this second code snippet and add the include statement right after the line include $xcart_dir."/modules/Extra_Fields/extra_fields.php"; in the file product.php. Please note that this module has not been extensively tested in Xcart 4.0.
Code:
<?php # $Id: xmas_delivery_time.php,v 1.1.0 2005/11/22 15:55:45 bjoshua Exp $ ############################################################################## ## ## Christmas Delivery Time ## ## ############################################################################## ## Checks if there is enough time to make a delivery by Christmas Eve and ## ## calculates the earliest date needed to receive the product in time. ## ## This code is self-activating year after year. ## ############################################################################## ## Initially Created: 11/13/2005 if (!defined('XCART_START')) { header('Location: ../'); exit('Access Denied!'); } /** * @author bjoshua * @copyright NuAlpha, Inc. * @todo Take timezones into account on the client side to accurately extend order by time to include time of day. */ if (!empty($extra_fields) && !@IS_ROBOT) { $one_day = 24 * 60 * 60; // Define a day in seconds. $current_timestamp = time(); # Get the current year. $current_year = getdate(); $current_year = $current_year['year']; # November is usually when people begin Christmas shopping. $start_of_season = strtotime('1 November '.$current_year); # 6 PM is the average time deliveries stop (between UPS, USPS, FedEx, etc.) $xmas_eve_timestamp = strtotime('24 December '.$current_year.' 6pm'); # Check if Christmas Eve falls on a weekday. $christmas_eve_date = getdate($xmas_eve_timestamp); # Push back the required arrival date if Christmas Eve falls on a weekend. if ($christmas_eve_date['weekday'] == 'Saturday') $xmas_eve_timestamp -= $one_day; elseif ($christmas_eve_date['weekday'] == 'Sunday') $xmas_eve_timestamp -= $one_day * 2; # NOTE: Remove the 'Saturday' checks if your shipping carrier makes standard deliveries or pickups on that day. # Push forward the date if today is not a weekday, assuming shipments aren't made on weekends. if ($current_date['weekday'] == 'Saturday') $current_timestamp += $one_day * 2; elseif ($current_date['weekday'] == 'Sunday') $current_timestamp += $one_day; if ($current_timestamp < $xmas_eve_timestamp && $current_timestamp > $start_of_season) { # Capture the maximum time needed (with optional minimum) to complete and ship the product and the unit of time used. # Change the regular expression below if you need to, but ensure you keep the named captures assigned correctly. if (preg_match('/(?P<min_time>[0-9]*) ?-? ?(?P<max_time>[0-9]+).*?(?P<unit>hour|day|week|month)/i', $extra_fields['YOUR_EXTRA_FIELD'], $matches)) { if (empty($matches['min_time'])) $matches['min_time'] = 0; # Convert units to seconds. For instance, "3-5 Business Days" would be converted to 5 days worth of seconds. switch (strtolower($matches['unit'])) { case 'day': $max_time_till_shipped = $matches['max_time'] * $one_day; $min_time_till_shipped = $matches['min_time'] * $one_day; break; case 'week': $max_time_till_shipped = $matches['max_time'] * 7 * $one_day; $min_time_till_shipped = $matches['min_time'] * 7 * $one_day; break; case 'month': $max_time_till_shipped = $matches['max_time'] * 4 * 7 * $one_day; $min_time_till_shipped = $matches['min_time'] * 4 * 7 * $one_day; break; default: // Default to hours. $max_time_till_shipped = $matches['max_time'] * 60 * 60; $min_time_till_shipped = $matches['min_time'] * 60 * 60; # NOTE: Most online stores ship within 24 hours. If you don't have this default defined in the # extra field then change the two $matches['...'] in the switch default above to the number 24. } # It is assumed that work on the product will only be done on business days, so weekends count as lost time. # Change this value to 6 if work is done on Saturdays or simply comment out condition block if work done all week. if ($max_time_till_shipped > 5 * $one_day) { $weeks_remainder = ($max_time_till_shipped / $one_day) % 7; $num_weeks = ($max_time_till_shipped - ($weeks_remainder * $one_day)) / $one_day / 7; $max_time_till_shipped += $num_weeks * 2 * $one_day + ($weeks_remainder > 5 ? $one_day : 0); } $std_max_delivery_time = 7 * $one_day; // Most carriers make standard deliveries in 7 days or less. $exp_max_delivery_time = 3 * $one_day; // Most carriers make expedited deliveries in 3 days or less. $product_info['xmas_delivery']['time'] = $xmas_eve_timestamp - $max_time_till_shipped - $std_max_delivery_time; $product_info['xmas_delivery']['method'] = 'standard'; $order_by_date = getdate($product_info['xmas_delivery']['time']); # Push back the time if the order by date is not a weekday. if ($order_by_date['weekday'] == 'Saturday') $product_info['xmas_delivery']['time'] -= $one_day; elseif ($order_by_date['weekday'] == 'Sunday') $product_info['xmas_delivery']['time'] -= $one_day * 2; # Standard delivery won't make it in time. if ($product_info['xmas_delivery']['time'] < $current_timestamp) { $product_info['xmas_delivery']['time'] = $xmas_eve_timestamp - $max_time_till_shipped - $exp_max_delivery_time; $product_info['xmas_delivery']['method'] = 'expedited'; $order_by_date = getdate($product_info['xmas_delivery']['time']); if ($order_by_date['weekday'] == 'Saturday') $product_info['xmas_delivery']['time'] -= $one_day; elseif ($order_by_date['weekday'] == 'Sunday') $product_info['xmas_delivery']['time'] -= $one_day * 2; } # Expedited delivery also won't make it in time. Maybe with min time needed for turnaround. if ($product_info['xmas_delivery']['time'] < $current_timestamp && $min_time_till_shipped > 0) { $product_info['xmas_delivery']['time'] = $xmas_eve_timestamp - $min_time_till_shipped - $exp_max_delivery_time; $product_info['xmas_delivery']['method'] = 'maybe_expedited'; $order_by_date = getdate($product_info['xmas_delivery']['time']); if ($order_by_date['weekday'] == 'Saturday') $product_info['xmas_delivery']['time'] -= $one_day; elseif ($order_by_date['weekday'] == 'Sunday') $product_info['xmas_delivery']['time'] -= $one_day * 2; } # Even with the minimum time needed, expedited delivery still isn't fast enough. if ($product_info['xmas_delivery']['time'] < $current_timestamp) { $product_info['xmas_delivery']['time'] = 0; $product_info['xmas_delivery']['method'] = 'none'; } } } } ?>

Insert the following code into the customer/main/product.tpl Smarty template anywhere you'd like it to show up. Customize the appearance and wording of the below as you'd like.

Code:
{if $product.xmas_delivery} <p style="border:2px dotted DarkRed;"> {if $product.xmas_delivery.method eq 'standard'} To be certain this product will arrive by Christmas Eve, order by <font color="Green">{$product.xmas_delivery.time|date_format:'%A, %B %e'}</font>. {elseif $product.xmas_delivery.method eq 'expedited'} This product should arrive by Christmas Eve if ordered by <font color="Green">{$product.xmas_delivery.time|date_format:'%A, %B %e'} and shipped using an expedited delivery method.</font>. {elseif $product.xmas_delivery.method eq 'maybe_expedited'} It is possible that this could arrive by Christmas Eve if an expedited delivery method is used if ordered by <font color="Green">{$product.xmas_delivery.time|date_format:'%A, %B %e'}</font>. {else} It is not likely that this product will arrive by Christmas Eve if ordered now. {/if} </p> {/if}

Please post any code improvements or fixes if you come across them.

Let me know how it works out!
__________________
X-Cart Pro 4.5.5 Platinum
X-Payments 1.0.6
PHP 5.3.14
MySQL 5.1.68
Apache 2.2.23
Reply With Quote
  #2  
Old 11-24-2005, 10:32 AM
 
markwhoo markwhoo is offline
 

X-Adept
  
Join Date: Nov 2003
Posts: 799
 

Default

Happy Holidays NuAlpha!

Great Mod Idea!

Just one question 4 U...

The 3.5 version, is it close maybe to the 3.4 version code?

I have a 4.1 store I do not use due to speed issues, but I do have a screaming 3.4 store open 4 business... lol

Thanks for the mod!
__________________
vs 4.1.12
Reply With Quote
  #3  
Old 11-25-2005, 01:16 PM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default

Quote:
Originally Posted by markwhoo
The 3.5 version, is it close maybe to the 3.4 version code?

Unfortunately I don't know if this works on 3.4. I don't have a 3.4 store setup to test it on at the moment.
__________________
X-Cart Pro 4.5.5 Platinum
X-Payments 1.0.6
PHP 5.3.14
MySQL 5.1.68
Apache 2.2.23
Reply With Quote
  #4  
Old 11-25-2005, 01:55 PM
 
markwhoo markwhoo is offline
 

X-Adept
  
Join Date: Nov 2003
Posts: 799
 

Default

Well, Sadly it does not work for 3.4 version that is.

I uploaded everything. At first had an issue with finding the xmas php file in modules, corrected that and then nothing.

So, looks like in my case, a simple but old method that sux would be a crude countdown script, lol.

Thanks though, looked like a nice mod.
__________________
vs 4.1.12
Reply With Quote
  #5  
Old 12-01-2005, 08:55 AM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default

Has anyone else tried this module?

How would this work better for your situation or products setup on your site?
__________________
X-Cart Pro 4.5.5 Platinum
X-Payments 1.0.6
PHP 5.3.14
MySQL 5.1.68
Apache 2.2.23
Reply With Quote
  #6  
Old 12-01-2005, 08:58 AM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default

Quote:
Originally Posted by markwhoo
Well, Sadly it does not work for 3.4 version that is.
Can you email me a zip of some of the latest default Xcart 3.4 code? I didn't see it in the file area of the Qualiteam Xcart support pages.

I think I'll just need the contents of the customer template directory and the following directories zipped up:
/include
/customer
/modules

If I can find time this weekend I will see if I can get it working for version 3.4 if doing so is feasible.

PM me if you can send it and I will provide you with an email to attach it to.
__________________
X-Cart Pro 4.5.5 Platinum
X-Payments 1.0.6
PHP 5.3.14
MySQL 5.1.68
Apache 2.2.23
Reply With Quote
  #7  
Old 12-02-2005, 04:22 AM
  HWT's Avatar 
HWT HWT is offline
 

eXpert
  
Join Date: Jan 2005
Location: Massachusetts, USA
Posts: 392
 

Default

Tried to get this working in 4.0.13, but nothing showed up. I'm curious if I got the extra field wrong or something. Mine's 'Ships In:' Would love to get this up and running.
__________________
x-cart 4.0.13 and 4.1.7 and 4.1.10
Reply With Quote
  #8  
Old 12-05-2005, 04:04 PM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default

Quote:
Originally Posted by HWT
Tried to get this working in 4.0.13, but nothing showed up. I'm curious if I got the extra field wrong or something. Mine's 'Ships In:' Would love to get this up and running.

Will try to take a look at it if I can. The ante just got upped here and we are scarely able to keep a handle on order fulfillment from all the traffic this season.
__________________
X-Cart Pro 4.5.5 Platinum
X-Payments 1.0.6
PHP 5.3.14
MySQL 5.1.68
Apache 2.2.23
Reply With Quote
  #9  
Old 12-05-2005, 04:28 PM
  HWT's Avatar 
HWT HWT is offline
 

eXpert
  
Join Date: Jan 2005
Location: Massachusetts, USA
Posts: 392
 

Default

That's great!! "Can barely keep up" is a great place to be for short periods of time.
__________________
x-cart 4.0.13 and 4.1.7 and 4.1.10
Reply With Quote
  #10  
Old 12-06-2005, 09:07 AM
 
markwhoo markwhoo is offline
 

X-Adept
  
Join Date: Nov 2003
Posts: 799
 

Default

Quote:
Originally Posted by NuAlpha
Quote:
Originally Posted by markwhoo
Well, Sadly it does not work for 3.4 version that is.
Can you email me a zip of some of the latest default Xcart 3.4 code? I didn't see it in the file area of the Qualiteam Xcart support pages.

I think I'll just need the contents of the customer template directory and the following directories zipped up:
/include
/customer
/modules

If I can find time this weekend I will see if I can get it working for version 3.4 if doing so is feasible.

PM me if you can send it and I will provide you with an email to attach it to.

NuAlpha,

Did you get those files I sent you last week?

I had not heard so thought I would ask. Good to know business is going well for you too. We are working 7 days a week trying to keep up with the demand. tis the season to go crazy! I love it :0)
__________________
vs 4.1.12
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:25 PM.

   

 
X-Cart forums © 2001-2020