/** * Calculate late fee for 1 product * * @param $product * @param $qty * @param $originalStartDate * @param $originalEndDate * @param $lateReturnDate * @param $options * @return int */ public static function calculateLateFee($product, $qty, $originalStartDate, $originalEndDate, $lateReturnDate, $options = null) { $originalRentalPrice = ITwebexperts_Payperrentals_Helper_Price::getPriceForAnyProductType($product, 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, $originalStartDate, $originalEndDate, $qty); $rentalPriceIncludingLateTime = ITwebexperts_Payperrentals_Helper_Price::getPriceForAnyProductType($product, 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, $originalStartDate, $lateReturnDate, $qty); $lateFeePrice = $rentalPriceIncludingLateTime - $originalRentalPrice; return $lateFeePrice; }
/** * 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; }
/** * Get price for the selected quantity and dates */ public function getPriceAction() { if (!$this->getRequest()->getParam('product_id') || !$this->getRequest()->getParam('start_date')) { $jsonReturn = array('amount' => -1, 'onclick' => '', 'needsConfigure' => true, 'formatAmount' => -1); $this->getResponse()->setBody(Zend_Json::encode($jsonReturn)); return; } $productId = $this->getRequest()->getParam('product_id'); $product = Mage::getModel('catalog/product')->load($productId); $qty = urldecode($this->getRequest()->getParam('qty')); list($startDate, $endDate) = ITwebexperts_Payperrentals_Helper_Date::saveDatesForGlobalUse($this->getRequest()->getPost()); if ($this->getRequest()->getParam('is_fixed_date')) { //get all fixed dates id with names and hours in a html with rectangle classes.. and disable rent button... have price as an attribute //add onclick event and a hidden field which updates...also enable button and start end date to get the real price $startDate = date('Y-m-d', strtotime($startDate)); $endDate = date('Y-m-d', strtotime($endDate)); $fixedDatesArray = ITwebexperts_Payperrentals_Helper_Data::getFixedRentalDates($product); $fixedDatesDropdown = ''; if (count($fixedDatesArray)) { $fixedDatesDropdown .= '<ul class="fixed_array">'; } $hasAvailability = false; foreach ($fixedDatesArray as $fixedDate) { if (date('Y-m-d', strtotime($fixedDate['start_date'])) == date('Y-m-d', strtotime($startDate))) { if (Mage::helper('payperrentals/inventory')->isAvailable($productId, $fixedDate['start_date'], $fixedDate['end_date'], $qty)) { //if (date('Y-m-d', strtotime($fixedDate['start_date'])) == date('Y-m-d', strtotime($fixedDate['end_date']))) { // $fixedDatesDropdown .= '<li idname="' . $fixedDate['id'] . '">' . date('H:i', strtotime($fixedDate['start_date'])) /*. ' ' . $fixedDate['name']*/ . '</li>'; //} else { $fixedDatesDropdown .= '<li idname="' . $fixedDate['id'] . '">' . Mage::helper('payperrentals')->__('Start: ') . ITwebexperts_Payperrentals_Helper_Date::formatDbDate($fixedDate['start_date'], false, false) . ' ' . Mage::helper('payperrentals')->__('End: ') . ITwebexperts_Payperrentals_Helper_Date::formatDbDate($fixedDate['end_date'], false, false) . '</li>'; //} $hasAvailability = true; } } } if (count($fixedDatesArray)) { $fixedDatesDropdown .= '</ul>'; } if (!$hasAvailability) { $fixedDatesDropdown = Mage::helper('payperrentals')->__('Sorry, there is no availability left for this option'); } $jsonReturn = array('amount' => 0, 'onclick' => '', 'fixedDates' => $fixedDatesDropdown, 'needsConfigure' => false, 'formatAmount' => -1); $this->getResponse()->setBody(Zend_Json::encode($jsonReturn)); return; } $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; $onClick = ''; $priceAmount = ITwebexperts_Payperrentals_Helper_Price::getPriceForAnyProductType($product, $attributes, $bundleOptions, $bundleOptionsQty1, $bundleOptionsQty, $startDate, $endDate, $qty, $onClick); if (Mage::helper('payperrentals/config')->useListButtons() || ITwebexperts_Payperrentals_Helper_Data::isUsingGlobalDates($product)) { ITwebexperts_Payperrentals_Helper_Date::saveDatesForGlobalUse($this->getRequest()->getPost()); } $jsonReturn = array('amount' => $priceAmount, 'onclick' => $onClick, 'needsConfigure' => false, 'formatAmount' => $priceAmount != -1 ? Mage::helper('core')->currency($priceAmount) : -1); $this->getResponse()->setBody(Zend_Json::encode($jsonReturn)); }