Esempio n. 1
0
 /**
  * Returns an array of dates that a product is booked. Can accept an array of product ids,
  * this enables this function to work with bundles.
  *
  * @param      $productIds
  * @param null $stDate
  * @param null $enDate
  * @param bool $isReport
  *
  * @return array|mixed|null
  */
 public static function getBookedQtyForProducts($productIds, $stDate = null, $enDate = null, $isReport = false, $excludedQtysForDates = null)
 {
     /*Check if we are in the quote*/
     if (!Mage::registry('no_quote')) {
         $isQuote = Mage::getSingleton("checkout/session")->getQuoteId();
         if (!$isQuote) {
             $isQuote = false;
         }
     }
     if (!is_array($productIds)) {
         $productIds = array($productIds);
     }
     foreach ($productIds as $iProduct) {
         if (!$isReport && ITwebexperts_Payperrentals_Helper_Inventory::isAllowedOverbook($iProduct)) {
             return array('booked' => array());
         }
     }
     $booked = array();
     foreach ($productIds as $iProduct) {
         $inventorySerialized = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($iProduct, 'inventory_serialized');
         if ($inventorySerialized == 'not_updated') {
             self::updateInventory($iProduct);
             $inventorySerialized = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($iProduct, 'inventory_serialized');
         }
         if ($inventorySerialized) {
             $objArr = ITwebexperts_Payperrentals_Helper_Data::arrayToObject(json_decode($inventorySerialized, true));
             $booked += array($iProduct => $objArr);
         }
     }
     if (!isset($isQuote) || !$isQuote) {
         $booked = self::getBookedWithExcludedQtys($excludedQtysForDates, $booked);
         return $booked;
     }
     if ($isQuote) {
         $reserveQuote = Mage::getModel('payperrentals/reservationquotes')->getCollection()->addQuoteIdFilter($isQuote)->addProductIdsFilter($productIds);
         if (Mage::registry('quote_item_id')) {
             $reserveQuote->addQuoteItemIdFilterNot(Mage::registry('quote_item_id'));
         }
         Mage::dispatchEvent('ppr_before_filter_order', array('collection' => $reserveQuote));
         if (Mage::helper('payperrentals/config')->isHotelMode(Mage::app()->getStore()->getId()) || date('Y-m-d', strtotime($stDate)) == date('Y-m-d', strtotime($enDate))) {
             $reserveQuote->addSelectFilter("start_turnover_before <= '" . ITwebexperts_Payperrentals_Helper_Date::toDbDate($enDate, false, -60) . "' AND DATE_SUB(end_turnover_after, INTERVAL 1 MINUTE) >= '" . ITwebexperts_Payperrentals_Helper_Date::toDbDate($stDate) . "'");
         } else {
             $reserveQuote->addSelectFilter("start_turnover_before <= '" . ITwebexperts_Payperrentals_Helper_Date::toDbDate($enDate) . "' AND end_turnover_after >= '" . ITwebexperts_Payperrentals_Helper_Date::toDbDate($stDate) . "'");
         }
         $booked = self::getBooked($reserveQuote, false, $booked);
         $booked = self::getBookedWithExcludedQtys($excludedQtysForDates, $booked);
     }
     return $booked;
 }