Ejemplo n.º 1
0
 /**
  * function used to show the price near the bundle options.
  * @param $item
  * @param $order
  *
  * @return string
  */
 public function getBundleOptionPriceAsHtml($item, $order)
 {
     $result = '';
     if ($item->getParentItem()) {
         $isReservation = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($item->getParentItem()->getProductId(), 'is_reservation');
         $bundlePriceType = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($item->getParentItem()->getProductId(), 'bundle_pricingtype');
         if ($isReservation) {
             if (!$bundlePriceType || $bundlePriceType == ITwebexperts_Payperrentals_Model_Product_Bundlepricingtype::PRICING_BUNDLE_PERPRODUCT) {
                 if ($item instanceof Mage_Sales_Model_Order_Item) {
                     $options = $item->getProductOptions();
                 } else {
                     $options = $item->getOrderItem()->getProductOptions();
                 }
                 if (isset($options['info_buyRequest']['start_date'])) {
                     $selectionPrice = ITwebexperts_Payperrentals_Helper_Price::calculatePrice($item->getProductId(), $options['info_buyRequest']['start_date'], $options['info_buyRequest']['end_date'], $options['info_buyRequest']['qty'], ITwebexperts_Payperrentals_Helper_Data::getCustomerGroup());
                     $formattedPrice = $order->formatPrice($selectionPrice);
                 } else {
                     $formattedPrice = ITwebexperts_Payperrentals_Helper_Price::getPriceListHtml($item->getProductId(), -1, true);
                 }
             } else {
                 $formattedPrice = '';
             }
             $result = " " . $formattedPrice;
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
 public function getPriceList()
 {
     if ($this->getProduct()->getCanShowPrice()) {
         return ITwebexperts_Payperrentals_Helper_Price::getPriceListHtml($this->getProduct(), Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Data::XML_PATH_PRICING_ON_LISTING));
     } else {
         return '';
     }
 }
Ejemplo n.º 3
0
 public function getPriceBundle()
 {
     $product = $this->getProduct();
     $htmlOutput = '';
     if (ITwebexperts_Payperrentals_Helper_Data::isReservationType($product)) {
         $bundlePriceType = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($product->getId(), 'bundle_pricingtype');
         if ($bundlePriceType == ITwebexperts_Payperrentals_Model_Product_Bundlepricingtype::PRICING_BUNDLE_FORALL) {
             $htmlOutput = ITwebexperts_Payperrentals_Helper_Price::getPriceListHtml($product, Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_PRICING_ON_LISTING));
         } else {
             $htmlOutput = '';
         }
         $htmlOutput .= '<input type="hidden" class="ppr_attr_butname" value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . Mage::helper('payperrentals')->__('Rent') . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" />';
     }
     return $htmlOutput;
 }
Ejemplo n.º 4
0
 public function getSelectionQtyTitlePrice($_selection, $includeContainer = true)
 {
     $price = $this->getProduct()->getPriceModel()->getSelectionPreFinalPrice($this->getProduct(), $_selection);
     $formattedPrice = $this->formatPriceString($price, $includeContainer);
     if ($_selection->getTypeId() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE) {
         if ($this->getProduct()->getBundlePricingtype() == ITwebexperts_Payperrentals_Model_Product_Bundlepricingtype::PRICING_BUNDLE_PERPRODUCT) {
             $formattedPrice = ITwebexperts_Payperrentals_Helper_Price::getPriceListHtml($_selection, -1, true);
         } else {
             $formattedPrice = '';
         }
     }
     $this->setFormatProduct($_selection);
     $priceTitle = $_selection->getSelectionQty() * 1 . ' x ' . $this->escapeHtml($_selection->getName());
     $priceTitle .= ' &nbsp; ' . ($includeContainer ? '<span class="price-notice">' : '') . '+' . $formattedPrice . ($includeContainer ? '</span>' : '');
     return $priceTitle;
 }
Ejemplo n.º 5
0
 /**
  * Render price for products
  *
  * @param   Varien_Object $row
  * @return  string
  */
 public function render(Varien_Object $row)
 {
     $_data = $row->getData($this->getColumn()->getIndex());
     $_priceHtml = false;
     if ($_data) {
         $_priceHtml = $_data;
     } elseif (is_null($_data)) {
         $_product = $row->load($row->getId());
         if ($_product) {
             $_priceHtml = ITwebexperts_Payperrentals_Helper_Price::getPriceListHtml($_product, 2);
         }
     }
     if ($_priceHtml !== false) {
         return $_priceHtml;
     } else {
         return $this->getColumn()->getDefault();
     }
 }
Ejemplo n.º 6
0
 public function getPriceList()
 {
     return ITwebexperts_Payperrentals_Helper_Price::getPriceListHtml($this->getProduct(), Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_PRICING_ON_LISTING));
 }
Ejemplo n.º 7
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;
 }
Ejemplo n.º 8
0
 /**
  * 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));
 }