public function indexAction() { $orderId = $this->getRequest()->getParam('order_id'); $newDate = ITwebexperts_Payperrentals_Helper_Date::toMysqlDate($this->getRequest()->getParam('new_date'), true); /** @var $sourceOrder Mage_Sales_Model_Order */ $sourceOrder = Mage::getModel('sales/order')->load($orderId); $cart = Mage::getModel('checkout/cart'); $cart->init(); $cart->truncate(); $orderItems = $sourceOrder->getAllItems(); $configHelper = Mage::helper('payperrentals/config'); foreach ($orderItems as $item) { $timeIncrement = $configHelper->getTimeIncrement() * 60; if ($item->getParentItem()) { continue; } $originalEndDate = $item->getBuyRequest()->getEndDate(); //check timeIncrement and check if product has times enabled if (ITwebexperts_Payperrentals_Helper_Data::useTimes($item->getProduct()->getId()) == 0) { $timeIncrement = 24 * 60 * 60; } $originalEndDatePlusTimeIncrement = strtotime($originalEndDate) + $timeIncrement; $originalEndDatePlusTimeIncrement = date('Y-m-d H:i:s', $originalEndDatePlusTimeIncrement); $productOptions = $item->getProductOptions(); $buyRequestArray = $productOptions['info_buyRequest']; $buyRequestArray['start_date'] = $originalEndDatePlusTimeIncrement; $buyRequestArray['end_date'] = $newDate; $buyRequestArray['is_extended'] = true; if (count($item->getChildrenItems()) > 0) { foreach ($item->getChildrenItems() as $child) { $turnoverArr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($child->getProductId(), $child); $buyRequestArray['excluded_qty'][] = array('product_id' => $child->getProductId(), 'start_date' => $turnoverArr['before'], 'end_date' => $turnoverArr['after'], 'qty' => $productOptions['info_buyRequest']['qty']); } } else { $turnoverArr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($item->getProductId(), $item); $buyRequestArray['excluded_qty'][] = array('product_id' => $item->getProductId(), 'start_date' => $turnoverArr['before'], 'end_date' => $turnoverArr['after'], 'qty' => $productOptions['info_buyRequest']['qty']); } $buyRequest = new Varien_Object($buyRequestArray); $product = Mage::getModel('catalog/product')->load($item->getProductId()); try { $cart->addProduct($product, $buyRequest); } catch (Exception $e) { Mage::getSingleton('core/session')->addError($e->getMessage()); } } $cart->save(); Mage::getSingleton('checkout/session')->setIsExtendedQuote(true); Mage::getSingleton('checkout/session')->setCartWasUpdated(true); $this->_redirect('checkout/cart'); }
/** * Function used to return the booked object in the required format check phpdoc on getAllBookedQtyForProduct * * @param $reservedCollection * @param $isOrder * @param null $booked * * @return array|null */ private static function getBooked($reservedCollection, $isOrder, $booked = null) { if (is_null($booked)) { $booked = array(); } $configHelper = Mage::helper('payperrentals/config'); foreach ($reservedCollection as $iReserved) { $start = strtotime($iReserved->getStartTurnoverBefore()); $end = strtotime($iReserved->getEndTurnoverAfter()); if (Mage::helper('payperrentals/config')->useReserveInventoryDropoffPickup()) { if ($iReserved->getDropoff()) { $start = strtotime($iReserved->getDropoff()); } if ($iReserved->getPickup()) { $end = strtotime($iReserved->getPickup()); } } if (Mage::helper('payperrentals/config')->useReserveInventorySendReturn()) { $sendReturnCollection = Mage::getModel('payperrentals/sendreturn')->getCollection(); $sendReturnCollection->addSelectFilter("resorder_id=" . $iReserved->getId()); $sendReturnCollection->addSelectFilter("return_date <= '" . ITwebexperts_Payperrentals_Helper_Date::toDbDate($end, true) . "' AND return_date <> '0000-00-00 00:00:00'"); $sendReturnCollection->getSelect()->order('main_table.return_date DESC'); } //a required option for bundle products is to have prices defined when times is enabled. //So use times and prices should be defined for all components of bundle products. $useTimes = ITwebexperts_Payperrentals_Helper_Data::useTimes($iReserved->getProductId()) == 2; if ($useTimes && (date('H:i:s', $start) != '00:00:00' || date('H:i:s', $end) != '23:59:00' && date('H:i:s', $end) != '23:58:59')) { $timeIncrement = $configHelper->getTimeIncrement() * 60; } else { $timeIncrement = 3600 * 24; } $returnsArray = array(); if (isset($sendReturnCollection)) { foreach ($sendReturnCollection as $sendReturnItem) { if ($timeIncrement !== 3600 * 24) { $dateReturn = date('Y-m-d H:i', strtotime($sendReturnItem->getReturnDate())); } else { $dateReturn = date('Y-m-d', strtotime($sendReturnItem->getReturnDate())) . ' 00:00'; } if (strtotime($dateReturn) < $start) { $dateReturn = date('Y-m-d', $start) . ' 00:00'; } if (!isset($returnsArray[$sendReturnItem->getProductId()][$dateReturn])) { $returnsArray[$sendReturnItem->getProductId()][$dateReturn] = $sendReturnItem->getQty(); } else { $returnsArray[$sendReturnItem->getProductId()][$dateReturn] += $sendReturnItem->getQty(); } } } $qtyReturnedArray = array(); while ($start < $end) { if ($timeIncrement !== 3600 * 24) { $dateFormatted = date('Y-m-d H:i', $start); } else { $dateFormatted = date('Y-m-d', $start) . ' 00:00'; } if (!isset($qtyReturnedArray[$iReserved->getProductId()])) { $qtyReturnedArray[$iReserved->getProductId()] = 0; } if (isset($returnsArray[$iReserved->getProductId()]) && array_key_exists($dateFormatted, $returnsArray[$iReserved->getProductId()]) !== false) { $qtyReturnedArray[$iReserved->getProductId()] = $returnsArray[$sendReturnItem->getProductId()][$dateFormatted]; } if (!isset($booked[$iReserved->getProductId()][$dateFormatted])) { $vObject = new Varien_Object(); $vObject->setQty($iReserved->getQty() - $qtyReturnedArray[$iReserved->getProductId()]); if ($isOrder) { $vObject->setOrders(array($iReserved->getOrderId())); } $booked[$iReserved->getProductId()][$dateFormatted] = $vObject; } else { $vObject = $booked[$iReserved->getProductId()][$dateFormatted]; $vObject->setQty($vObject->getQty() + $iReserved->getQty() - $qtyReturnedArray[$iReserved->getProductId()]); if ($isOrder) { $orderArr = $vObject->getOrders(); $orderArr = array_merge($orderArr, array($iReserved->getOrderId())); array_unique($orderArr); $vObject->setOrders($orderArr); } $booked[$iReserved->getProductId()][$dateFormatted] = $vObject; } $start += $timeIncrement; } } /** * Event used to complete the booked object with specific dates. Needed in case of maintenance module */ $resultObject = new Varien_Object(); $resultObject->setBooked($booked); Mage::dispatchEvent('after_booked', array('result' => $resultObject, 'reserved_collection' => $reservedCollection, 'is_order' => $isOrder)); return $resultObject->getBooked(); }
public function indexAction() { $orderId = $this->getRequest()->getParam('order_id'); $newDate = ITwebexperts_Payperrentals_Helper_Date::toMysqlDate($this->getRequest()->getParam('new_date'), true); /** @var $sourceOrder Mage_Sales_Model_Order */ $sourceOrder = Mage::getModel('sales/order')->load($orderId); /** @var Mage_Adminhtml_Model_Session_Quote $orderSession */ $orderSession = Mage::getSingleton('adminhtml/session_quote'); $orderSession->clear(); $customer = Mage::getModel('customer/customer')->load($sourceOrder->getCustomerId()); $orderSession->setCustomer($customer); $orderSession->setCustomerId($sourceOrder->getCustomerId()); $orderSession->setStoreId($sourceOrder->getStoreId()); //$orderSession->setQuoteId($quote->getId()); /** @var $quote Mage_Sales_Model_Quote */ $quote = $orderSession->getQuote(); /** @var $converterOrder Mage_Sales_Model_Convert_Order */ $converterOrder = Mage::getModel('sales/convert_order'); $orderShippingAddress = $converterOrder->addressToQuoteAddress($sourceOrder->getShippingAddress()); $orderBillingAddress = $converterOrder->addressToQuoteAddress($sourceOrder->getBillingAddress()); // $orderPayment = $converterOrder->paymentToQuotePayment($sourceOrder->getPayment()); $quote->setShippingAddress($orderShippingAddress); $quote->setBillingAddress($orderBillingAddress); //$quote->setPayment($orderPayment); $orderItems = $sourceOrder->getAllItems(); $configHelper = Mage::helper('payperrentals/config'); foreach ($orderItems as $item) { $timeIncrement = $configHelper->getTimeIncrement() * 60; if ($item->getParentItem()) { continue; } $originalEndDate = $item->getBuyRequest()->getEndDate(); //check timeIncrement and check if product has times enabled if (ITwebexperts_Payperrentals_Helper_Data::useTimes($item->getProduct()->getId()) == 0) { $timeIncrement = 24 * 60 * 60; } $originalEndDatePlusTimeIncrement = strtotime($originalEndDate) + $timeIncrement; $originalEndDatePlusTimeIncrement = date('Y-m-d H:i:s', $originalEndDatePlusTimeIncrement); $productOptions = $item->getProductOptions(); $buyRequestArray = $productOptions['info_buyRequest']; $buyRequestArray['start_date'] = $originalEndDatePlusTimeIncrement; $buyRequestArray['end_date'] = $newDate; $buyRequestArray['is_extended'] = true; if (count($item->getChildrenItems()) > 0) { foreach ($item->getChildrenItems() as $child) { $turnoverArr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($child->getProductId(), $child); $buyRequestArray['excluded_qty'][] = array('product_id' => $child->getProductId(), 'start_date' => $turnoverArr['before'], 'end_date' => $turnoverArr['after'], 'qty' => $productOptions['info_buyRequest']['qty']); } } else { $turnoverArr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($item->getProductId(), $item); $buyRequestArray['excluded_qty'][] = array('product_id' => $item->getProductId(), 'start_date' => $turnoverArr['before'], 'end_date' => $turnoverArr['after'], 'qty' => $productOptions['info_buyRequest']['qty']); } $buyRequest = new Varien_Object($buyRequestArray); $product = Mage::getModel('catalog/product')->load($item->getProductId()); $itemNew = $quote->addProduct($product, $buyRequest); $itemNew->calcRowTotal(); $quote->collectTotals(); } $quote->save(); $orderSession->setIsExtendedQuote(true); $this->_redirect('adminhtml/sales_order_create/index'); }
public function indexAction() { $orderid = $this->getRequest()->getParam('orderid'); if ($this->getRequest()->getParam('late_date')) { $lateReturnDate = ITwebexperts_Payperrentals_Helper_Date::toMysqlDate($this->getRequest()->getParam('late_date'), true); } else { $lateReturnDate = date('Y-m-d H:i:s'); } //if($this->getRequest()->getParam('custom_price') && $this->getRequest()->getParam('custom_price') != '') { // $customPrice = $this->getRequest()->getParam('custom_price'); //} /** @var $sourceOrder Mage_Sales_Model_Order */ $sourceOrder = Mage::getModel('sales/order')->load($orderid); /** @var Mage_Adminhtml_Model_Session_Quote $orderSession */ $orderSession = Mage::getSingleton('adminhtml/session_quote'); $orderSession->clear(); $customer = Mage::getModel('customer/customer')->load($sourceOrder->getCustomerId()); $orderSession->setCustomer($customer); $orderSession->setCustomerId($sourceOrder->getCustomerId()); $orderSession->setStoreId($sourceOrder->getStoreId()); //$orderSession->setQuoteId($quote->getId()); /** @var $quote Mage_Sales_Model_Quote */ $quote = $orderSession->getQuote(); /** @var $converterOrder Mage_Sales_Model_Convert_Order */ $converterOrder = Mage::getModel('sales/convert_order'); /** @var $quote Mage_Sales_Model_Quote */ //$quoteNew = $converterOrder->toQuote($sourceOrder); $orderShippingAddress = $converterOrder->addressToQuoteAddress($sourceOrder->getShippingAddress()); $orderBillingAddress = $converterOrder->addressToQuoteAddress($sourceOrder->getBillingAddress()); //$orderPayment = $converterOrder->paymentToQuotePayment($sourceOrder->getPayment()); $quote->setShippingAddress($orderShippingAddress); $quote->setBillingAddress($orderBillingAddress); //$quote->setPayment($orderPayment); $orderItems = $sourceOrder->getAllItems(); $configHelper = Mage::helper('payperrentals/config'); foreach ($orderItems as $item) { $timeIncrement = $configHelper->getTimeIncrement() * 60; if ($item->getParentItem()) { continue; } $originalEndDate = $item->getBuyRequest()->getEndDate(); if (strtotime($originalEndDate) > strtotime($lateReturnDate)) { continue; } //check timeIncrement and check if product has times enabled $useTimes = ITwebexperts_Payperrentals_Helper_Data::useTimes($item->getProduct()->getId()); if ($useTimes == 0) { $timeIncrement = 24 * 60 * 60; } $originalEndDatePlusTimeIncrement = strtotime($originalEndDate) + $timeIncrement; $originalEndDatePlusTimeIncrement = date('Y-m-d H:i:s', $originalEndDatePlusTimeIncrement); $productOptions = $item->getProductOptions(); $buyRequestArray = $productOptions['info_buyRequest']; $buyRequestArray['start_date'] = $originalEndDatePlusTimeIncrement; $buyRequestArray['end_date'] = $useTimes == 0 ? date('Y-m-d', strtotime($lateReturnDate)) . ' 00:00:00' : $lateReturnDate; $buyRequestArray['is_extended'] = true; if (!isset($customPrice)) { $lateFee = ITwebexperts_Payperrentals_Helper_LateFeesandReturns::calculateLateFee($item->getProduct(), $item->getQtyOrdered(), $item->getBuyRequest()->getStartDate(), $originalEndDate, $lateReturnDate, $buyRequestArray); } else { $lateFee = $customPrice; } $buyRequest = new Varien_Object(); $buyRequest->setData($buyRequestArray); $product = Mage::getModel('catalog/product')->load($item->getProductId()); $additionalOptions[] = array('label' => 'Type', 'value' => 'Late Fee'); $product->addCustomOption('additional_options', serialize($additionalOptions)); $itemNew = $quote->addProduct($product, $buyRequest); //$itemNew = $quote->getItembyProduct($product); $itemNew->setCustomPrice($lateFee); $itemNew->calcRowTotal(); $quote->collectTotals(); } $quote->save(); $orderSession->setIsExtendedQuote(true); $this->_redirect('adminhtml/sales_order_create/index'); }