Beispiel #1
0
 public static function getAdminDamageWaiverHtml($item, $productId)
 {
     $html = '<div>';
     $startDate = Mage::getSingleton('core/session')->getData('startDateInitial');
     $endDate = Mage::getSingleton('core/session')->getData('endDateInitial');
     $damageWaiverSelected = false;
     if (isset($item) && $item != -1 && Mage::app()->getRequest()->getActionName() != 'configureProductToAdd') {
         $buyRequest = $item->getBuyRequest();
         if ($buyRequest->getDamageWaiver() != '' && $buyRequest->getDamageWaiver() == '1') {
             $damageWaiverSelected = true;
         }
         $_showTime = (bool) Mage::getResourceModel('catalog/product')->getAttributeRawValue($item->getProductId(), 'payperrentals_use_times', $item->getStoreId());
         if (!Mage::helper('payperrentals/config')->isNonSequentialSelect(Mage::app()->getStore()->getId())) {
             $startDate = $buyRequest->getStartDate() != '' ? $buyRequest->getStartDate() : ($startDate ? $startDate : false);
             $endDate = $buyRequest->getEndDate() != '' ? $buyRequest->getEndDate() : ($endDate ? $endDate : false);
         } else {
             $startDate = $buyRequest->getStartDate() != '' ? ITwebexperts_Payperrentals_Helper_Date::localiseNonsequentialBuyRequest($buyRequest->getStartDate(), $_showTime) : ($startDate ? $startDate : false);
             $endDate = $buyRequest->getStartDate() != '' ? ITwebexperts_Payperrentals_Helper_Date::localiseNonsequentialBuyRequest($buyRequest->getStartDate(), $_showTime) : ($startDate ? $startDate : false);
         }
     }
     if ($startDate) {
         list($startDate, $endDate) = ITwebexperts_Payperrentals_Helper_Date::convertDatepickerToDbFormat($startDate, $endDate);
         $rentalPrice = ITwebexperts_Payperrentals_Helper_Price::calculatePrice($productId, $startDate, $endDate, 1, ITwebexperts_Payperrentals_Helper_Data::getCustomerGroup());
         $damageWaiverPrice = self::getDamageWaiver($productId, $rentalPrice);
     } else {
         $damageWaiverPrice = self::getDamageWaiver($productId, 0);
     }
     if ($damageWaiverPrice) {
         $html .= '<input type="radio" name="damage_waiver" class="damage-waiver-input" id="damageWaiverNo" value="0" ';
         if (!$damageWaiverSelected) {
             $html .= 'checked="checked"';
         }
         $html .= '/>';
         $html .= '<label for="damageWaiverNo">' . Mage::helper('payperrentals')->__(' No') . '</label>';
         $html .= '</div>';
         $html .= '<div>';
         $html .= '<input type="radio" name="damage_waiver" class="damage-waiver-input" id="damageWaiverYes" value="1" ';
         if ($damageWaiverSelected) {
             $html .= 'checked="checked"';
         }
         $html .= '/>';
         $html .= '<label for="damageWaiverYes">' . Mage::helper('payperrentals')->__(' Yes +%s', Mage::helper('checkout')->formatPrice($damageWaiverPrice > -1 ? $damageWaiverPrice : $item->getData(ITwebexperts_Payperrentals_Helper_Price::DAMAGE_WAIVER_OPTION_PRICE), true, true)) . '</label>';
         $html .= '</div>';
     }
     return $html;
 }
 /**
  * Get bundled selections (slections-products collection)
  *
  * Returns array of options objects.
  * Each option object will contain array of selections objects
  *
  * @return array
  */
 public function getBundleOptions(Mage_Catalog_Model_Product_Configuration_Item_Interface $item)
 {
     $options = array();
     $product = $item->getProduct();
     /**
      * @var Mage_Bundle_Model_Product_Type
      */
     $typeInstance = $product->getTypeInstance(true);
     // get bundle options
     $optionsQuoteItemOption = $item->getOptionByCode('bundle_option_ids');
     $bundleOptionsIds = $optionsQuoteItemOption ? unserialize($optionsQuoteItemOption->getValue()) : array();
     if ($bundleOptionsIds) {
         /**
          * @var Mage_Bundle_Model_Mysql4_Option_Collection
          */
         $optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $product);
         // get and add bundle selections collection
         $selectionsQuoteItemOption = $item->getOptionByCode('bundle_selection_ids');
         $selectionsCollection = $typeInstance->getSelectionsByIds(unserialize($selectionsQuoteItemOption->getValue()), $product);
         $bundleOptions = $optionsCollection->appendSelections($selectionsCollection, true);
         foreach ($bundleOptions as $bundleOption) {
             if ($bundleOption->getSelections()) {
                 $option = array('label' => $bundleOption->getTitle(), 'value' => array());
                 $bundleSelections = $bundleOption->getSelections();
                 foreach ($bundleSelections as $bundleSelection) {
                     $qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1;
                     if ($qty) {
                         $val = $qty . ' x ' . $this->escapeHtml($bundleSelection->getName()) . ' ';
                         if ($bundleSelection->getTypeId() == 'reservation') {
                             if ($product->getBundlePricingtype() == ITwebexperts_Payperrentals_Model_Product_Bundlepricingtype::PRICING_BUNDLE_PERPRODUCT) {
                                 $customerGroup = ITwebexperts_Payperrentals_Helper_Data::getCustomerGroup();
                                 if (!is_object($product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION))) {
                                     $source = unserialize($product->getCustomOption('info_buyRequest')->getValue());
                                     if (isset($source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION])) {
                                         $start_date = $source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION];
                                         $end_date = $source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::END_DATE_OPTION];
                                     }
                                 } else {
                                     $start_date = $product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION)->getValue();
                                     $end_date = $product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::END_DATE_OPTION)->getValue();
                                 }
                                 $data = new Varien_Object(array('start_date' => $start_date, 'end_date' => $end_date));
                                 Mage::dispatchEvent('payperrentals_bundle_option_calculate_price_before', array('data' => $data, 'item' => $item, 'selection' => $bundleSelection));
                                 extract($data->getData(), EXTR_OVERWRITE);
                                 $priceAmount = ITwebexperts_Payperrentals_Helper_Price::calculatePrice($bundleSelection, $start_date, $end_date, $qty, $customerGroup);
                                 $val .= Mage::helper('core')->currency($priceAmount);
                             } else {
                             }
                         } else {
                             $val .= Mage::helper('core')->currency($this->getSelectionFinalPrice($item, $bundleSelection));
                         }
                         $option['value'][] = $val;
                     }
                 }
                 if ($option['value']) {
                     $options[] = $option;
                 }
             }
         }
     }
     return $options;
 }
Beispiel #3
0
 public function renderDates($options, $item = null, $product = null, $isCart = false)
 {
     $isSingle = true;
     $nonSequential = 0;
     if ($item && $item->getOrder() && !$isCart) {
         $isSingleBool = ITwebexperts_Payperrentals_Helper_Data::isSingleOrder($item->getOrder());
         $isSingle = $isSingleBool['bool'];
     } else {
         if ($item && $item->getQuote() && !$isCart) {
             $isSingle = false;
         }
     }
     $productId = -1;
     $storeId = 1;
     $qty = 0;
     if (!is_null($item) && !is_null($item->getProductId())) {
         $productId = $item->getProductId();
         $storeId = $item->getStoreId();
         $qty = $item->getQty();
         $product = $item->getProduct();
     } else {
         if (!is_null($product) && is_object($product)) {
             $productId = $product->getId();
         } elseif (isset($options['info_buyRequest']['product'])) {
             $productId = $options['info_buyRequest']['product'];
         }
     }
     $showTime = (bool) Mage::getResourceModel('catalog/product')->getAttributeRawValue($productId, 'payperrentals_use_times', $storeId);
     $customerGroup = ITwebexperts_Payperrentals_Helper_Data::getCustomerGroup();
     $source = $this->_getOptionsArray($product, $options);
     $options = array();
     $isBuyout = isset($source['buyout']) ? $source['buyout'] : 'false';
     if ($isBuyout != "false") {
         $options[] = array('label' => $this->__('Product Type'), 'value' => 'Rental Buyout', 'type' => 'reservation');
     } else {
         if (isset($source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION]) && $source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION] != '') {
             $startDate = ITwebexperts_Payperrentals_Helper_Date::formatDbDate($source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION], !$showTime, false);
             $endDate = ITwebexperts_Payperrentals_Helper_Date::formatDbDate($source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION], !$showTime, false);
             if (!isset($nonSequential) || $nonSequential == 0) {
                 $endDate = ITwebexperts_Payperrentals_Helper_Date::formatDbDate($source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::END_DATE_OPTION], !$showTime, false);
                 if (isset($source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::FIXED_DATE_ID])) {
                     $fixedRentalDatesCollection = Mage::getModel('payperrentals/fixedrentaldates')->getCollection()->addFieldToFilter('id', $source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::FIXED_DATE_ID])->getFirstItem();
                     $fixedNameId = $fixedRentalDatesCollection->getNameid();
                     $fixedStartDate = $fixedRentalDatesCollection->getStartDate();
                     $fixedEndDate = $fixedRentalDatesCollection->getEndDate();
                     $difference = strtotime($fixedEndDate) - strtotime($fixedStartDate);
                     $startDate = date('Y-m-d', strtotime($startDate)) . ' ' . date('H:i:s', strtotime($fixedStartDate));
                     $endDate = date('Y-m-d H:i:s', strtotime($startDate) + $difference);
                     $fixedRentalNamesCollection = Mage::getModel('payperrentals/fixedrentalnames')->getCollection()->addFieldToFilter('id', $fixedNameId)->getFirstItem();
                     $fixedName = $fixedRentalNamesCollection->getName();
                     $options[] = array('label' => $this->__('Start Date'), 'value' => ITwebexperts_Payperrentals_Helper_Date::formatDbDate($startDate, !$showTime, false), 'type' => 'reservation');
                     $options[] = array('label' => $this->__('End Date'), 'value' => ITwebexperts_Payperrentals_Helper_Date::formatDbDate($endDate, !$showTime, false), 'type' => 'reservation');
                     //$options[] = array('label' => $this->__('Fixed Date'), 'value' => $fixedName, 'type' => 'reservation');
                 } else {
                     $options[] = array('label' => $this->__('Start Date'), 'value' => $startDate, 'type' => 'reservation');
                     $options[] = array('label' => $this->__('End Date'), 'value' => $endDate, 'type' => 'reservation');
                 }
             } else {
                 $options[] = array('label' => $this->__('Dates:'), 'value' => ITwebexperts_Payperrentals_Helper_Date::localiseNonsequentialBuyRequest($startDate, $showTime), 'type' => 'reservation');
             }
             if (!$isCart && $isSingle) {
                 $options = array();
             }
             $damageWaiver = ITwebexperts_Payperrentals_Helper_Price::getDamageWaiver($productId, 1);
             if ($damageWaiver) {
                 $options[] = array('label' => $this->__('Damage Waiver'), 'value' => ITwebexperts_Payperrentals_Helper_Price::getDamageWaiverHtml($item, (bool) $item->getBuyRequest()->getDamageWaiver(), $qty), 'type' => 'reservation');
             }
         } else {
             return array();
         }
     }
     $resultObject = new Varien_Object();
     $resultObject->setResult($options);
     Mage::dispatchEvent('render_cart', array('options' => $source, 'result' => $resultObject, 'product' => $product, 'item' => $item, 'is_cart' => $isCart));
     return $resultObject->getResult();
 }
Beispiel #4
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;
 }
Beispiel #5
0
 /**
  * Get product final price
  *
  * @param   double $qty
  * @param   Mage_Catalog_Model_Product $product
  * @return  double
  */
 public function getFinalPrice($qty = null, $product)
 {
     if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
         return $product->getCalculatedFinalPrice();
     }
     $finalPrice = $this->getBasePrice($product, $qty);
     $product->setFinalPrice($finalPrice);
     Mage::dispatchEvent('catalog_product_get_final_price', array('product' => $product, 'qty' => $qty));
     $finalPrice = $product->getData('final_price');
     $finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice);
     $isReservation = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($product->getId(), 'is_reservation');
     $bundlePriceType = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($product->getId(), 'bundle_pricingtype');
     if ($isReservation != ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_DISABLED) {
         if ($bundlePriceType == ITwebexperts_Payperrentals_Model_Product_Bundlepricingtype::PRICING_BUNDLE_FORALL) {
             if (is_object($product->getCustomOption('info_buyRequest'))) {
                 $source = unserialize($product->getCustomOption('info_buyRequest')->getValue());
                 if (isset($source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION])) {
                     $startingDate = $source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION];
                     $endingDate = $source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::END_DATE_OPTION];
                 }
             }
             if (isset($startingDate) && isset($endingDate)) {
                 $customerGroup = ITwebexperts_Payperrentals_Helper_Data::getCustomerGroup();
                 $finalPrice = ITwebexperts_Payperrentals_Helper_Price::calculatePrice($product->getId(), $startingDate, $endingDate, $qty, $customerGroup);
             }
         } else {
             $finalPrice = $this->getTotalBundleItemsPrice($product, $qty);
         }
     } else {
         $finalPrice += $this->getTotalBundleItemsPrice($product, $qty);
     }
     $product->setFinalPrice($finalPrice);
     return max(0, $product->getData('final_price'));
 }