public function indexAction() { $orderId = $this->getRequest()->getParam('order_id'); $newDate = ITwebexperts_Payperrentals_Helper_Date::toMysqlDate($this->getRequest()->getParam('new_date'), true); /** @var $sourceOrder Mage_Sales_Model_Order */ $sourceOrder = Mage::getModel('sales/order')->load($orderId); $cart = Mage::getModel('checkout/cart'); $cart->init(); $cart->truncate(); $orderItems = $sourceOrder->getAllItems(); $configHelper = Mage::helper('payperrentals/config'); foreach ($orderItems as $item) { $timeIncrement = $configHelper->getTimeIncrement() * 60; if ($item->getParentItem()) { continue; } $originalEndDate = $item->getBuyRequest()->getEndDate(); //check timeIncrement and check if product has times enabled if (ITwebexperts_Payperrentals_Helper_Data::useTimes($item->getProduct()->getId()) == 0) { $timeIncrement = 24 * 60 * 60; } $originalEndDatePlusTimeIncrement = strtotime($originalEndDate) + $timeIncrement; $originalEndDatePlusTimeIncrement = date('Y-m-d H:i:s', $originalEndDatePlusTimeIncrement); $productOptions = $item->getProductOptions(); $buyRequestArray = $productOptions['info_buyRequest']; $buyRequestArray['start_date'] = $originalEndDatePlusTimeIncrement; $buyRequestArray['end_date'] = $newDate; $buyRequestArray['is_extended'] = true; if (count($item->getChildrenItems()) > 0) { foreach ($item->getChildrenItems() as $child) { $turnoverArr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($child->getProductId(), $child); $buyRequestArray['excluded_qty'][] = array('product_id' => $child->getProductId(), 'start_date' => $turnoverArr['before'], 'end_date' => $turnoverArr['after'], 'qty' => $productOptions['info_buyRequest']['qty']); } } else { $turnoverArr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($item->getProductId(), $item); $buyRequestArray['excluded_qty'][] = array('product_id' => $item->getProductId(), 'start_date' => $turnoverArr['before'], 'end_date' => $turnoverArr['after'], 'qty' => $productOptions['info_buyRequest']['qty']); } $buyRequest = new Varien_Object($buyRequestArray); $product = Mage::getModel('catalog/product')->load($item->getProductId()); try { $cart->addProduct($product, $buyRequest); } catch (Exception $e) { Mage::getSingleton('core/session')->addError($e->getMessage()); } } $cart->save(); Mage::getSingleton('checkout/session')->setIsExtendedQuote(true); Mage::getSingleton('checkout/session')->setCartWasUpdated(true); $this->_redirect('checkout/cart'); }
public function indexAction() { $orderId = $this->getRequest()->getParam('order_id'); $newDate = ITwebexperts_Payperrentals_Helper_Date::toMysqlDate($this->getRequest()->getParam('new_date'), true); /** @var $sourceOrder Mage_Sales_Model_Order */ $sourceOrder = Mage::getModel('sales/order')->load($orderId); /** @var Mage_Adminhtml_Model_Session_Quote $orderSession */ $orderSession = Mage::getSingleton('adminhtml/session_quote'); $orderSession->clear(); $customer = Mage::getModel('customer/customer')->load($sourceOrder->getCustomerId()); $orderSession->setCustomer($customer); $orderSession->setCustomerId($sourceOrder->getCustomerId()); $orderSession->setStoreId($sourceOrder->getStoreId()); //$orderSession->setQuoteId($quote->getId()); /** @var $quote Mage_Sales_Model_Quote */ $quote = $orderSession->getQuote(); /** @var $converterOrder Mage_Sales_Model_Convert_Order */ $converterOrder = Mage::getModel('sales/convert_order'); $orderShippingAddress = $converterOrder->addressToQuoteAddress($sourceOrder->getShippingAddress()); $orderBillingAddress = $converterOrder->addressToQuoteAddress($sourceOrder->getBillingAddress()); // $orderPayment = $converterOrder->paymentToQuotePayment($sourceOrder->getPayment()); $quote->setShippingAddress($orderShippingAddress); $quote->setBillingAddress($orderBillingAddress); //$quote->setPayment($orderPayment); $orderItems = $sourceOrder->getAllItems(); $configHelper = Mage::helper('payperrentals/config'); foreach ($orderItems as $item) { $timeIncrement = $configHelper->getTimeIncrement() * 60; if ($item->getParentItem()) { continue; } $originalEndDate = $item->getBuyRequest()->getEndDate(); //check timeIncrement and check if product has times enabled if (ITwebexperts_Payperrentals_Helper_Data::useTimes($item->getProduct()->getId()) == 0) { $timeIncrement = 24 * 60 * 60; } $originalEndDatePlusTimeIncrement = strtotime($originalEndDate) + $timeIncrement; $originalEndDatePlusTimeIncrement = date('Y-m-d H:i:s', $originalEndDatePlusTimeIncrement); $productOptions = $item->getProductOptions(); $buyRequestArray = $productOptions['info_buyRequest']; $buyRequestArray['start_date'] = $originalEndDatePlusTimeIncrement; $buyRequestArray['end_date'] = $newDate; $buyRequestArray['is_extended'] = true; if (count($item->getChildrenItems()) > 0) { foreach ($item->getChildrenItems() as $child) { $turnoverArr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($child->getProductId(), $child); $buyRequestArray['excluded_qty'][] = array('product_id' => $child->getProductId(), 'start_date' => $turnoverArr['before'], 'end_date' => $turnoverArr['after'], 'qty' => $productOptions['info_buyRequest']['qty']); } } else { $turnoverArr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($item->getProductId(), $item); $buyRequestArray['excluded_qty'][] = array('product_id' => $item->getProductId(), 'start_date' => $turnoverArr['before'], 'end_date' => $turnoverArr['after'], 'qty' => $productOptions['info_buyRequest']['qty']); } $buyRequest = new Varien_Object($buyRequestArray); $product = Mage::getModel('catalog/product')->load($item->getProductId()); $itemNew = $quote->addProduct($product, $buyRequest); $itemNew->calcRowTotal(); $quote->collectTotals(); } $quote->save(); $orderSession->setIsExtendedQuote(true); $this->_redirect('adminhtml/sales_order_create/index'); }
/** * override for changing the current stock qty based on the quote_item * (this is a bad design from Magento, checkQuoteItemQty should receive the quoteItem in the original code too) * * @param mixed $qty * @param mixed $summaryQty * @param int $origQty * @param Mage_Sales_Model_Quote_Item $quoteItem * * @return Varien_Object */ public function checkQuoteItemQty($qty, $summaryQty, $origQty = 0, $quoteItem = null, $product = null) { if ($quoteItem && ITwebexperts_Payperrentals_Helper_Data::isReservationOnly($product) && (!$quoteItem->getChildren() || Mage::app()->getStore()->isAdmin())) { $qtyOption = 1; if ($quoteItem->getParentProductQty()) { $qty = $quoteItem->getParentProductQty(); $qtyOption = $quoteItem->getParentProductQtyOption(); } $quoteItemId = $quoteItem->getId(); if ($quoteItem->getParentItem() && $quoteItem->getParentItem()->getProduct()) { if ($quoteItem->getParentItem()->getProduct()->getTypeId() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_BUNDLE) { $quoteItemId = $quoteItem->getParentItem()->getItemId(); } } $turnoverArr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($product, $quoteItem); list($startDate, $endDate) = array($turnoverArr['before'], $turnoverArr['after']); $result = new Varien_Object(); $result->setHasError(false); if (!is_numeric($qty)) { $qty = Mage::app()->getLocale()->getNumber($qty); } /** * Check quantity type */ $result->setItemIsQtyDecimal($this->getIsQtyDecimal()); if (!$this->getIsQtyDecimal()) { $result->setHasQtyOptionUpdate(true); $qty = intval($qty); /** * Adding stock data to quote item */ $result->setItemQty($qty); if (!is_numeric($qty)) { $qty = Mage::app()->getLocale()->getNumber($qty); } $origQty = intval($origQty); $result->setOrigQty($origQty); } if ($qty < ITwebexperts_Payperrentals_Helper_Inventory::getMinSaleQuantity($product)) { $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('The minimum quantity allowed for purchase is %s.', ITwebexperts_Payperrentals_Helper_Inventory::getMinSaleQuantity($product)))->setErrorCode('qty_min')->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))->setQuoteMessageIndex('qty'); return $result; } if ($qty > ITwebexperts_Payperrentals_Helper_Inventory::getMaxSaleQuantity($product)) { $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('The maximum quantity allowed for purchase is %s.', ITwebexperts_Payperrentals_Helper_Inventory::getMaxSaleQuantity($product)))->setErrorCode('qty_max')->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))->setQuoteMessageIndex('qty'); return $result; } $result->addData($this->checkQtyIncrements($qty)->getData()); if ($result->getHasError()) { return $result; } $option = $quoteItem->getOptionByCode('info_buyRequest'); $buyRequest = $option ? unserialize($option->getValue()) : null; if (Mage::app()->getStore()->isAdmin() && Mage::getSingleton('adminhtml/session_quote')->getOrderId()) { $editedOrderId = Mage::getSingleton('adminhtml/session_quote')->getOrderId(); $order = Mage::getModel('sales/order')->load($editedOrderId); $buyRequestArray = (array) $buyRequest; foreach ($order->getAllItems() as $oItem) { if ($oItem->getProduct()->getId() != $product->getId()) { continue; } if (is_object($oItem->getOrderItem())) { $item = $oItem->getOrderItem(); } else { $item = $oItem; } if ($item->getParentItem()) { continue; } //check for bundles if (count($item->getChildrenItems()) > 0) { foreach ($item->getChildrenItems() as $child) { $turnoverArr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($child->getProductId(), $child); $buyRequestArray['excluded_qty'][] = array('product_id' => $child->getProductId(), 'start_date' => $turnoverArr['before'], 'end_date' => $turnoverArr['after'], 'qty' => $item->getQtyOrdered()); } } else { $turnoverArr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($item->getProductId(), $item); $buyRequestArray['excluded_qty'][] = array('product_id' => $item->getProductId(), 'start_date' => $turnoverArr['before'], 'end_date' => $turnoverArr['after'], 'qty' => $item->getQtyOrdered()); } } $buyRequest = new Varien_Object($buyRequestArray); } if (isset($buyRequest['start_date']) && isset($buyRequest['end_date'])) { if (strtotime($buyRequest['start_date']) > strtotime($buyRequest['end_date'])) { $message = Mage::helper('payperrentals')->__('Start Date is bigger then End Date. Please change!'); $result->setHasError(true)->setMessage($message)->setQuoteMessage($message); return $result; } } $isAvailable = false; if (ITwebexperts_Payperrentals_Helper_Inventory::isAllowedOverbook($product->getId())) { $isAvailable = true; } if (ITwebexperts_Payperrentals_Helper_Data::isBuyout($buyRequest)) { if (!$isAvailable) { Mage::register('quote_item_id', $quoteItemId); $maxQty = ITwebexperts_Payperrentals_Helper_Inventory::getQuantity($product, null, null, $buyRequest); Mage::unregister('quote_item_id'); if ($maxQty >= $qty) { $isAvailable = true; } } if ($isAvailable) { return $result; } else { $message = Mage::helper('payperrentals')->__('There is not enough quantity for buy this product'); $result->setHasError(true)->setMessage($message)->setQuoteMessage($message); return $result; } } if (!Mage::app()->getStore()->isAdmin() && !Mage::getSingleton('checkout/session')->getIsExtendedQuote() && isset($buyRequest['start_date']) && isset($buyRequest['end_date']) && ITwebexperts_Payperrentals_Helper_Inventory::isExcludedDay($product->getId(), $buyRequest['start_date'], $buyRequest['end_date'])) { $message = Mage::helper('payperrentals')->__('There are blocked dates or excluded days on your selected dates!'); $result->setHasError(true)->setMessage($message)->setQuoteMessage($message); return $result; } else { if (!$isAvailable && isset($buyRequest['start_date']) && isset($buyRequest['end_date'])) { Mage::register('quote_item_id', $quoteItemId); $maxQty = ITwebexperts_Payperrentals_Helper_Inventory::getQuantity($product, $startDate, $endDate, $buyRequest); Mage::unregister('quote_item_id'); if ($maxQty >= $qty) { $isAvailable = true; } } } if (ITwebexperts_Payperrentals_Helper_Data::isUsingGlobalDatesShoppingCart($product) && !$buyRequest['start_date']) { $message = Mage::helper('payperrentals')->__('Please select Global Dates!'); $result->setHasError(true)->setMessage($message)->setQuoteMessage($message); return $result; } if (!Mage::app()->getStore()->isAdmin() && !ITwebexperts_Payperrentals_Helper_Data::isBuyout($buyRequest) && (isset($buyRequest['start_date']) && strtotime($buyRequest['start_date']) < strtotime(date('Y-m-d')) || isset($buyRequest['end_date']) && strtotime($buyRequest['end_date']) < strtotime(date('Y-m-d')))) { $message = Mage::helper('payperrentals')->__('The selected Dates are in the past. Please select new dates!'); $result->setHasError(true)->setMessage($message)->setQuoteMessage($message); return $result; } if (Mage::app()->getStore()->isAdmin() && ITwebexperts_Payperrentals_Helper_Inventory::isAllowedOverbook($product->getId()) && ITwebexperts_Payperrentals_Helper_Inventory::showAdminOverbookWarning()) { Mage::register('quote_item_id', $quoteItemId); $maxQty = ITwebexperts_Payperrentals_Helper_Inventory::getQuantity($product, $startDate, $endDate, $buyRequest, true); Mage::unregister('quote_item_id'); if ($maxQty < $qty) { $message = Mage::helper('cataloginventory')->__('Product is not available for the selected dates'); $result->setHasError(false)->setMessage($message)->setQuoteMessage($message)->setQuoteMessageIndex('qtyppr'); return $result; } } Mage::dispatchEvent('before_stock_check', array('buyrequest' => $buyRequest, 'isavailable' => &$isAvailable)); if (!$isAvailable) { if (isset($buyRequest['start_date']) && isset($buyRequest['end_date'])) { //Mage::register('no_quote', 1); Mage::register('quote_item_id', $quoteItemId); $maxQty = ITwebexperts_Payperrentals_Helper_Inventory::getQuantity($product, $startDate, $endDate, $buyRequest); Mage::unregister('quote_item_id'); $maxQty = intval($maxQty / $qtyOption); //Mage::unregister('no_quote', 1); if ($maxQty > 0) { $message = Mage::helper('payperrentals')->__('Max quantity available for these dates is: ' . $maxQty . ', your quantity has been adjusted.'); // Mage::getSingleton('checkout/session')->addError($message); $result->setHasQtyOptionUpdate(true); //$result->setOrigQty($maxQty); $result->setQty($maxQty); $result->setItemQty($maxQty); $result->setMessage($message)->setQuoteMessage($message); return $result; } $message = Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProductName()); } else { $message = Mage::helper('cataloginventory')->__('Please select Start and End Dates'); } $result->setHasError(true)->setMessage($message)->setQuoteMessage($message)->setQuoteMessageIndex('qtyppr'); return $result; } return $result; } $return = parent::checkQuoteItemQty($qty, $summaryQty, $origQty); return $return; }
/** * Get product padding dates by global or product attribute params * Adds to padding the turnover time before because they need * to be added together. * type = 0 return padding days with turnover toghether * type = 1 returns only padding days * type = 2 return only turnover * * @param int $productId * @param $startDateTimestamp * @param int $type * *@return array */ public static function getProductPaddingDays($productId, $startDateTimestamp, $type = 0) { $paddingDays = array(); if (Mage::app()->getStore()->isAdmin()) { return $paddingDays; } $storeClose = intval(Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_STORE_CLOSE_TIME)); $t1 = preg_replace('/^0+?|:00*/', '', date('H', $startDateTimestamp)); $daysPadding = self::getPaddingDays($productId); if ($t1 > $storeClose || Mage::helper('payperrentals/config')->isNextHourSelection()) { $daysPadding++; } if ($daysPadding > 0) { $startTimePadding = $startDateTimestamp; while ($daysPadding > 0) { $dateFormatted = date('Y-m-d', $startTimePadding) . ' 00:00'; $paddingDays[] = $dateFormatted; $startTimePadding = strtotime('+1 day', $startTimePadding); $daysPadding--; } } if ($type == 0 || $type == 2) { if ($type == 2) { unset($paddingDays); $paddingDays = array(); unset($startTimePadding); } $turnoverAr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($productId, null, null, null, 'days'); $turnoverTimeBefore = $turnoverAr['before']; if ($turnoverTimeBefore > 0) { if (!isset($startTimePadding)) { if ($t1 > $storeClose) { $turnoverTimeBefore++; } $startTimePadding = $startDateTimestamp; } while ($turnoverTimeBefore > 0) { $dateFormatted = date('Y-m-d', $startTimePadding) . ' 00:00'; if (!in_array($dateFormatted, $paddingDays)) { $paddingDays[] = $dateFormatted; } $startTimePadding = strtotime('+1 day', $startTimePadding); $turnoverTimeBefore--; } } return $paddingDays; } if ($type == 1) { return $paddingDays; } }
/** * 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)); }
/** * @param $item * @param $product * @param $source * @param $qty * @param $startDate * @param $endDate */ private function saveSimpleReservationProduct($item, $product, $source, $qty, $startDate, $endDate) { $turnoverAr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($product, $source, $startDate, $endDate); $BQuoteItem = Mage::getModel('payperrentals/reservationquotes')->setProductId($product->getId())->setStartDate($startDate)->setEndDate($endDate)->setStartTurnoverBefore($turnoverAr['before'])->setEndTurnoverAfter($turnoverAr['after'])->setQuoteItemId($item->getId())->setQty($qty)->setQuoteId($item->getQuote()->getId()); if ($product->getVendorId() && $product->getVendorId() != 0) { $BQuoteItem->setVendorId($product->getVendorId()); } Mage::dispatchEvent('ppr_set_stock', array('item' => $item, 'res_order' => $BQuoteItem)); $BQuoteItem->save(); }