Jump to content



Latest News: (loading..)

sammedit

Member Since 15 Nov 2007
OFFLINE Last Active Oct 14 2012 09:34 AM
-----

Topics I've Started

Estimated Shipping Date Function

20 September 2012 - 08:47 AM

Hello forum,
     I am looking for a fix to an estimated shipping date function that originally came from a contribution at http://addons.oscommerce.com/info/8286.

The code is supposed to return a future shipping date based on a user set amount of business days from today's date.  It is supposed to skip over weekends and add extra processing time if the final estimated shipping date falls on the weekend which kicks it over to Monday.  Unfortunately this code does not work correctly and returns the wrong dates when dealing with longer estimated shipping dates and when dealing with weekends.  So I am hoping someone can help me get this fixed and come up with a code that actually works.  I think that if there is a way to make the code pretend the weekends don't exist at all, that would be the best way to fix it.  Currently the code adds processing days when it goes over or lands on Saturday or Sunday.  The code that needs changed in this function is this:

$adddays = 0;
for ($i = 0; $i<$processdays; $i++) {
  $dayofweek = $startdayofweek + $i;  
  if ($dayofweek == "6") { $adddays = $adddays+1; }
  elseif ($dayofweek=="7") { $adddays = $adddays +1; }
  elseif ($dayofweek == "8") { $dayofweek = "1"; }
  
}

and this:

$dayofweekfinal = date("N",$finaldate);
if ($dayofweekfinal=='6') { $processdays = $processdays+2;  }
else if ($dayofweekfinal=='7') { $processdays = $processdays+1;  }

I would really appreciate any help replacing this code with code that actually works.  I have posted the full function below.  Please note that is also takes into account holidays and time of day BUT that code is not giving me any trouble.  The only problems stem from the above code.  Thank you.

sammedit

function get_early_shipping_date_estimate($cutofftime = MODULE_ESTIMATED_EARLY_SHIP_TIMES, $processdays = MODULE_ESTIMATED_EARLY_SHIP_DAYS) {
global $cart;
// Get the current time
$now = strtotime("now");
 
// Get the current year
$year = date("Y",$now);

// Get the time of day
$timeofday = date("H",$now);

// Get the day of the week (Monday, Tuesday..etc)
$startdayofweek = date("N",$now);


// If the time of day is greater than the cut off time for shipments AND it is not a weekend then add a day.

//if ($startdayofweek < "6"  && $timeofday > $cutofftime ) { $processdays = $processdays + 1; }

//  Count number of days to process
//  If the count comes across a Saturday or Sunday, add an additional day
//  If the count gets to 8, start over at 1
$adddays = 0;
for ($i = 0; $i<$processdays; $i++) {
  $dayofweek = $startdayofweek + $i;  
  if ($dayofweek == "6") { $adddays = $adddays+1; }
  elseif ($dayofweek=="7") { $adddays = $adddays +1; }
  elseif ($dayofweek == "8") { $dayofweek = "1"; }
  
}

$processdays = $processdays + $adddays;

/*
*   Get a "final" date based on the extra processing days so far
*/

$finaldate = strtotime("+".$processdays." days");


/*
*  Check and see if any holidays were in the mix of the final dates and add extra days for those
*/

$holiday_query = tep_db_query("select date from ".TABLE_SHIPPING_HOLIDAYS." where YEAR(date)='".$year."' order by date");
  while ($holidays = tep_db_fetch_array($holiday_query)) {
   if ($now <= strtotime($holidays['date'].' 00:00:00') && strtotime($holidays['date'].' 23:59:59') <= $finaldate) {   $processdays = $processdays+1; $finaldate = strtotime("+".$processdays." days");}
  
  }
  /*
  *   If the new "final" date falls on a Saturday or Sunday add extra processing days to land on a Monday
  */

$dayofweekfinal = date("N",$finaldate);


if ($dayofweekfinal=='6') { $processdays = $processdays+2;  }
else if ($dayofweekfinal=='7') { $processdays = $processdays+1;  }
$finalfinaldate = strtotime("+".$processdays." days");

/*
*   Then check the final ship date incase it may have landed on a holiday closure. 
*/
$senddate = check_early_ship_date($finalfinaldate);
return $senddate;
}
function check_early_ship_date($senddate) {

/*
*   Function determines if the estimated ship date is a holiday and if so, adds an additional day until it no longer is a holiday closure day.
*/
$holiday_query = tep_db_query("select date from shipping_holiday_closures where YEAR(date)='".date('Y', $senddate)."' order by date");
while ($holidays = tep_db_fetch_array($holiday_query)) {
  if ($holidays['date'] == date('Y-m-d', $senddate)) { 
   if (date("N",$senddate) == '5') { $days = 3; }
   elseif (date("N",$senddate) == '6') { $days = 2; }
   else { $days = 1; }
  
   $senddate = $senddate + ($days * 24 * 60 * 60); }
 
}

return $senddate;
}

date('Y-m-d h:m:s') odd problem

17 September 2012 - 04:20 AM

Hi,
   Are there any obvisious issues that would make the code:

date('Y-m-d h:m:s')

display a time where minute hand doesn't move?  ie.

At 9:35:13 p.m., time would read 9:09:13 p.m.

At 9:44:25 p.m., time would read 9:09:25 p.m.

At 10:25:44 p.m. time would read 10:09:44 p.m.

At 11:55:12 p.m. time would ready 11:09:12 p.m.

How to limit a count to show only up to a certain number

14 September 2012 - 02:09 AM

Hello Forum,

Here is my code:

  <?php if($product_info['products_quantity'] > 0) { ?>
	 <select name="qty" style="width: 120px; height: 20px;">
  
	<?php
	for ($x=1 ; $x <= $product_info['products_quantity']; $x++) { ?>
	<option   value="<?php echo $x; ?>"><?php echo $x; ?></option>
	<?php }?>
	</select>
	  <?php } else echo "NO available Stock"; ?>

This code allows you to add multiple qtys of an item on the product_info.php page.  It gets the qty from the database.  The problem is that if I have 10,000 qty of a product, the drop down menu will have a count up to 10,000.  I would like to cap it at 10.  How do I limit that?  Thank you.

sammedit

Why doesn't this code repeat?

11 September 2012 - 05:06 AM

Hi,
    Why doesn't the code below repeat itself and how can I make it repeat itself?  The code:

$adddays = 0;
for ($i = 0; $i<$processdays; $i++) {
  $dayofweek = $startdayofweek + $i;  
  if ($dayofweek == "6") { $adddays = $adddays+2; }
  elseif ($dayofweek == "8") { $dayofweek = "1"; }
  
}

is used in a function that creates an estimated shipping date and the code above is used to "skip" the weekend if the estimated date passes Saturday.  It works but if I have an extra long shipping date like 14 days and it goes over multiple weekends, it only works correctly on the first weekend.  Does that make sense?  If you want the code in context, it is below.  Thank you.

sammedit

function get_late_shipping_date_estimate($cutofftime = MODULE_ESTIMATED_LATE_SHIP_TIMES, $processdays = MODULE_ESTIMATED_LATE_SHIP_DAYS) {
global $cart;
// Get the current time
$now = strtotime("now");
 
// Get the current year
$year = date("Y",$now);

// Get the time of day
$timeofday = date("H",$now);

// Get the day of the week (Monday, Tuesday..etc)
$startdayofweek = date("N",$now);


// If the time of day is greater than the cut off time for shipments AND it is not a weekend then add a day.

if ($startdayofweek < "6"  && $timeofday > $cutofftime ) { $processdays = $processdays + 1; }

//  Count number of days to process
//  If the count comes across a Saturday or Sunday, add an additional day
//  If the count gets to 8, start over at 1
$adddays = 0;
for ($i = 0; $i<$processdays; $i++) {
  $dayofweek = $startdayofweek + $i;  
  if ($dayofweek == "6") { $adddays = $adddays+2; }
  elseif ($dayofweek == "8") { $dayofweek = "1"; }
  
}

$processdays = $processdays + $adddays;

/*
*   Get a "final" date based on the extra processing days so far
*/

$finaldate = strtotime("+".$processdays." days");


/*
*  Check and see if any holidays were in the mix of the final dates and add extra days for those
*/

$holiday_query = tep_db_query("select date from ".TABLE_SHIPPING_HOLIDAYS." where YEAR(date)='".$year."' order by date");
  while ($holidays = tep_db_fetch_array($holiday_query)) {
   if ($now <= strtotime($holidays['date'].' 00:00:00') && strtotime($holidays['date'].' 23:59:59') <= $finaldate) {   $processdays = $processdays+1; $finaldate = strtotime("+".$processdays." days");}
  
  }
  /*
  *   If the new "final" date falls on a Saturday or Sunday add extra processing days to land on a Monday
  */

$dayofweekfinal = date("N",$finaldate);


if ($dayofweekfinal=='6') { $processdays = $processdays+2;  }
else if ($dayofweekfinal=='7') { $processdays = $processdays+1;  }
$finalfinaldate = strtotime("+".$processdays." days");

/*
*   Then check the final ship date incase it may have landed on a holiday closure. 
*/
$senddate = check_late_ship_date($finalfinaldate);
return $senddate;
}
function check_late_ship_date($senddate) {

/*
*   Function determines if the estimated ship date is a holiday and if so, adds an additional day until it no longer is a holiday closure day.
*/
$holiday_query = tep_db_query("select date from shipping_holiday_closures where YEAR(date)='".date('Y', $senddate)."' order by date");
while ($holidays = tep_db_fetch_array($holiday_query)) {
  if ($holidays['date'] == date('Y-m-d', $senddate)) { 
   if (date("N",$senddate) == '5') { $days = 3; }
   elseif (date("N",$senddate) == '6') { $days = 2; }
   else { $days = 1; }
  
   $senddate = $senddate + ($days * 24 * 60 * 60); }
 
}

return $senddate;
}

What controls the admin login no activity reset?

10 September 2012 - 11:02 PM

Is there anyway to change it?  It seems like I have to re-login every 10-15 minutes after no activity.  It really gets annoying.