Beispiel #1
0
 public static function getExtensibleProductsFromOrder($orderId, $date = null)
 {
     $order = Mage::getModel('sales/order')->load($orderId);
     if (!is_null($date)) {
         $date = ITwebexperts_Payperrentals_Helper_Date::toMysqlDate($date, true);
     }
     $productsArr = array();
     foreach ($order->getAllItems() as $_item) {
         if (is_object($_item->getOrderItem())) {
             $item = $_item->getOrderItem();
         } else {
             $item = $_item;
         }
         if ($item->getParentItem()) {
             continue;
         }
         if (is_null($date)) {
             if (Mage::helper('payperrentals/config')->hasExtendEnabled($_item->getId(), $_item->getChildren())) {
                 $productsArr[] = array('name' => $_item->getProduct()->getName(), 'oId' => $_item->getId());
             }
         } else {
             if ($options = $item->getProductOptions()) {
                 if (isset($options['info_buyRequest'])) {
                     if (isset($options['info_buyRequest'][ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION])) {
                         $start_date = $options['info_buyRequest'][ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION];
                         $end_date = $options['info_buyRequest'][ITwebexperts_Payperrentals_Model_Product_Type_Reservation::END_DATE_OPTION];
                         $diffSeconds = ITwebexperts_Payperrentals_Helper_Date::getDifferenceInSeconds($start_date, $date);
                         $maxLength = Mage::helper('payperrentals/config')->getMaximumExtensionLength();
                         $isExtendEnabled = Mage::helper('payperrentals/config')->hasExtendEnabled($_item->getProduct()->getId());
                         $isAvailable = ITwebexperts_Payperrentals_Helper_Inventory::getQuantityForAnyProductTypeFromOptions($_item->getProduct()->getId(), $end_date, $date, $options['info_buyRequest']) > 0;
                         if ($diffSeconds < $maxLength && strtotime($end_date) < strtotime($date) && $isExtendEnabled && $isAvailable) {
                             $productsArr[] = array('name' => $_item->getProduct()->getName(), 'oId' => $_item->getId());
                         }
                     }
                 }
             }
         }
     }
     return $productsArr;
 }
Beispiel #2
0
 private static function _calculatePrice($product, $startingDate, $endingDate, $qty, $customerGroup, $useCurrency = false)
 {
     if (is_numeric($product)) {
         $product = ITwebexperts_Payperrentals_Helper_Data::initProduct($product);
     }
     if (!is_object($product)) {
         return 0;
     }
     list($startingDate, $endingDate) = ITwebexperts_Payperrentals_Helper_Date::convertDatepickerToDbFormat($startingDate, $endingDate);
     $rentalPeriodInSeconds = ITwebexperts_Payperrentals_Helper_Date::getDifferenceInSeconds($startingDate, $endingDate);
     if ($product->getPayperrentalsPricingtype() == ITwebexperts_Payperrentals_Model_Product_Pricingtype::PRICING_PRORATED) {
         $useProRated = true;
     } else {
         $useProRated = false;
     }
     $pricesCollection = self::getPricesCollection($product);
     // If no prices, return 0
     if (count($pricesCollection) == 0) {
         return 0;
     }
     self::reCalculatePeriodFromSettings($rentalPeriodInSeconds, $startingDate, $endingDate, $product);
     $pricesArray = array();
     $hasSpecials = self::getPricesArray($pricesCollection, $pricesArray, $startingDate, $endingDate, $qty, $customerGroup);
     if ($hasSpecials && $rentalPeriodInSeconds > 0) {
         $finalPriceAmount = self::getPriceForAllPricesArray($pricesArray, $useProRated, $rentalPeriodInSeconds);
     } else {
         $finalPriceAmount = self::getFinalPrice($pricesArray, $useProRated, $rentalPeriodInSeconds);
     }
     return $finalPriceAmount;
 }