public function getEvents($startDate, $endDate, $productIds, $currentView) { $events = array(); $bookedByIds = ITwebexperts_Payperrentals_Helper_Inventory::getBookedQtyForProducts($productIds, $startDate, $endDate, true); $configHelper = Mage::helper('payperrentals/config'); foreach ($productIds as $productId) { if (isset($bookedByIds[$productId])) { $oldDate = array(); foreach ($bookedByIds[$productId] as $dateFormatted => $vObject) { if (strtotime($dateFormatted) < strtotime($startDate) || strtotime($dateFormatted) > strtotime($endDate)) { continue; } if (($currentView == 'resourceMonth' || $currentView == 'resourceWeek') && in_array(date('Y-m-d', strtotime($dateFormatted)), $oldDate)) { continue; } $maxQty = ITwebexperts_Payperrentals_Helper_Inventory::getQuantity($productId); if (date('H:i', strtotime($dateFormatted)) != '00:00' && $currentView == 'resourceDay') { $time_increment = $configHelper->getTimeIncrement() * 60; $start = date('Y-m-d', strtotime($dateFormatted)) . ' ' . date('H:i', strtotime($dateFormatted)) . ':00'; $end = date('Y-m-d', strtotime($dateFormatted)) . ' ' . date('H:i', strtotime('+' . $time_increment . ' SECOND', strtotime($dateFormatted))) . ':00'; $isHour = true; } else { $start = date('Y-m-d', strtotime($dateFormatted)) . ' 00:00:00'; $end = date('Y-m-d', strtotime($dateFormatted)) . ' 23:59:59'; $oldDate[] = date('Y-m-d', strtotime($dateFormatted)); $isHour = false; } $evb = array('title' => $vObject->getQty() . '/' . ($maxQty - $vObject->getQty()), 'url' => urlencode($dateFormatted . '||' . implode(';', $vObject->getOrders()) . '||' . $productId), 'start' => $start, 'end' => $end, 'qty' => $vObject->getQty(), 'maxqty' => $maxQty - $vObject->getQty(), 'df' => date('Y-m-d', strtotime($dateFormatted)), 'is_hour' => $isHour, 'resource' => $productId); if ($maxQty - $vObject->getQty() < 0) { $evb['backgroundColor'] = '#cc0000'; $evb['className'] = 'overbookColor'; } $events[] = $evb; } } } return $events; }
/** * Returns the array of booked days, for the quantity and selected dates * * @return array */ public function updateBookedForProductAction() { if (!$this->getRequest()->getParam('product_id')) { $bookedHtml = array('bookedDates' => '', 'fixedRentalDates' => '', 'isDisabled' => true, 'isShoppingCartDates' => ITwebexperts_Payperrentals_Helper_Data::isUsingGlobalDatesShoppingCart() ? true : false, 'partiallyBooked' => ''); $this->getResponse()->setBody(Zend_Json::encode($bookedHtml)); return; } $product = ITwebexperts_Payperrentals_Helper_Data::initProduct($this->getRequest()->getParam('product_id')); //todo might not be necessary $qty = $this->getRequest()->getParam('qty') ? $this->getRequest()->getParam('qty') : 1; $normalPrice = ''; $needsConfigure = false; $isConfigurable = false; $isDisabled = false; $attributes = $this->getRequest()->getParam('super_attribute') ? $this->getRequest()->getParam('super_attribute') : null; $bundleOptions = $this->getRequest()->getParam('bundle_option') ? $this->getRequest()->getParam('bundle_option') : null; $bundleOptionsQty1 = $this->getRequest()->getParam('bundle_option_qty1') ? $this->getRequest()->getParam('bundle_option_qty1') : null; $bundleOptionsQty = $this->getRequest()->getParam('bundle_option_qty') ? $this->getRequest()->getParam('bundle_option_qty') : null; $qtyArr = ITwebexperts_Payperrentals_Helper_Inventory::getQuantityArrayForProduct($product, 1, $attributes, $bundleOptions, $bundleOptionsQty1, $bundleOptionsQty, true); $maxQtyArr = array(); $bookedDates = array(); $partiallyBookedDates = array(); $turnoverTimeBefore = 0; $turnoverTimeAfter = 0; $maxQtyForParentProduct = 10000; /** * We get the maximum qty available at this moment for every associated product */ foreach ($qtyArr as $iProduct => $iQty) { if (ITwebexperts_Payperrentals_Helper_Inventory::isAllowedOverbook($iProduct)) { $maxQtyForChildProduct = 100000; } else { $maxQtyForChildProduct = ITwebexperts_Payperrentals_Helper_Inventory::getQuantity($iProduct); } $qtyForParentProduct = intval($maxQtyForChildProduct / $iQty); $maxQtyArr[$iProduct] = $maxQtyForChildProduct; if ($maxQtyForParentProduct > $qtyForParentProduct) { $maxQtyForParentProduct = $qtyForParentProduct; } if ($maxQtyForChildProduct < $iQty * $qty) { $isDisabled = true; break; } } if (!$isDisabled) { $resProductArrIds = ITwebexperts_Payperrentals_Helper_Inventory::getReservationProductsArrayIds($product->getId(), $attributes, $bundleOptions); $turnoverArr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($product->getId(), null, null, null, 'days'); $turnoverTimeBefore = $turnoverArr['before']; $turnoverTimeAfter = $turnoverArr['after']; foreach ($resProductArrIds as $resProductId) { $booked = ITwebexperts_Payperrentals_Helper_Inventory::getBookedQtyForProducts($resProductId); //Normally if shipping method with turnovers is used global turnovers should be null if ($turnoverTimeAfter == 0 && $turnoverTimeBefore == 0) { $turnoverArr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($resProductId, null, null, null, 'days'); $turnoverTimeBefore = $turnoverArr['before']; $turnoverTimeAfter = $turnoverArr['after']; } /** * We go product by product(in the associated products) and date by date and subtract from * this moment qty the booked qty for that date This is how calendar is created. */ if (isset($booked[$resProductId])) { foreach ($booked[$resProductId] as $dateFormatted => $vObject) { $qtyAvailForProduct = intval(($maxQtyArr[$resProductId] - $vObject->getQty()) / $qtyArr[$resProductId]); $isPartial = false; if (date('H:i', strtotime($dateFormatted)) != '00:00') { if (!isset($partiallyBookedDates[$dateFormatted . ':00'])) { $partiallyBookedDates[$dateFormatted . ':00'] = $qtyAvailForProduct; } else { $partiallyBookedDates[$dateFormatted . ':00'] = min($qtyAvailForProduct, $partiallyBookedDates[$dateFormatted . ':00']); } $isPartial = true; } if (!$isPartial) { if (!isset($bookedDates[$dateFormatted])) { $bookedDates[$dateFormatted] = $qtyAvailForProduct; } else { $bookedDates[$dateFormatted] = min($bookedDates[$dateFormatted], $qtyAvailForProduct); } } } } } $bookedDates = ITwebexperts_Payperrentals_Helper_Data::toFormattedBookedArray($bookedDates, false); } $typeId = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($product->getId(), 'type_id'); if ($typeId == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_CONFIGURABLE) { reset($qtyArr); $normalPrice = ITwebexperts_Payperrentals_Helper_Price::getPriceListHtml(key($qtyArr)); $isConfigurable = true; $blockedDates = ITwebexperts_Payperrentals_Helper_Data::getDisabledDates(key($qtyArr)); $fixedRentalDates = ITwebexperts_Payperrentals_Helper_Data::getFixedRentalDates(key($qtyArr)); } else { $blockedDates = ITwebexperts_Payperrentals_Helper_Data::getDisabledDates($product->getId()); $fixedRentalDates = ITwebexperts_Payperrentals_Helper_Data::getFixedRentalDates($product->getId()); } $blockedDates = ITwebexperts_Payperrentals_Helper_Data::toFormattedDateArray($blockedDates, false); $fixedRentalDates = ITwebexperts_Payperrentals_Helper_Data::toFormattedArraysOfDatesArray($fixedRentalDates, false); $bookedHtml = array('bookedDates' => $bookedDates, 'fixedRentalDates' => $fixedRentalDates, 'isDisabled' => $isDisabled, 'blockedDates' => implode(',', $blockedDates), 'isShoppingCartDates' => ITwebexperts_Payperrentals_Helper_Data::isUsingGlobalDatesShoppingCart() ? true : false, 'isConfigurable' => $isConfigurable, 'needsConfigure' => $needsConfigure, 'normalPrice' => $normalPrice, 'partiallyBooked' => $partiallyBookedDates); $bookedHtml['turnoverTimeBefore'] = $turnoverTimeBefore; $bookedHtml['turnoverTimeAfter'] = $turnoverTimeAfter; $bookedHtml['maxQty'] = $maxQtyForParentProduct; $disabledDaysStart = ITwebexperts_Payperrentals_Helper_Data::getDisabledDaysStart(); $disabledDaysEnd = ITwebexperts_Payperrentals_Helper_Data::getDisabledDaysEnd(); if (count($disabledDaysStart) > 0) { $bookedHtml['disabledForStartRange'] = $disabledDaysStart; } if (count($disabledDaysEnd) > 0) { $bookedHtml['disabledForEndRange'] = $disabledDaysEnd; } if (Mage::helper('payperrentals/config')->getFutureReservationLimit($product) > 0) { $bookedHtml['futureDate'] = date('Y-m-d', time() + Mage::helper('payperrentals/config')->getFutureReservationLimit($product) * 3600 * 24); } Mage::dispatchEvent('ppr_get_booked_html_for_products', array('request_params' => $this->getRequest()->getParams(), 'booked_html' => &$bookedHtml, 'product' => $product)); $this->getResponse()->setBody(Zend_Json::encode($bookedHtml)); }