Esempio n. 1
0
 /**
  * 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));
 }