Exemple #1
0
 public static function completeListingAndProductInfoWithExtraButtons($product)
 {
     if (Mage::getSingleton('core/session')->getData('startDateInitial') && !Mage::helper('payperrentals/config')->useListButtons()) {
         $htmlPrice = '';
         if (Mage::helper('payperrentals/config')->keepListingPriceAfterDatesSelection()) {
             $htmlPrice = ITwebexperts_Payperrentals_Helper_Price::getPriceListHtml($product, Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_PRICING_ON_LISTING));
         } else {
             $priceVal = ITwebexperts_Payperrentals_Helper_Price::calculatePrice($product, Mage::getSingleton('core/session')->getData('startDateInitial'), Mage::getSingleton('core/session')->getData('endDateInitial'), 1, ITwebexperts_Payperrentals_Helper_Data::getCustomerGroup());
             if (!ITwebexperts_Payperrentals_Helper_Data::isAddToQueue($product) && !ITwebexperts_Payperrentals_Helper_Data::isAddToQueueGrouped($product)) {
                 $htmlPrice = $product->getTypeId() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE ? Mage::helper('payperrentals')->__('Not available') : Mage::helper('payperrentals')->__('');
             }
             if ($priceVal > 0) {
                 $htmlPrice = '<div class="price-box"><span class="price">Price: ' . Mage::helper('core')->currency($priceVal) . '</span></div>';
             }
             $buyoutHtml = '';
             $isRentalBuyout = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($product->getId(), 'payperrentals_enable_buyout');
             if ($isRentalBuyout) {
                 $buyoutPrice = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($product->getId(), 'payperrentals_buyoutprice');
                 $buyoutHtml = Mage::helper('payperrentals')->__('Buyout: ') . Mage::helper('core')->currency($buyoutPrice, true, false);
             }
             $htmlPrice .= $buyoutHtml;
         }
     } else {
         $htmlPrice = ITwebexperts_Payperrentals_Helper_Price::getPriceListHtml($product, Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_PRICING_ON_LISTING));
         if ($product->getTypeId() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE) {
             //use list buttons
             if (Mage::getSingleton('core/session')->getData('startDateInitial') && !Mage::registry('current_product')) {
                 $selectedArray = Mage::helper('payperrentals/config')->getFixedSelection();
                 $notAvailable = false;
                 foreach ($selectedArray as $iDay) {
                     $startDate = Mage::getSingleton('core/session')->getData('startDateInitial');
                     $endDate = date('Y-m-d H:i:s', strtotime('+ ' . $iDay . ' DAY', strtotime($startDate)));
                     $priceVal = ITwebexperts_Payperrentals_Helper_Price::calculatePrice($product, $startDate, $endDate, 1, ITwebexperts_Payperrentals_Helper_Data::getCustomerGroup());
                     if ($priceVal > 0) {
                         $selectedDayLink = Mage::helper('checkout/cart')->getAddUrl($product, array('_query' => array('options' => array('selected_days' => $iDay), 'selected_days' => $iDay)));
                         $htmlPrice .= '<input type="hidden" class="ppr_attr_sel_days" href="' . $selectedDayLink . '" value="' . Mage::helper('payperrentals')->__('Rent %s days at %s', $iDay, strip_tags(Mage::helper('core')->currency($priceVal))) . '" />';
                     } else {
                         $notAvailable = true;
                         break;
                     }
                 }
                 if ($notAvailable) {
                     if (!ITwebexperts_Payperrentals_Helper_Data::isAddToQueue($product) && !ITwebexperts_Payperrentals_Helper_Data::isAddToQueueGrouped($product)) {
                         $htmlPrice = $product->getTypeId() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE ? Mage::helper('payperrentals')->__('Not available') : Mage::helper('payperrentals')->__('');
                     } else {
                         $htmlPrice = '';
                     }
                 }
             }
         }
     }
     $configHelper = Mage::helper('payperrentals/config');
     $inventoryHelper = Mage::helper('payperrentals/inventory');
     if ($configHelper->showAvailabilityOnProductListing()) {
         if ($product->getTypeId() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE) {
             $isAvailable = $inventoryHelper->isAvailable($product->getId(), Mage::getSingleton('core/session')->getData('startDateInitial'), Mage::getSingleton('core/session')->getData('endDateInitial'), 1);
             if ($isAvailable) {
                 $htmlPrice .= '';
                 //Mage::helper('payperrentals')->__('Available for selected dates');
             } else {
                 $htmlPrice .= Mage::helper('payperrentals')->__('Not available for selected dates');
             }
         }
     }
     if (ITwebexperts_Payperrentals_Helper_Data::isReservation($product) && ITwebexperts_Payperrentals_Helper_Data::isReservationType($product)) {
         if (Mage::getSingleton('core/session')->getData('startDateInitial') && Mage::getSingleton('core/session')->getData('endDateInitial')) {
             $getAddUrl = Mage::helper('checkout/cart')->getAddUrl($product, array('_query' => array('options' => array('start_date' => Mage::getSingleton('core/session')->getData('startDateInitial'), 'end_date' => Mage::getSingleton('core/session')->getData('endDateInitial')), 'start_date' => Mage::getSingleton('core/session')->getData('startDateInitial'), 'end_date' => Mage::getSingleton('core/session')->getData('endDateInitial'))));
             $htmlPrice .= '<input type="hidden" href="' . $getAddUrl . '" class="ppr_attr_butname_global" value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . Mage::helper('payperrentals')->__('Rent') . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" />';
         } else {
             if (ITwebexperts_Payperrentals_Helper_Data::isUsingGlobalDates()) {
                 $getAddUrl = Mage::helper('checkout/cart')->getAddUrl($product, array('_query' => array('options' => array('start_date' => '', 'end_date' => ''), 'start_date' => '', 'end_date' => '')));
                 $htmlPrice .= '<input type="hidden" href="' . $getAddUrl . '" class="ppr_attr_butname_global" value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . Mage::helper('payperrentals')->__('Rent') . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" />';
             } else {
                 $htmlPrice .= '<input type="hidden" class="ppr_attr_butname" value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . Mage::helper('payperrentals')->__('Rent') . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" />';
             }
         }
         if (Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_ALLOW_LISTING_QTY) && Mage::app()->getRequest()->getRouteName() != 'wishlist') {
             $htmlPrice .= '<input type="hidden" class="ppr_attr_qty" prid="' . $product->getId() . '"  value="' . Mage::helper('payperrentals')->__('Qty: ') . '" />';
         }
     }
     if (Mage::helper('payperrentals/config')->isBuyout($product)) {
         $buyoutLink = Mage::helper('checkout/cart')->getAddUrl($product, array('_query' => array('options' => array('buyout' => 'true'), 'buyout' => 'true')));
         $htmlPrice .= '<input type="hidden" class="ppr_attr_buyout" href="' . $buyoutLink . '" value="' . Mage::helper('payperrentals')->__('Buy Now') . '" />';
     }
     $rentalLink = Mage::helper('checkout/cart')->getAddUrl($product, array('_query' => array('options' => array('one_option' => 'no_value'), 'is_reservation' => ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_RENTAL)));
     if (ITwebexperts_Payperrentals_Helper_Data::isAddToQueueGrouped($product)) {
         $htmlPrice .= '<input type="hidden" class="ppr_attr_queue" href="' . $rentalLink . '" value="' . Mage::helper('payperrentals')->__('Add All To Queue') . '" />';
     } elseif (ITwebexperts_Payperrentals_Helper_Data::isAddToQueue($product)) {
         /** used to disable and gray out add to queue button if not enabled for membership */
         $isalloweditem = '';
         $disabled_queue_class = '';
         if (Mage::getSingleton('customer/session')->isLoggedIn()) {
             $isalloweditem = Mage::helper('payperrentals/membership')->hasMembership($product->getId());
             if ($isalloweditem == false) {
                 $disabled_queue_class = ' notallowed';
             }
         }
         $htmlPrice .= '<input type="hidden" class="ppr_attr_queue' . $disabled_queue_class . '" href="' . $rentalLink . '" value="' . Mage::helper('payperrentals')->__('Add To Queue') . '" />';
     }
     return $htmlPrice;
 }
Exemple #2
0
 /**
  * Update start & end dates from global dates for all items in
  * the shopping cart
  *
  * @param $fromDate
  * @param $toDate
  */
 public static function updateCurrentGlobalDates($fromDate, $toDate)
 {
     /** @var $quote Mage_Sales_Model_Quote */
     $oldQuote = Mage::getModel('checkout/cart')->getQuote();
     $quote = clone $oldQuote;
     if ($quote) {
         //$cart = Mage::getModel('checkout/cart')->getQuote();
         $cartUpdated = false;
         $startDate = date('Y-m-d H:i:s', strtotime($fromDate));
         $endDate = date('Y-m-d H:i:s', strtotime($toDate));
         foreach ($quote->getAllVisibleItems() as $quoteItem) {
             // TODO: check configurable, bundle, and grouped product types
             /** @var $quoteItem Mage_Sales_Model_Quote_Item */
             $product = $quoteItem->getProduct();
             if (ITwebexperts_Payperrentals_Helper_Data::isUsingGlobalDates($product)) {
                 $oldBuyRequest = $quoteItem->getBuyRequest();
                 $buyRequest = clone $oldBuyRequest;
                 $buyRequest->setData(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION, $startDate);
                 $buyRequest->setData(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::END_DATE_OPTION, $endDate);
                 $buyRequest->setIsFiltered(true);
                 $isException = false;
                 try {
                     $quote->removeItem($quoteItem->getId());
                 } catch (Exception $e) {
                     $isException = true;
                     $quote->addProduct($product, $oldBuyRequest);
                 }
                 if (!$isException) {
                     try {
                         $quote->addProduct($product, $buyRequest);
                         $cartUpdated = true;
                     } catch (Exception $e) {
                         $cartUpdated = false;
                         break;
                     }
                 }
             }
         }
         if ($cartUpdated) {
             Mage::getSingleton('core/session')->setData('startDateInitial', $startDate);
             Mage::getSingleton('core/session')->setData('endDateInitial', $endDate);
             $quote->save();
             Mage::getModel('checkout/cart')->setQuote($quote);
         }
     }
 }
 /**
  * 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));
 }