Example #1
0
 public static function isDisabledDates($productId, $startTimestamp, $endTimestamp)
 {
     $blockedDates = ITwebexperts_Payperrentals_Helper_Data::getDisabledDates($productId);
     $disabledDays = ITwebexperts_Payperrentals_Helper_Data::getDisabledDays($productId, true);
     $disabledDaysStart = ITwebexperts_Payperrentals_Helper_Data::getDisabledDaysStart(true);
     $disabledDaysEnd = ITwebexperts_Payperrentals_Helper_Data::getDisabledDaysEnd(true);
     $currentTimeStamp = Mage::getSingleton('core/date')->timestamp(time());
     $paddingDays = ITwebexperts_Payperrentals_Helper_Data::getProductPaddingDays($productId, $currentTimeStamp, 1);
     $dayOfWeekStart = date('w', $startTimestamp);
     $dayOfWeekEnd = date('w', $endTimestamp);
     $formattedDateStart = date('Y-m-d H:i', $startTimestamp);
     $formattedDateEnd = date('Y-m-d H:i', $endTimestamp);
     return in_array($dayOfWeekStart, $disabledDaysStart) || in_array($dayOfWeekEnd, $disabledDaysEnd) || in_array($dayOfWeekStart, $disabledDays) || in_array($dayOfWeekEnd, $disabledDays) || in_array($formattedDateStart, $blockedDates) || in_array($formattedDateEnd, $blockedDates) || in_array($formattedDateStart, $paddingDays) || in_array($formattedDateEnd, $paddingDays);
 }
Example #2
0
 /**
  * Function which completes the booked array with the disabled and excluded days, so they
  * can't be selected in the calendar. The report will ignore them
  *
  * @param array    $productIds
  * @param array    $booked
  * @param int      $currentTimestamp
  * @param datetime $stDate
  * @param datetime $enDate
  *
  * @return array
  */
 public static function isExcludedDay($productIds, $stDate, $enDate)
 {
     if (!is_array($productIds)) {
         $productIds = array($productIds);
     }
     $currentTimestamp = (int) Mage::getSingleton('core/date')->timestamp(time());
     foreach ($productIds as $id) {
         $disabledDays = ITwebexperts_Payperrentals_Helper_Data::getDisabledDays($id);
         $disabledDaysStart = ITwebexperts_Payperrentals_Helper_Data::getDisabledDaysStart();
         $disabledDaysEnd = ITwebexperts_Payperrentals_Helper_Data::getDisabledDaysEnd();
         //$paddingDays = ITwebexperts_Payperrentals_Helper_Data::getProductPaddingDays($id, $currentTimestamp);
         $paddingDays = ITwebexperts_Payperrentals_Helper_Data::getFirstAvailableDateRange($id, null, false, true);
         if (!$paddingDays) {
             return true;
         }
         $blockedDates = ITwebexperts_Payperrentals_Helper_Data::getDisabledDates($id);
         foreach ($blockedDates as $dateFormatted) {
             if (date('Y-m-d', strtotime($dateFormatted)) == date('Y-m-d', strtotime($stDate)) || date('Y-m-d', strtotime($dateFormatted)) == date('Y-m-d', strtotime($enDate))) {
                 return true;
             }
         }
         foreach ($paddingDays as $dateFormatted) {
             if (strtotime($dateFormatted) >= strtotime($stDate) && strtotime($dateFormatted) <= strtotime($enDate)) {
                 return true;
             }
         }
         if (count($disabledDays) > 0) {
             $startTimePadding = strtotime(date('Y-m-d', strtotime($stDate)));
             $endTimePadding = strtotime(date('Y-m-d', strtotime($enDate)));
             $dayofWeek = date('D', $startTimePadding);
             if (in_array($dayofWeek, $disabledDays)) {
                 return true;
             }
             $dayofWeek = date('D', $startTimePadding);
             if (in_array($dayofWeek, $disabledDaysStart)) {
                 return true;
             }
             $dayofWeek = date('D', $endTimePadding);
             if (in_array($dayofWeek, $disabledDays)) {
                 return true;
             }
             $dayofWeek = date('D', $endTimePadding);
             if (in_array($dayofWeek, $disabledDaysEnd)) {
                 return true;
             }
         }
     }
     return false;
 }
Example #3
0
 /**
  * Function to remove disabled days and dates from the start-end interval
  * @param $rentalPeriodInSeconds
  * @param $startingDate
  * @param $endingDate
  * @param $start_date
  * @param $end_date
  * @param $product
  */
 private static function reCalculatePeriodFromSettings(&$rentalPeriodInSeconds, $startingDate, $endingDate, $product)
 {
     // Add extra time from admin settings field
     if (Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_ADDTIME_NUMBER) != '' && Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_ADDTIME_NUMBER) > 0 && !(date('Y-m-d', strtotime($startingDate)) == date('Y-m-d', strtotime($endingDate)) && date('H:i:s', strtotime($endingDate)) == '23:59:59')) {
         $secondsToAdd = ITwebexperts_Payperrentals_Helper_Data::getPeriodInSeconds(Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_ADDTIME_NUMBER), Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_ADDTIME_TYPE));
         $rentalPeriodInSeconds += $secondsToAdd;
     }
     $disabledDays = ITwebexperts_Payperrentals_Helper_Data::getDisabledDays($product->getId(), false, true);
     $blockedDates = ITwebexperts_Payperrentals_Helper_Data::getDisabledDates($product->getId(), true);
     foreach ($blockedDates as $dateFormattedString) {
         if (strtotime($dateFormattedString) >= strtotime($startingDate) && strtotime($dateFormattedString) <= strtotime($endingDate)) {
             $secondsToRemove = 60 * 60 * 24;
             $rentalPeriodInSeconds -= $secondsToRemove;
         }
     }
     if (count($disabledDays) > 0) {
         $startTimePadding = strtotime(date('Y-m-d', strtotime($startingDate)));
         $endTimePadding = strtotime(date('Y-m-d', strtotime($endingDate)));
         while ($startTimePadding <= $endTimePadding) {
             $dayofWeek = date('D', $startTimePadding);
             if (in_array($dayofWeek, $disabledDays)) {
                 $secondsToRemove = 60 * 60 * 24;
                 $rentalPeriodInSeconds -= $secondsToRemove;
             }
             $startTimePadding += 60 * 60 * 24;
         }
     }
 }
Example #4
0
 /**
  * Check rental for disabled days
  *
  * @param string $_testId
  * @param int $product_id
  * @test
  * @loadFixture
  * @loadExpectation
  * @dataProvider dataProvider
  */
 public function checkDisabledDays($_testId, $product_id)
 {
     $product = Mage::getModel('catalog/product')->load($product_id);
     $_expected = $this->expected('testId' . $_testId);
     $disabledDays = ITwebexperts_Payperrentals_Helper_Data::getDisabledDays($product);
     $this->assertCount(count($_expected->getValues()), $disabledDays);
     foreach ($_expected->getValues() as $value) {
         $this->assertContains($value, $disabledDays);
     }
 }