/**
  * Get price for the selected quantity and dates
  */
 public function getPriceAction()
 {
     if (!$this->getRequest()->getParam('product_id') || !$this->getRequest()->getParam('start_date')) {
         $jsonReturn = array('amount' => -1, 'onclick' => '', 'needsConfigure' => true, 'formatAmount' => -1);
         $this->getResponse()->setBody(Zend_Json::encode($jsonReturn));
         return;
     }
     $productId = $this->getRequest()->getParam('product_id');
     $product = Mage::getModel('catalog/product')->load($productId);
     $qty = urldecode($this->getRequest()->getParam('qty'));
     list($startDate, $endDate) = ITwebexperts_Payperrentals_Helper_Date::saveDatesForGlobalUse($this->getRequest()->getPost());
     if ($this->getRequest()->getParam('is_fixed_date')) {
         //get all fixed dates id with names and hours in a html with rectangle classes.. and disable rent button... have price as an attribute
         //add onclick event and a hidden field which updates...also enable button and start end date to get the real price
         $startDate = date('Y-m-d', strtotime($startDate));
         $endDate = date('Y-m-d', strtotime($endDate));
         $fixedDatesArray = ITwebexperts_Payperrentals_Helper_Data::getFixedRentalDates($product);
         $fixedDatesDropdown = '';
         if (count($fixedDatesArray)) {
             $fixedDatesDropdown .= '<ul class="fixed_array">';
         }
         $hasAvailability = false;
         foreach ($fixedDatesArray as $fixedDate) {
             if (date('Y-m-d', strtotime($fixedDate['start_date'])) == date('Y-m-d', strtotime($startDate))) {
                 if (Mage::helper('payperrentals/inventory')->isAvailable($productId, $fixedDate['start_date'], $fixedDate['end_date'], $qty)) {
                     //if (date('Y-m-d', strtotime($fixedDate['start_date'])) == date('Y-m-d', strtotime($fixedDate['end_date']))) {
                     //   $fixedDatesDropdown .= '<li idname="' . $fixedDate['id'] . '">' . date('H:i', strtotime($fixedDate['start_date'])) /*. '   ' . $fixedDate['name']*/ . '</li>';
                     //} else {
                     $fixedDatesDropdown .= '<li idname="' . $fixedDate['id'] . '">' . Mage::helper('payperrentals')->__('Start: ') . ITwebexperts_Payperrentals_Helper_Date::formatDbDate($fixedDate['start_date'], false, false) . ' &nbsp;&nbsp;&nbsp;  ' . Mage::helper('payperrentals')->__('End: ') . ITwebexperts_Payperrentals_Helper_Date::formatDbDate($fixedDate['end_date'], false, false) . '</li>';
                     //}
                     $hasAvailability = true;
                 }
             }
         }
         if (count($fixedDatesArray)) {
             $fixedDatesDropdown .= '</ul>';
         }
         if (!$hasAvailability) {
             $fixedDatesDropdown = Mage::helper('payperrentals')->__('Sorry, there is no availability left for this option');
         }
         $jsonReturn = array('amount' => 0, 'onclick' => '', 'fixedDates' => $fixedDatesDropdown, 'needsConfigure' => false, 'formatAmount' => -1);
         $this->getResponse()->setBody(Zend_Json::encode($jsonReturn));
         return;
     }
     $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;
     $onClick = '';
     $priceAmount = ITwebexperts_Payperrentals_Helper_Price::getPriceForAnyProductType($product, $attributes, $bundleOptions, $bundleOptionsQty1, $bundleOptionsQty, $startDate, $endDate, $qty, $onClick);
     if (Mage::helper('payperrentals/config')->useListButtons() || ITwebexperts_Payperrentals_Helper_Data::isUsingGlobalDates($product)) {
         ITwebexperts_Payperrentals_Helper_Date::saveDatesForGlobalUse($this->getRequest()->getPost());
     }
     $jsonReturn = array('amount' => $priceAmount, 'onclick' => $onClick, 'needsConfigure' => false, 'formatAmount' => $priceAmount != -1 ? Mage::helper('core')->currency($priceAmount) : -1);
     $this->getResponse()->setBody(Zend_Json::encode($jsonReturn));
 }
Beispiel #2
0
 /**
  * Adds rental start and end dates to custom options
  *
  * @param Varien_Object $buyRequest
  * @param null $product
  * @param null $processMode
  * @param string $productType
  * @return string
  * todo refactor /investigate more to additional_options(how the translations of options would work, might need a lot of effort)
  * this function should check if we are in global dates mode, should get the existing param etc, no need to modify query string on listing.
  * This will allow so adding a product from a different block from listing to work too
  */
 public function prepareForCartAdvanced(Varien_Object $buyRequest, $product = null, $processMode = null, $productType = 'simple')
 {
     if (ITwebexperts_Payperrentals_Helper_Data::isBuyout($buyRequest)) {
         $product->addCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::BUYOUT_PRICE_OPTION, true, $product);
         return 'call_parent';
     }
     if (!ITwebexperts_Payperrentals_Helper_Sso::isAllowedRenting()) {
         return Mage::helper('payperrentals')->__('You are not allowed renting. Please login on CNH');
     }
     if ($productType != 'simple' && !ITwebexperts_Payperrentals_Helper_Data::isReservationAndRental($product)) {
         return 'call_parent';
     }
     if ($buyRequest->getIsReservation() == ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_RENTAL) {
         return Mage::helper('payperrentals/membership')->addProductToQueue($product, $buyRequest, $productType == 'grouped' ? true : false);
     }
     $msg = $this->_completeBuyRequestObject($buyRequest, $product, $productType);
     if ($msg) {
         return $msg;
     }
     $resultObject = new Varien_Object();
     Mage::dispatchEvent('prepare_advanced_before', array('buy_request' => $buyRequest, 'product_type' => $productType, 'product' => $product, 'result' => $resultObject));
     if ($resultObject->getResult() != '') {
         return $resultObject->getResult();
     }
     $this->_addCustomOptions($product, $buyRequest);
     ITwebexperts_Payperrentals_Helper_Date::saveDatesForGlobalUse((array) $buyRequest);
     return 'call_parent';
 }