private static function getPricesArray($pricesCollection, &$pricesArray, $startDate, $endDate, $qty, $customerGroup) { $hasSpecials = false; foreach ($pricesCollection as $priceItem) { // BEGIN customer group, quantity, and date from/to Check $continueCustomerGroup = true; $continueQuantityStart = true; $continueQuantityEnd = true; if ($priceItem->getCustomersGroup() == '-1' || $priceItem->getCustomersGroup() == $customerGroup) { $continueCustomerGroup = false; } if ($priceItem->getQtyStart() != '' && $priceItem->getQtyStart() > 0 && $qty >= $priceItem->getQtyStart() || $priceItem->getQtyStart() == '' || $priceItem->getQtyStart() == 0) { $continueQuantityStart = false; } if ($priceItem->getQtyEnd() != '' && $priceItem->getQtyEnd() > 0 && $qty <= $priceItem->getQtyEnd() || $priceItem->getQtyEnd() == '' || $priceItem->getQtyEnd() == 0) { $continueQuantityEnd = false; } if ($continueCustomerGroup || $continueQuantityStart || $continueQuantityEnd) { continue; } // END customer group, quantity, and date from/to Check. If they pass, set price /** * Build $pricesArray */ $pricePoint = $priceItem->getPrice(); $pricePointInSeconds = ITwebexperts_Payperrentals_Helper_Data::getPeriodInSeconds($priceItem->getNumberof(), $priceItem->getPtype()); $additionalPricePoint = $priceItem->getPriceadditional(); if ($additionalPricePoint == 0) { $additionalPricePoint = null; } /*Additional Number Of is always considered 1*/ $additionalPricePointInSeconds = ITwebexperts_Payperrentals_Helper_Data::getPeriodInSeconds(1, $priceItem->getPtypeadditional()); if ($priceItem->getReservationpricesdatesId() == null || $priceItem->getReservationpricesdatesId() == 0) { $isForSpecial = null; } else { $isForSpecial = "yes"; } if (is_null($isForSpecial)) { $pricesArray[] = array('mainPricePointInSeconds' => $pricePointInSeconds, 'mainPricePoint' => (double) $pricePoint, 'additionalPricePointInSeconds' => $additionalPricePointInSeconds, 'additionalPricePoint' => $additionalPricePoint, 'start' => strtotime($startDate), 'end' => strtotime($endDate), 'special' => false); } else { $pricesArrayTemp = array('mainPricePointInSeconds' => $pricePointInSeconds, 'mainPricePoint' => (double) $pricePoint, 'additionalPricePointInSeconds' => $additionalPricePointInSeconds, 'additionalPricePoint' => $additionalPricePoint, 'special' => true); $hasSpecials = true; self::getReservationpricesdates($priceItem->getReservationpricesdatesId(), $pricesArrayTemp, $startDate, $endDate, $pricesArray); } } return $hasSpecials; }
/** * @deprecated * This function was used to return the next available date when fixed date selection was used. * Is better so no start date is automatically selected * @param $product * @param $startDate * * @return array */ private function _getAvailDateAndSelDays($product, $startDate) { $selDays = false; $availDate = false; if ($this->getRequest()->getParam('selDays')) { $selDays = (int) $this->getRequest()->getParam('selDays') + 1; $availDateArr = ITwebexperts_Payperrentals_Helper_Data::getFirstAvailableDateRange($product, $startDate, ITwebexperts_Payperrentals_Helper_Data::getPeriodInSeconds($selDays, ITwebexperts_Payperrentals_Model_Product_Periodtype::DAYS)); $availDate = $availDateArr['start_date']; } return array($selDays, $availDate); }
/** * Check min and max rental period * * @param string $_testId * @param int $product_id * @test * @loadFixture * @loadExpectation * @dataProvider dataProvider */ public function checkMinMax($_testId, $product_id) { $product = Mage::getModel('catalog/product')->load($product_id); $_expected = $this->expected('testId' . $_testId); list($_minRentalNumber, $_minRentalType, $_maxRentalNumber, $_maxRentalType) = ITwebexperts_Payperrentals_Helper_Data::getMinMaxRental($product); $_minRentalPeriod = ITwebexperts_Payperrentals_Helper_Data::getPeriodInSeconds($_minRentalNumber, $_minRentalType); $_maxRentalPeriod = ITwebexperts_Payperrentals_Helper_Data::getPeriodInSeconds($_maxRentalNumber, $_maxRentalType); $this->assertEquals($_expected->getMin(), $_minRentalPeriod); $this->assertEquals($_expected->getMax(), $_maxRentalPeriod); }
/** * Returns maximum extension length in second * @param null $storeId * * @return int */ public function getMaximumExtensionLength($storeId = null) { if (Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_MAX_EXTENSION_NUMBER, $storeId) != '') { ITwebexperts_Payperrentals_Helper_Data::getPeriodInSeconds(Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_MAX_EXTENSION_NUMBER, $storeId), Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_MAX_EXTENSION_TYPE, $storeId)); } else { return 10000000000.0; } }
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); } }