Example #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;
 }
Example #2
0
 /**
  * Renders grid column
  *
  * @param   Varien_Object $row
  * @return  string
  */
 public function render(Varien_Object $_row)
 {
     if (ITwebexperts_Payperrentals_Helper_Data::isReservationType($_row->getId())) {
         $data = intval(ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($_row->getId(), 'payperrentals_quantity'));
     } else {
         $data = intval($_row->getQty());
     }
     return $data;
 }
Example #3
0
 public function isVirtual($product = null)
 {
     $hasShipping = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($this->getProduct($product)->getId(), 'payperrentals_has_shipping');
     $isReservation = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($this->getProduct($product)->getId(), 'is_reservation');
     if ($isReservation != ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_DISABLED && $isReservation != ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_NOTSET) {
         return Mage::helper('payperrentals/config')->removeShipping() || $hasShipping == ITwebexperts_Payperrentals_Model_Product_Hasshipping::STATUS_DISABLED;
     } else {
         return parent::isVirtual($product);
     }
 }
Example #4
0
 /**
  * Convert block to html string
  *
  * @return string
  */
 protected function _toHtml()
 {
     if (Mage::registry('current_product') == $this->getProduct()) {
         return '<div class="pricingppr">' . $this->getPriceBundle() . '</div>' . parent::_toHtml();
     } else {
         $product = $this->getProduct();
         $_isReservation = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($product->getId(), 'is_reservation');
         if ($_isReservation != ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_DISABLED && $_isReservation !== false) {
             $priceHtml = $this->getLayout()->createBlock("payperrentals/bundle_catalog_product_price")->setTemplate('payperrentals/bundle/catalog/product/priceppr.phtml')->setProduct($product)->setPriceElementIdPrefix('bundle-price-')->setIdSuffix($this->getIdSuffix())->toHtml();
             return $priceHtml;
         }
         return parent::_toHtml();
     }
 }
Example #5
0
 /**
  * Convert block to html string
  *
  * @return string
  */
 protected function _toHtml()
 {
     $product = $this->getProduct();
     $isReservation = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($product->getId(), 'is_reservation');
     $typeId = $product->getTypeId();
     if ($this->getTemplate() == $this->getTierPriceTemplate()) {
         return parent::_toHtml();
     }
     if ($typeId == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE || $isReservation != ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_DISABLED && $isReservation !== false) {
         $priceHtml = $this->getLayout()->createBlock("payperrentals/catalog_product_price")->setTemplate('payperrentals/catalog/product/priceppr.phtml')->setProduct($product)->setDisplayMinimalPrice($this->getDisplayMinimalPrice())->setIdSuffix($this->getIdSuffix());
         $priceHtml = $priceHtml->toHtml();
         return $priceHtml;
     }
     return parent::_toHtml();
 }
Example #6
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;
 }
Example #7
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'));
 }
Example #8
0
 /**
  * @param ITwebexperts_Payperrentals_Model_Reservationorders $reservationOrder
  * @param array $serialNumbers
  * @param array $orderItems
  * @param int $reservationId
  *
  * @return array
  */
 private function getAllTheSerialNumbersForOrder($reservationOrder, $serialNumbers, $orderItems, $reservationId, $shipQty)
 {
     /** @var $payperrentalsUseSerials bool */
     $payperrentalsUseSerials = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($reservationOrder->getProductId(), 'payperrentals_use_serials');
     /** @var array $serialNumbersForOrderItems */
     $serialNumbersForOrderItems = array();
     /**
      * Get a list of manually entered serial numbers in the shipment form
      */
     if ($payperrentalsUseSerials) {
         foreach ($serialNumbers as $salesOrderItemId => $serialArr) {
             if ($salesOrderItemId == $orderItems[$reservationId]) {
                 foreach ($serialArr as $enteredSerial) {
                     if ($enteredSerial != '') {
                         if (!in_array($enteredSerial, $serialNumbersForOrderItems)) {
                             $serialNumbersForOrderItems[] = $enteredSerial;
                         }
                     }
                 }
             }
         }
         /*
          * Completes the array of entered serial numbers with non broken and not under maintenance serial numbers
          * */
         if (count($serialNumbersForOrderItems) < $shipQty) {
             $collectionSerials = Mage::getModel('payperrentals/serialnumbers')->getCollection()->addEntityIdFilter($reservationOrder->getProductId())->addSelectFilter("NOT FIND_IN_SET(sn, '" . implode(',', $serialNumbersForOrderItems) . "') AND (status = 'A')");
             $j = 0;
             foreach ($collectionSerials as $item) {
                 /** @var $item ITwebexperts_Payperrentals_Model_Serialnumbers */
                 if (!in_array($item->getSn(), $serialNumbersForOrderItems)) {
                     $serialNumbersForOrderItems[] = $item->getSn();
                     if ($j >= $shipQty - count($serialNumbersForOrderItems)) {
                         break;
                     }
                     $j++;
                 }
             }
         }
         $this->updateSerialNumbersStatus($serialNumbersForOrderItems);
     }
     return $serialNumbersForOrderItems;
 }
Example #9
0
 /**
  * @param Varien_Event_Observer $observer
  */
 public function updateTurnoverPeriods(Varien_Event_Observer &$observer)
 {
     /*
      * If shipping is enabled then turnover are got from the defined ones not the global ones.
      */
     $configHelper = Mage::helper('rshipping/config');
     if (!$configHelper->isEnabled(Mage::app()->getStore()->getId())) {
         return;
     }
     $turnoverTimeBeforeShip = 0;
     //$observer->getEvent()->getTurnoverTimeBefore();
     $turnoverTimeAfterShip = 0;
     //$observer->getEvent()->getTurnoverTimeAfter();
     $productId = $observer->getEvent()->getProduct();
     /** @var $product Mage_Catalog_Model_Product */
     $product = Mage::getModel('catalog/product')->load($productId);
     $shippingMethod = $observer->getEvent()->getShippingMethod();
     $postcode = $observer->getEvent()->getPostcode();
     /** Loading rental shipping method data */
     $rentalShippingMethod = Mage::getModel('rshipping/rshipping')->load($shippingMethod, 'shipping_method');
     if (!$rentalShippingMethod->getId()) {
         return;
     }
     /** Check if all methods allowing, without product configuration */
     $storeId = Mage::app()->getRequest()->getParam('store_id') ? Mage::app()->getRequest()->getParam('store_id') : Mage::app()->getStore()->getId();
     $isAllowAllMethods = $configHelper->isAllowAllMethods($storeId);
     if ($isAllowAllMethods) {
         $productAvailability = true;
     } else {
         $prodShippingMethod = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($product->getId(), 'shipping_method');
         $shippingMethodArr = array();
         if ($prodShippingMethod) {
             $shippingMethodArr = explode(',', $prodShippingMethod);
         }
         $productAvailability = in_array($rentalShippingMethod->getId(), $shippingMethodArr) && $product->getAllowShipping() ? true : false;
     }
     if ($productAvailability) {
         $startPaddingCalcTimeStamp = $observer->getEvent()->getOrderItemBeforeTurnoverTimestamp();
         /** Calculate ups transit time by API */
         $upsTransitTime = 0;
         if (stripos($rentalShippingMethod->getShippingMethod(), 'ups') !== false && $configHelper->isLiveTransitApi(Mage::app()->getStore()->getId()) && $rentalShippingMethod->getUseLiveUpsApi()) {
             $upsTransitTime = Mage::helper('rshipping')->getTimeInTransit($postcode, $product, $rentalShippingMethod->getShippingMethod());
         }
         $turnoverTimeBeforeShip += ITwebexperts_Payperrentals_Helper_Data::getPeriodInSeconds($rentalShippingMethod->getTurnoverBeforePeriod(), $rentalShippingMethod->getTurnoverBeforeType()) + ITwebexperts_Payperrentals_Helper_Data::getPeriodInSeconds($upsTransitTime, 3);
         $turnoverTimeAfterShip += ITwebexperts_Payperrentals_Helper_Data::getPeriodInSeconds($rentalShippingMethod->getTurnoverAfterPeriod(), $rentalShippingMethod->getTurnoverAfterType());
         /** Calculate turnover before for exists orders with ups shipping method */
         $turnoverTimeBeforeShipForIgnore = $turnoverTimeBeforeShip;
         if (stripos($rentalShippingMethod->getShippingMethod(), 'ups') !== false && $rentalShippingMethod->getIgnoreTurnoverDay()) {
             $ignoreTurnoverDayAr = explode(',', $rentalShippingMethod->getIgnoreTurnoverDay());
             while ($turnoverTimeBeforeShipForIgnore != 0) {
                 if (in_array(date('w', $startPaddingCalcTimeStamp - $turnoverTimeBeforeShipForIgnore), $ignoreTurnoverDayAr)) {
                     /* Plus 1 day if day ignored*/
                     $turnoverTimeBeforeShip += ITwebexperts_Payperrentals_Helper_Data::getPeriodInSeconds(1, 3);
                 }
                 $turnoverTimeBeforeShipForIgnore -= ITwebexperts_Payperrentals_Helper_Data::getPeriodInSeconds(1, 3);
             }
         }
         $observer->getEvent()->setTurnoverTimeBefore($turnoverTimeBeforeShip);
         $observer->getEvent()->setTurnoverTimeAfter($turnoverTimeAfterShip);
     }
 }
Example #10
0
 public static function getBuyoutPrice($product, $configurableParent = null)
 {
     if (is_object($configurableParent) && $configurableParent->getPayperrentalsBuyoutprice()) {
         $buyoutPrice = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($configurableParent->getId(), 'payperrentals_buyoutprice');
     } else {
         $buyoutPrice = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($product->getId(), 'payperrentals_buyoutprice');
     }
     return $buyoutPrice;
 }
Example #11
0
 /**
  * Checks if membership sku is allowed to rent the product
  *
  * @param $product
  */
 public function membershipAllowsProduct($productId, $membershipSku)
 {
     $_resExcludedMembership = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($productId, 'res_excluded_membership');
     $disabledMemberships = explode(',', $_resExcludedMembership);
     if (!in_array($membershipSku, $disabledMemberships)) {
         return true;
     } else {
         return false;
     }
 }
Example #12
0
 /**
  * Address item initialization
  *
  * @param  $item
  * @return bool
  */
 protected function _initItem($address, $item)
 {
     if ($item instanceof Mage_Sales_Model_Quote_Address_Item) {
         $quoteItem = $item->getAddress()->getQuote()->getItemById($item->getQuoteItemId());
     } else {
         $quoteItem = $item;
     }
     $product = $quoteItem->getProduct();
     $product->setCustomerGroupId($quoteItem->getQuote()->getCustomerGroupId());
     /**
      * Quote super mode flag mean what we work with quote without restriction
      */
     if ($item->getQuote()->getIsSuperMode()) {
         if (!$product) {
             return false;
         }
     } else {
         if (!$product || !$product->isVisibleInCatalog()) {
             return false;
         }
     }
     $isReservationBundle = false;
     if ($quoteItem->getParentItem() && $quoteItem->getParentItem()->getProductType() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_BUNDLE) {
         $isReservation = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($quoteItem->getParentItem()->getProductId(), 'is_reservation');
         $bundlePriceType = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($quoteItem->getParentItem()->getProductId(), 'bundle_pricingtype');
         if ($isReservation != ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_DISABLED && $bundlePriceType == ITwebexperts_Payperrentals_Model_Product_Bundlepricingtype::PRICING_BUNDLE_FORALL) {
             $isReservationBundle = true;
             if (!$quoteItem->getParentItem()->getIsCalculatedBundle()) {
                 $quoteItem->getParentItem()->setIsCalculatedBundle(true);
                 $finalPrice = $quoteItem->getParentItem()->getProduct()->getFinalPrice($quoteItem->getParentItem()->getQty());
                 $item->setPrice($finalPrice)->setBaseOriginalPrice($finalPrice);
                 /*This is needed because the price is already calculated for all the qtys*/
                 $item->setQty(1);
                 $item->calcRowTotal();
             }
         }
     }
     if (!$isReservationBundle) {
         if ($quoteItem->getParentItem() && $quoteItem->isChildrenCalculated()) {
             $finalPrice = $quoteItem->getParentItem()->getProduct()->getPriceModel()->getChildFinalPrice($quoteItem->getParentItem()->getProduct(), $quoteItem->getParentItem()->getQty(), $quoteItem->getProduct(), $quoteItem->getQty());
             $item->setPrice($finalPrice)->setBaseOriginalPrice($finalPrice);
             $item->calcRowTotal();
         } else {
             if (!$quoteItem->getParentItem()) {
                 $source = unserialize($quoteItem->getProduct()->getCustomOption('info_buyRequest')->getValue());
                 $finalPrice = $product->getFinalPrice($quoteItem->getQty());
                 $item->setData(ITwebexperts_Payperrentals_Helper_Price::DAMAGE_WAIVER_OPTION, 0);
                 if ($product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION)) {
                     if ($product->getTypeId() == 'configurable') {
                         $children = $item->getChildren();
                         if (count($children)) {
                             $damageProduct = $children[0]->getProduct();
                         } else {
                             $damageProduct = $product;
                         }
                     } else {
                         $damageProduct = $product;
                     }
                     $damageWaiverPrice = ITwebexperts_Payperrentals_Helper_Price::getDamageWaiver($damageProduct, $finalPrice);
                     $item->setData(ITwebexperts_Payperrentals_Helper_Price::DAMAGE_WAIVER_OPTION_PRICE, $damageWaiverPrice);
                     $forceDamageWaiver = Mage::helper('payperrentals/config')->forceDamageWaiver();
                     if (isset($source[ITwebexperts_Payperrentals_Helper_Price::DAMAGE_WAIVER_OPTION]) || $forceDamageWaiver) {
                         if ((bool) $source[ITwebexperts_Payperrentals_Helper_Price::DAMAGE_WAIVER_OPTION] || $forceDamageWaiver) {
                             if ($damageWaiverPrice) {
                                 $finalPrice += $damageWaiverPrice;
                                 $item->setData(ITwebexperts_Payperrentals_Helper_Price::DAMAGE_WAIVER_OPTION, $damageWaiverPrice);
                             }
                         }
                     }
                 }
                 $item->setPrice($finalPrice)->setBaseOriginalPrice($finalPrice);
                 $item->calcRowTotal();
                 $this->_addAmount($item->getRowTotal());
                 $this->_addBaseAmount($item->getBaseRowTotal());
                 $address->setTotalQty($address->getTotalQty() + $item->getQty());
             }
         }
     }
     return true;
 }
Example #13
0
 public function getFutureReservationLimit($product = null, $storeId = null)
 {
     if (is_object($product)) {
         $productId = $product->getId();
     } else {
         $productId = $product;
     }
     $useGlobalFutureLimit = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($productId, 'use_global_future_limit');
     if ($useGlobalFutureLimit == 0) {
         $futureLimit = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($productId, 'future_reservation_limit');
         return (int) $futureLimit;
     } else {
         if ($storeId) {
             return (int) Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_FUTURE_LIMIT, $storeId);
         } else {
             return (int) Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_FUTURE_LIMIT);
         }
     }
 }
Example #14
0
 /**
  * @param Varien_Object $row
  * @return mixed
  */
 public function render(Varien_Object $row)
 {
     $data = $row->getData($this->getColumn()->getIndex());
     //$product = Mage::getModel('catalog/product')->load($data);
     return ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($data, 'name');
 }
Example #15
0
 public function isVirtual($product = null)
 {
     $hasShipping = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($this->getProduct($product)->getId(), 'payperrentals_has_shipping');
     return Mage::helper('payperrentals/config')->removeShipping() || $hasShipping == ITwebexperts_Payperrentals_Model_Product_Hasshipping::STATUS_DISABLED;
 }
Example #16
0
 /**
  * Function which return the deposit price for all the products in the quote
  * @param $quote
  * @return float|int
  */
 public static function getDeposit($quote)
 {
     $quoteItems = $quote->getItemsCollection();
     $depositAmount = 0;
     if (Mage::app()->getStore()->isAdmin()) {
         $storeID = Mage::getSingleton('adminhtml/session_quote')->getStoreId();
     } else {
         $storeID = Mage::app()->getStore()->getId();
     }
     if ($storeID) {
         $depositAmountPerOrder = Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_GLOBAL_DEPOSIT_PER_ORDER, $storeID);
     } else {
         $depositAmountPerOrder = Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_GLOBAL_DEPOSIT_PER_ORDER);
     }
     $totalPrice = 0;
     foreach ($quoteItems as $item) {
         $product = Mage::getModel('catalog/product')->load($item->getProduct()->getId());
         $productOptions = $item->getOptionsByCode();
         $options = $productOptions['info_buyRequest'];
         $finalPrice = ITwebexperts_Payperrentals_Helper_Price::getPriceForAnyProductType($item->getProduct(), isset($options['attributes']) ? $options['attributes'] : null, isset($options['bundle_option']) ? $options['bundle_option'] : null, isset($options['bundle_option_qty1']) ? $options['bundle_option_qty1'] : null, isset($options['bundle_option_qty']) ? $options['bundle_option_qty'] : null, $item->getBuyRequest()->getStartDate(), $item->getBuyRequest()->getEndDate(), $item->getQty());
         if ($item->getProductType() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_BUNDLE || $item->getProductType() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_CONFIGURABLE || $item->getProductType() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_GROUPED) {
             continue;
         }
         if ($item->getParentItem() && $item->getParentItem()->getProductType() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_BUNDLE) {
             $qty1 = $item->getParentItem()->getQty();
         } else {
             $qty1 = 1;
         }
         if ($storeID) {
             $depositAmountPerProduct = Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_GLOBAL_DEPOSIT_PER_PRODUCT, $storeID);
         } else {
             $depositAmountPerProduct = Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_GLOBAL_DEPOSIT_PER_PRODUCT);
         }
         $useGlobalDeposit = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($product->getId(), 'use_global_deposit_per_product');
         if (!$useGlobalDeposit) {
             $depositAmountPerProduct = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($product->getId(), 'payperrentals_deposit');
         }
         if ($depositAmountPerOrder == '') {
             if (strpos($depositAmountPerProduct, '%') !== false) {
                 $depositAmountPerProduct = floatval(substr($depositAmountPerProduct, 0, strlen($depositAmountPerProduct) - 1));
                 $depositAmountPerProduct = $depositAmountPerProduct / 100 * $finalPrice;
             }
             $depositAmount += floatval($depositAmountPerProduct) * $item->getQty() * $qty1;
         } else {
             $totalPrice += $finalPrice;
         }
     }
     if ($totalPrice > 0) {
         if (strpos($depositAmountPerOrder, '%') !== false) {
             $depositAmount = floatval(substr($depositAmountPerOrder, 0, strlen($depositAmountPerOrder) - 1));
             $depositAmount = $depositAmount / 100 * $totalPrice;
         }
     }
     return $depositAmount;
 }
Example #17
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;
 }
Example #18
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));
 }