/** * 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; }
public function getPrice($product, $qty = null) { $isBuyout = false; if ($product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION)) { $from_date = $product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION)->getValue(); } if ($product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::END_DATE_OPTION)) { $to_date = $product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::END_DATE_OPTION)->getValue(); } if ($product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::BUYOUT_PRICE_OPTION)) { $isBuyout = $product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::BUYOUT_PRICE_OPTION)->getValue(); } $price = 0; if (is_null($qty) || $qty <= 0) { $qty = 1; } $customerGroup = $this->_getCustomerGroupId($product); if (isset($from_date) && isset($to_date)) { $price = ITwebexperts_Payperrentals_Helper_Price::calculatePrice($product, $from_date, $to_date, $qty, $customerGroup); $product->setData('final_price', $price); } if ($isBuyout) { $priceTemp = ITwebexperts_Payperrentals_Helper_Price::getBuyoutPrice($product); $product->setData('final_price', $priceTemp); $price = $priceTemp; } return $price; }
public function collect(Mage_Sales_Model_Quote_Address $address) { parent::collect($address); $address->setDamageWaiverAmount(0); $address->setBaseDamageWaiverAmount(0); $items = $this->_getAddressItems($address); if (!count($items)) { return $this; //this makes only address type shipping to come through } $quote = $address->getQuote(); $quote->setDamageWaiverAmount(0); $depositAmt = ITwebexperts_Payperrentals_Helper_Price::getQuoteDamageWaiver($quote); if ($depositAmt > 0) { $exist_amount = $quote->getDamageWaiverAmount(); $fee = $depositAmt; $balance = $fee - $exist_amount; $address->setDamageWaiverAmount($balance); $address->setBaseDamageWaiverAmount($balance); $quote->setDamageWaiverAmount($balance); } else { $address->setDamageWaiverAmount(0); $address->setBaseDamageWaiverAmount(0); $quote->setDamageWaiverAmount(0); } return $this; }
public function getPriceList() { if ($this->getProduct()->getCanShowPrice()) { return ITwebexperts_Payperrentals_Helper_Price::getPriceListHtml($this->getProduct(), Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Data::XML_PATH_PRICING_ON_LISTING)); } else { return ''; } }
/** * Check price calculations * * @param string $expectation * @param int $product_id * @param datetime $start_date * @param datetime $end_date * @param int $qty * @param int $customerGroup * @test * @loadFixture * @loadExpectation * @dataProvider dataProvider */ public function priceCalculations($expectation, $product_id, $start_date, $end_date, $qty, $customerGroup) { //$customerSessionMock = $this->getModelMock('customer/session', array('renewSession')); // $this->replaceByMock('singleton', 'customer/session', $customerSessionMock); $product = Mage::getModel('catalog/product')->load($product_id); $iPriceCalculated = ITwebexperts_Payperrentals_Helper_Price::calculatePrice($product, $start_date, $end_date, $qty, $customerGroup); $iExpectedPrice = $this->expected($expectation)->getPrice(); //$this->_getExpectations()->getData($testNr . '/price') $this->assertEquals($iExpectedPrice, $iPriceCalculated); }
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=" ' . Mage::helper('payperrentals')->__('Rent') . ' " />'; } return $htmlOutput; }
public function getSelectionQtyTitlePrice($_selection, $includeContainer = true) { $price = $this->getProduct()->getPriceModel()->getSelectionPreFinalPrice($this->getProduct(), $_selection); $formattedPrice = $this->formatPriceString($price, $includeContainer); if ($_selection->getTypeId() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE) { if ($this->getProduct()->getBundlePricingtype() == ITwebexperts_Payperrentals_Model_Product_Bundlepricingtype::PRICING_BUNDLE_PERPRODUCT) { $formattedPrice = ITwebexperts_Payperrentals_Helper_Price::getPriceListHtml($_selection, -1, true); } else { $formattedPrice = ''; } } $this->setFormatProduct($_selection); $priceTitle = $_selection->getSelectionQty() * 1 . ' x ' . $this->escapeHtml($_selection->getName()); $priceTitle .= ' ' . ($includeContainer ? '<span class="price-notice">' : '') . '+' . $formattedPrice . ($includeContainer ? '</span>' : ''); return $priceTitle; }
/** * Render price for products * * @param Varien_Object $row * @return string */ public function render(Varien_Object $row) { $_data = $row->getData($this->getColumn()->getIndex()); $_priceHtml = false; if ($_data) { $_priceHtml = $_data; } elseif (is_null($_data)) { $_product = $row->load($row->getId()); if ($_product) { $_priceHtml = ITwebexperts_Payperrentals_Helper_Price::getPriceListHtml($_product, 2); } } if ($_priceHtml !== false) { return $_priceHtml; } else { return $this->getColumn()->getDefault(); } }
public function getPrice($product, $qty = null) { if (ITwebexperts_Payperrentals_Helper_Data::isReservationAndRental($product)) { $selectedAttributes = array(); $isBuyout = false; $configurableParent = null; if ($product->getCustomOption('attributes')) { $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue()); } if ($product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION)) { $from_date = $product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION)->getValue(); } if ($product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::END_DATE_OPTION)) { $to_date = $product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::END_DATE_OPTION)->getValue(); } if ($product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::BUYOUT_PRICE_OPTION)) { $isBuyout = $product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::BUYOUT_PRICE_OPTION)->getValue(); $configurableParent = $product; } if ($product->isConfigurable()) { $product = Mage::getModel('catalog/product_type_configurable')->getProductByAttributes($selectedAttributes, $product); if (is_object($product)) { $product = Mage::getModel('catalog/product')->load($product->getId()); } } $price = 0; if (is_null($qty) || $qty <= 0) { $qty = 1; } if (isset($from_date) && isset($to_date) && is_object($product)) { $customerGroup = $this->_getCustomerGroupId($product); $price = ITwebexperts_Payperrentals_Helper_Price::calculatePrice($product, $from_date, $to_date, $qty, $customerGroup); $product->setData('final_price', $price); } if ($isBuyout) { $priceTemp = ITwebexperts_Payperrentals_Helper_Price::getBuyoutPrice($product, $configurableParent); $product->setData('final_price', $priceTemp); $price = $priceTemp; } return $price; } else { return parent::getPrice($product, $qty); } }
/** * Check price calculations * * @param string $expectation * @param int $product_id * @param datetime $start_date * @param datetime $end_date * @param int $qty * @param int $customerGroup * @param string $bundleArr * @param string $bundleQty * @param string $bundleQty1 * @test * @loadFixture * @loadExpectation * @dataProvider dataProvider */ public function priceBundles($expectation, $product_id, $start_date, $end_date, $qty, $customerGroup, $bundleArr, $bundleQty, $bundleQty1) { $bundleOptions = array(1 => array(1, 90), 2 => array(3, 4)); //normally passed via dataProvider $oBundleType = Mage::getModel('catalog/product')->load($product_id)->getTypeInstance(); $cSelections = $oBundleType->getSelectionsCollection(array_keys($bundleOptions)); $bundleOptionBuyRequest = array(); foreach ($bundleOptions as $optionId => $selection) { $bundleOptionBuyRequest[$optionId] = $cSelections->getItemByColumnValue('product_id', $selection)->getSelectionId(); } $Product = Mage::getModel('catalog/product')->load($product_id); if ($Product->getBundlePricingtype() == ITwebexperts_Payperrentals_Model_Product_Bundlepricingtype::PRICING_BUNDLE_FORALL) { $iPriceCalculated = ITwebexperts_Payperrentals_Helper_Price::calculatePrice($Product, $start_date, $end_date, $qty, $customerGroup); $iExpectedPrice = $this->expected($expectation)->getPrice(); $this->assertEquals($iExpectedPrice, $iPriceCalculated); } else { eval('$bundle_option = ' . $bundleArr . ';'); eval('$bundle_option_qty = ' . $bundleQty . ';'); eval('$bundle_option_qty1 = ' . $bundleQty1 . ';'); $iPriceCalculated = ITwebexperts_Payperrentals_Helper_Price::getBundlePricing($Product, $bundle_option, $bundle_option_qty, $bundle_option_qty1, $qty, $start_date, $end_date, $customerGroup); $iExpectedPrice = $this->expected($expectation)->getPrice(); $this->assertEquals($iExpectedPrice, $iPriceCalculated); } }
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=" ' . Mage::helper('payperrentals')->__('Rent') . ' " />'; } 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=" ' . Mage::helper('payperrentals')->__('Rent') . ' " />'; } else { $htmlPrice .= '<input type="hidden" class="ppr_attr_butname" value=" ' . Mage::helper('payperrentals')->__('Rent') . ' " />'; } } 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; }
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(); }
/** * 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')); }
protected function _getDamageWaiverHtml($damageWaiver) { return ITwebexperts_Payperrentals_Helper_Price::getDamageWaiverHtml($this->getItem(), (bool) $this->getItem()->getBuyRequest()->getDamageWaiver(), false); }
public static function getAdminDamageWaiverHtml($item, $productId) { $html = '<div>'; $startDate = Mage::getSingleton('core/session')->getData('startDateInitial'); $endDate = Mage::getSingleton('core/session')->getData('endDateInitial'); $damageWaiverSelected = false; if (isset($item) && $item != -1 && Mage::app()->getRequest()->getActionName() != 'configureProductToAdd') { $buyRequest = $item->getBuyRequest(); if ($buyRequest->getDamageWaiver() != '' && $buyRequest->getDamageWaiver() == '1') { $damageWaiverSelected = true; } $_showTime = (bool) Mage::getResourceModel('catalog/product')->getAttributeRawValue($item->getProductId(), 'payperrentals_use_times', $item->getStoreId()); if (!Mage::helper('payperrentals/config')->isNonSequentialSelect(Mage::app()->getStore()->getId())) { $startDate = $buyRequest->getStartDate() != '' ? $buyRequest->getStartDate() : ($startDate ? $startDate : false); $endDate = $buyRequest->getEndDate() != '' ? $buyRequest->getEndDate() : ($endDate ? $endDate : false); } else { $startDate = $buyRequest->getStartDate() != '' ? ITwebexperts_Payperrentals_Helper_Date::localiseNonsequentialBuyRequest($buyRequest->getStartDate(), $_showTime) : ($startDate ? $startDate : false); $endDate = $buyRequest->getStartDate() != '' ? ITwebexperts_Payperrentals_Helper_Date::localiseNonsequentialBuyRequest($buyRequest->getStartDate(), $_showTime) : ($startDate ? $startDate : false); } } if ($startDate) { list($startDate, $endDate) = ITwebexperts_Payperrentals_Helper_Date::convertDatepickerToDbFormat($startDate, $endDate); $rentalPrice = ITwebexperts_Payperrentals_Helper_Price::calculatePrice($productId, $startDate, $endDate, 1, ITwebexperts_Payperrentals_Helper_Data::getCustomerGroup()); $damageWaiverPrice = self::getDamageWaiver($productId, $rentalPrice); } else { $damageWaiverPrice = self::getDamageWaiver($productId, 0); } if ($damageWaiverPrice) { $html .= '<input type="radio" name="damage_waiver" class="damage-waiver-input" id="damageWaiverNo" value="0" '; if (!$damageWaiverSelected) { $html .= 'checked="checked"'; } $html .= '/>'; $html .= '<label for="damageWaiverNo">' . Mage::helper('payperrentals')->__(' No') . '</label>'; $html .= '</div>'; $html .= '<div>'; $html .= '<input type="radio" name="damage_waiver" class="damage-waiver-input" id="damageWaiverYes" value="1" '; if ($damageWaiverSelected) { $html .= 'checked="checked"'; } $html .= '/>'; $html .= '<label for="damageWaiverYes">' . Mage::helper('payperrentals')->__(' Yes +%s', Mage::helper('checkout')->formatPrice($damageWaiverPrice > -1 ? $damageWaiverPrice : $item->getData(ITwebexperts_Payperrentals_Helper_Price::DAMAGE_WAIVER_OPTION_PRICE), true, true)) . '</label>'; $html .= '</div>'; } return $html; }
/** * 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; }
public function getPriceList() { return ITwebexperts_Payperrentals_Helper_Price::getPriceListHtml($this->getProduct(), Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_PRICING_ON_LISTING)); }
/** * Get bundled selections (slections-products collection) * * Returns array of options objects. * Each option object will contain array of selections objects * * @return array */ public function getBundleOptions(Mage_Catalog_Model_Product_Configuration_Item_Interface $item) { $options = array(); $product = $item->getProduct(); /** * @var Mage_Bundle_Model_Product_Type */ $typeInstance = $product->getTypeInstance(true); // get bundle options $optionsQuoteItemOption = $item->getOptionByCode('bundle_option_ids'); $bundleOptionsIds = $optionsQuoteItemOption ? unserialize($optionsQuoteItemOption->getValue()) : array(); if ($bundleOptionsIds) { /** * @var Mage_Bundle_Model_Mysql4_Option_Collection */ $optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $product); // get and add bundle selections collection $selectionsQuoteItemOption = $item->getOptionByCode('bundle_selection_ids'); $selectionsCollection = $typeInstance->getSelectionsByIds(unserialize($selectionsQuoteItemOption->getValue()), $product); $bundleOptions = $optionsCollection->appendSelections($selectionsCollection, true); foreach ($bundleOptions as $bundleOption) { if ($bundleOption->getSelections()) { $option = array('label' => $bundleOption->getTitle(), 'value' => array()); $bundleSelections = $bundleOption->getSelections(); foreach ($bundleSelections as $bundleSelection) { $qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1; if ($qty) { $val = $qty . ' x ' . $this->escapeHtml($bundleSelection->getName()) . ' '; if ($bundleSelection->getTypeId() == 'reservation') { if ($product->getBundlePricingtype() == ITwebexperts_Payperrentals_Model_Product_Bundlepricingtype::PRICING_BUNDLE_PERPRODUCT) { $customerGroup = ITwebexperts_Payperrentals_Helper_Data::getCustomerGroup(); if (!is_object($product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION))) { $source = unserialize($product->getCustomOption('info_buyRequest')->getValue()); if (isset($source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION])) { $start_date = $source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION]; $end_date = $source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::END_DATE_OPTION]; } } else { $start_date = $product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION)->getValue(); $end_date = $product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::END_DATE_OPTION)->getValue(); } $data = new Varien_Object(array('start_date' => $start_date, 'end_date' => $end_date)); Mage::dispatchEvent('payperrentals_bundle_option_calculate_price_before', array('data' => $data, 'item' => $item, 'selection' => $bundleSelection)); extract($data->getData(), EXTR_OVERWRITE); $priceAmount = ITwebexperts_Payperrentals_Helper_Price::calculatePrice($bundleSelection, $start_date, $end_date, $qty, $customerGroup); $val .= Mage::helper('core')->currency($priceAmount); } else { } } else { $val .= Mage::helper('core')->currency($this->getSelectionFinalPrice($item, $bundleSelection)); } $option['value'][] = $val; } } if ($option['value']) { $options[] = $option; } } } } return $options; }
/** * 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)); }