public function updateBookedHtmlForShipping(Varien_Event_Observer &$observer) { $requestParams = $observer->getEvent()->getRequestParams(); $bookedHtml = $observer->getEvent()->getBookedHtml(); $product = $observer->getEvent()->getProduct(); if (array_key_exists('shipping_method', $requestParams)) { if ($requestParams['shipping_method'] != '') { $shippingMethodForLoad = $requestParams['shipping_method']; } elseif (array_key_exists('shipping_method_select_box', $requestParams) && $requestParams['shipping_method_select_box'] != 'null') { $shippingMethodForLoad = $requestParams['shipping_method_select_box']; } elseif (array_key_exists('shipping_method_select_box_additional', $requestParams)) { $shippingMethodForLoad = $requestParams['shipping_method_select_box_additional']; } else { $shippingMethodForLoad = ''; } $shippingMethod = Mage::getModel('rshipping/rshipping')->load($shippingMethodForLoad, 'shipping_method'); $bookedHtml['shippingMinRentalPeriod'] = ITwebexperts_Payperrentals_Helper_Data::getPeriodInSeconds($shippingMethod->getMinRentalPeriod(), $shippingMethod->getMinRentalType()); $bookedHtml['shippingMinRentalMessage'] = Mage::helper('payperrentals')->__('Minimum rental period is "%s". Please make sure you select at least that number', ITwebexperts_Payperrentals_Helper_Html::getTextForType($shippingMethod->getMinRentalPeriod(), $shippingMethod->getMinRentalType())); $upsTransitTime = 0; if (stripos($shippingMethod->getShippingMethod(), 'ups') !== false && Mage::getStoreConfig('payperrentals/rshipping_ups/enabled') && $shippingMethod->getUseLiveUpsApi()) { $zip = $requestParams['zip_code']; $upsTransitTime = Mage::helper('rshipping')->getTimeInTransit($zip, $product, $shippingMethod->getShippingMethod()); } $paddingDays = array(); /** * Day cutoff time. If current time > cutoff time => disable today and start from tomorrow * */ $currentTime = (int) Mage::getModel('core/date')->timestamp(time()); if ($shippingMethod->getShippingCutoffTime() != '') { $shipCutoffTime = strtotime(date('Y-m-d', $currentTime) . ' ' . $shippingMethod->getShippingCutoffTime()); if ($currentTime > $shipCutoffTime) { //$bookedHtml['disableToday'] = true; $dateFormatted = date('Y-m-d', $currentTime); $paddingDays[] = $dateFormatted; } } if ($shippingMethod->getStartDisabledDays()) { $bookedHtml['disabledForStartRange'] = ITwebexperts_Payperrentals_Helper_Data::getWeekdayForJs(explode(',', $shippingMethod->getStartDisabledDays())); } else { $bookedHtml['disabledForStartRange'] = ''; } if ($shippingMethod->getEndDisabledDays()) { $bookedHtml['disabledForEndRange'] = ITwebexperts_Payperrentals_Helper_Data::getWeekdayForJs(explode(',', $shippingMethod->getEndDisabledDays())); } else { $bookedHtml['disabledForEndRange'] = ''; } if (stripos($shippingMethod->getShippingMethod(), 'ups') !== false && $shippingMethod->getIgnoreTurnoverDay()) { $bookedHtml['ignoreTurnoverDay'] = ITwebexperts_Payperrentals_Helper_Data::getWeekdayForJs(explode(',', $shippingMethod->getIgnoreTurnoverDay())); } $turnoverBeforePeriod = (int) $shippingMethod->getTurnoverBeforePeriod() + $upsTransitTime; $turnoverAfterPeriod = (int) $shippingMethod->getTurnoverAfterPeriod(); $bookedHtml['turnoverTimeBefore'] = $turnoverBeforePeriod; $bookedHtml['turnoverTimeAfter'] = $turnoverAfterPeriod; if ($turnoverBeforePeriod > 0) { $startTimePadding = Mage::getSingleton('core/date')->timestamp(time()); while ($turnoverBeforePeriod > 0) { $dateFormatted = date('Y-m-d', $startTimePadding) . ' 00:00'; if (!in_array($dateFormatted, $paddingDays)) { $paddingDays[] = $dateFormatted; } $startTimePadding = strtotime('+1 day', $startTimePadding); $turnoverBeforePeriod--; } } if (count($paddingDays) > 0) { $bookedHtml['disabledDatesPadding'] = ITwebexperts_Payperrentals_Helper_Data::toFormattedDateArray($paddingDays, false); } $observer->getEvent()->setBookedHtml($bookedHtml); } }