Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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();
 }