2

So, I had some luck with embedding a backend attribute to each product (called ship_days) and have had success posting the variable through the following formula:

<?php   
        $days=array();
        $order_items = $order->getAllItems();
        foreach($order_items as $item) {
            $product = Mage::getModel('catalog/product')->load($item->getProductId());
            $day = number_format($product->getShipDays(),2,'.','');     
            $days[]=urlencode($day);
            $max=max($days);
        }

Which when echos provides the correct value depending on the products in cart (some SKUs have a ship_days variable of 3, others have 5) Iused the following output:

<?php echo date ('m/d/y', strtotime ( "+$max weekdays" ));  ?>

Which should have output 6/19/2015 when calculated on Friday the 12th (tested on a PHP Sandbox) but actually output 6/11/2015. I also tried putting a PHP function but it seemed to slow down the processing of Success.phtml to the point where the page wouldn't load... what's the best way to accomplish this?

The function I tried embedding into Success.phtml is a function I use successfully in other files, but should I call that from a block or an external PHP script? Function below:

function dateFromBusinessDays($days, $dateTime=null) {
  $dateTime = is_null($dateTime) ? time() : $dateTime;
  $_day = 0;
  $_direction = $days == 0 ? 0 : intval($days/abs($days));
  $_day_value = (60 * 60 * 24);

  while($_day !== $days) {
    $dateTime += $_direction * $_day_value;
    $_day_w = date("w", $dateTime);

    if ($_day_w > 0 && $_day_w < 6) {
      $_day += $_direction * 1; 
    }
  }

  return $dateTime;
}

Anyone have any idea how I could achieve this?

2

You need to drop the decimal places in the $day variable. The strtotime() function returns different results depending on whether or not whole numbers are used.

This gives the correct results:

<?php echo date ('m/d/y', strtotime ( "+5 weekdays" ));  ?>

This doesn't, which is what your code currently does assuming a shipping time of 5 days:

<?php echo date ('m/d/y', strtotime ( "+5.00 weekdays" ));  ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.