Пример #1
0
 /**
  * This function will return the price for any product type.
  * A configurable product has attributes
  * A bundle product is composed from bundle_options and bundle_quantities for every option.
  * A bundle product has an extra bundle_option_qty1 for qtys which are set as default and can't be changed by the user.
  * @param $product
  * @param $attributes
  * @param $bundleOptions
  * @param $bundleOptionsQty1 this is for holding default Bundle Quantities
  * @param $bundleOptionsQty
  * @param $startDate
  * @param $endDate
  * @param $qty
  * @param null $onClick
  *
  * @return int
  */
 public static function getPriceForAnyProductType($product, $attributes, $bundleOptions, $bundleOptionsQty1, $bundleOptionsQty, $startDate, $endDate, $qty, &$onClick = null)
 {
     if ($qty == '' || $qty == 0) {
         $qty = 1;
     }
     $productId = $product->getId();
     $customerGroup = ITwebexperts_Payperrentals_Helper_Data::getCustomerGroup();
     $qtyArr = ITwebexperts_Payperrentals_Helper_Inventory::getQuantityArrayForProduct($product, $qty, $attributes, $bundleOptions, $bundleOptionsQty1, $bundleOptionsQty);
     $typeId = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($productId, 'type_id');
     $priceAmount = 0;
     if ($typeId == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_CONFIGURABLE) {
         $priceAmount = $qty * ITwebexperts_Payperrentals_Helper_Price::calculatePrice(key($qtyArr), $startDate, $endDate, $qty, $customerGroup);
     } elseif ($typeId == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_GROUPED) {
         reset($qtyArr);
         $productAssoc = Mage::getModel('catalog/product')->load(key($qtyArr));
         $onClick = "setLocation('" . Mage::helper('checkout/cart')->getAddUrl($productAssoc, array('_query' => array('options' => array('start_date' => $startDate, 'end_date' => $endDate, 'qty' => $qty, 'is_filtered' => true), 'start_date' => $startDate, 'end_date' => $endDate, 'qty' => $qty, 'is_filtered' => true))) . "');";
         $priceAmount = $qty * ITwebexperts_Payperrentals_Helper_Price::calculatePrice(key($qtyArr), $startDate, $endDate, $qty, $customerGroup);
     } elseif ($typeId != ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_BUNDLE || $product->getBundlePricingtype() == ITwebexperts_Payperrentals_Model_Product_Bundlepricingtype::PRICING_BUNDLE_FORALL) {
         $priceAmount = $qty * ITwebexperts_Payperrentals_Helper_Price::calculatePrice($product->getId(), $startDate, $endDate, $qty, $customerGroup);
     } elseif ($bundleOptions) {
         foreach ($qtyArr as $iProduct => $iQty) {
             $priceVal = ITwebexperts_Payperrentals_Helper_Price::calculatePrice($iProduct, $startDate, $endDate, $qty, $customerGroup);
             if ($priceVal == -1) {
                 $priceAmount = -1;
                 break;
             }
             $priceAmount += $iQty * $priceVal;
         }
         $priceAmount *= $qty;
     }
     if ($priceAmount != -1) {
         $hasMultiply = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($product->getId(), 'payperrentals_has_multiply');
         if ($hasMultiply == ITwebexperts_Payperrentals_Model_Product_Hasmultiply::STATUS_ENABLED) {
             $priceAmount += self::getOptionsPrice($product, $priceAmount / $qty) * $qty;
         } else {
             $priceAmount += self::getOptionsPrice($product, $priceAmount);
         }
     }
     return $priceAmount;
 }
Пример #2
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));
 }