public function updateAction()
 {
     $params = ITwebexperts_Payperrentals_Helper_Date::filterDates($this->getRequest()->getParams());
     $startDate = array_key_exists('start_date', $params) ? $params['start_date'] : null;
     $endDate = array_key_exists('end_date', $params) ? $params['end_date'] : null;
     if ($startDate && $endDate) {
         $checkoutSession = Mage::getSingleton('checkout/session');
         try {
             ITwebexperts_Payperrentals_Helper_Data::updateCurrentGlobalDates($startDate, $endDate);
             $checkoutSession->addSuccess($this->__('Global Date was updated'));
         } catch (Mage_Core_Exception $e) {
             if ($checkoutSession->getUseNotice(true)) {
                 $checkoutSession->addNotice(Mage::helper('core')->escapeHtml($e->getMessage()));
             } else {
                 $messages = array_unique(explode("\n", $e->getMessage()));
                 foreach ($messages as $message) {
                     $checkoutSession->addError(Mage::helper('core')->escapeHtml($message));
                 }
             }
         } catch (Exception $e) {
             $checkoutSession->addException($e, $this->__('Cannot add the item to shopping cart.'));
             Mage::logException($e);
         }
     }
     $this->_redirect('checkout/cart');
 }
Exemplo n.º 2
0
 /**
  * Draw item line
  */
 public function draw()
 {
     $order = $this->getOrder();
     $item = $this->getItem();
     $pdf = $this->getPdf();
     $page = $this->getPage();
     $lines = array();
     // draw Product name
     $name = array();
     $name[] = $item->getName();
     //get order and check if it has items with different dates
     $isSingle = ITwebexperts_Payperrentals_Helper_Data::isSingleOrder($order);
     if ($options = $item->getOrderItem()->getProductOptions()) {
         //$startDateLabel = $this->getItem()->getIsVirtual() ? $this->__("Subscription start:") : $this->__("First delivery:");
         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];
             }
             if (!$isSingle['bool']) {
                 if (isset($start_date)) {
                     $name[] = 'Start date: ' . $start_date;
                 }
                 if (isset($end_date)) {
                     $name[] = 'End date: ' . $end_date;
                 }
             }
         }
     }
     foreach ($name as $j1 => $namen) {
         if ($order->getIsSingle() == 0 && $j1 > 0) {
             $lines[$j1] = array(array('text' => Mage::helper('core/string')->str_split($namen, 60, true, true), 'feed' => 100));
         } elseif ($j1 == 0) {
             $lines[$j1] = array(array('text' => Mage::helper('core/string')->str_split($namen . ($order->getIsSingle() == 1 ? '(reservation)' : ''), 60, true, true), 'feed' => 100));
         }
     }
     // draw QTY
     $lines[0][] = array('text' => $item->getQty() * 1, 'feed' => 35);
     // draw SKU
     $lines[0][] = array('text' => Mage::helper('core/string')->str_split($this->getSku($item), 25), 'feed' => 565, 'align' => 'right');
     // Custom options
     $options = $this->getItemOptions();
     if ($options) {
         foreach ($options as $option) {
             // draw options label
             $lines[][] = array('text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 70, true, true), 'font' => 'italic', 'feed' => 110);
             // draw options value
             if ($option['value']) {
                 $_printValue = isset($option['print_value']) ? $option['print_value'] : strip_tags($option['value']);
                 $values = explode(', ', $_printValue);
                 foreach ($values as $value) {
                     $lines[][] = array('text' => Mage::helper('core/string')->str_split($value, 50, true, true), 'feed' => 115);
                 }
             }
         }
     }
     $lineBlock = array('lines' => $lines, 'height' => 20);
     $page = $pdf->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
     $this->setPage($page);
 }
Exemplo n.º 3
0
 /**
  * Renders grid column
  *
  * @param   Varien_Object $row
  * @return  string
  */
 public function render(Varien_Object $_row)
 {
     if (ITwebexperts_Payperrentals_Helper_Data::isReservationType($_row->getId())) {
         $data = intval(ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($_row->getId(), 'payperrentals_quantity'));
     } else {
         $data = intval($_row->getQty());
     }
     return $data;
 }
Exemplo n.º 4
0
 public function isVirtual($product = null)
 {
     $hasShipping = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($this->getProduct($product)->getId(), 'payperrentals_has_shipping');
     $isReservation = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($this->getProduct($product)->getId(), 'is_reservation');
     if ($isReservation != ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_DISABLED && $isReservation != ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_NOTSET) {
         return Mage::helper('payperrentals/config')->removeShipping() || $hasShipping == ITwebexperts_Payperrentals_Model_Product_Hasshipping::STATUS_DISABLED;
     } else {
         return parent::isVirtual($product);
     }
 }
Exemplo n.º 5
0
 /**
  * @param $orderId
  */
 protected function _reserveOrdersById($orderId)
 {
     $order = Mage::getModel('sales/order')->load($orderId, 'entity_id');
     $iStatus = Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_RESERVATION_STATUS);
     if (Mage::helper('payperrentals/config')->reserveByStatus() && $order->getStatus() != $iStatus) {
         ITwebexperts_Payperrentals_Helper_Data::reserveOrder($order->getItemsCollection(), $order);
         $order->setStatus($iStatus);
         $order->save();
     }
 }
Exemplo n.º 6
0
 /**
  * Renders grid column
  *
  * @param   Varien_Object $row
  * @return  string
  */
 public function render(Varien_Object $_row)
 {
     if (ITwebexperts_Payperrentals_Helper_Data::isReservationType($_row->getId())) {
         $dates = Mage::helper('payperrentals/timebox')->getProductGridDates();
         $data = intval(ITwebexperts_Payperrentals_Helper_Inventory::getQuantity($_row->getId(), $dates['start_date'], $dates['end_date']));
     } else {
         $data = 0;
     }
     return $data;
 }
Exemplo n.º 7
0
 /**
  * Render minimal price for downloadable products
  *
  * @param   Varien_Object $row
  * @return  string
  */
 public function render(Varien_Object $row)
 {
     $_product = Mage::getModel('catalog/product')->load($row->getData($this->getColumn()->getIndex()));
     $qtyStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
     if (ITwebexperts_Payperrentals_Helper_Data::isReservationType($_product)) {
         $html = '<span class="currentstock">' . Mage::helper('payperrentals')->__('') . '</span>';
     } else {
         $html = '<span class="currentstock">' . intval($qtyStock) . '</span>';
     }
     $html .= '<script type="text/javascript">if (typeof(onLoadActions) == "function") onLoadActions();</script>';
     return $html;
 }
Exemplo n.º 8
0
 /**
  * Convert block to html string
  *
  * @return string
  */
 protected function _toHtml()
 {
     if (Mage::registry('current_product') == $this->getProduct()) {
         return '<div class="pricingppr">' . $this->getPriceBundle() . '</div>' . parent::_toHtml();
     } else {
         $product = $this->getProduct();
         $_isReservation = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($product->getId(), 'is_reservation');
         if ($_isReservation != ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_DISABLED && $_isReservation !== false) {
             $priceHtml = $this->getLayout()->createBlock("payperrentals/bundle_catalog_product_price")->setTemplate('payperrentals/bundle/catalog/product/priceppr.phtml')->setProduct($product)->setPriceElementIdPrefix('bundle-price-')->setIdSuffix($this->getIdSuffix())->toHtml();
             return $priceHtml;
         }
         return parent::_toHtml();
     }
 }
Exemplo n.º 9
0
 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');
 }
Exemplo n.º 10
0
 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="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . Mage::helper('payperrentals')->__('Rent') . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" />';
     }
     return $htmlOutput;
 }
Exemplo n.º 11
0
 /**
  * Convert block to html string
  *
  * @return string
  */
 protected function _toHtml()
 {
     $product = $this->getProduct();
     $isReservation = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($product->getId(), 'is_reservation');
     $typeId = $product->getTypeId();
     if ($this->getTemplate() == $this->getTierPriceTemplate()) {
         return parent::_toHtml();
     }
     if ($typeId == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE || $isReservation != ITwebexperts_Payperrentals_Model_Product_Isreservation::STATUS_DISABLED && $isReservation !== false) {
         $priceHtml = $this->getLayout()->createBlock("payperrentals/catalog_product_price")->setTemplate('payperrentals/catalog/product/priceppr.phtml')->setProduct($product)->setDisplayMinimalPrice($this->getDisplayMinimalPrice())->setIdSuffix($this->getIdSuffix());
         $priceHtml = $priceHtml->toHtml();
         return $priceHtml;
     }
     return parent::_toHtml();
 }
Exemplo n.º 12
0
 public function getOptionsPrice($product, $price)
 {
     if (ITwebexperts_Payperrentals_Helper_Data::isReservationAndRental($product)) {
         $optprice = 0;
         if ($optionIds = $product->getCustomOption('option_ids')) {
             $basePrice = $price;
             foreach (explode(',', $optionIds->getValue()) as $optionId) {
                 if ($option = $product->getOptionById($optionId)) {
                     $quoteItemOption = $product->getCustomOption('option_' . $option->getId());
                     $group = $option->groupFactory($option->getType())->setOption($option)->setQuoteItemOption($quoteItemOption);
                     $optprice += $group->getOptionPrice($quoteItemOption->getValue(), $basePrice);
                 }
             }
         }
         return $optprice;
     } else {
         return parent::getOptionsPrice($product, $price);
     }
 }
Exemplo n.º 13
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     parent::collect($address);
     $address->setDepositpprAmount(0);
     $address->setBaseDepositpprAmount(0);
     $items = $this->_getAddressItems($address);
     if (!count($items)) {
         return $this;
         //this makes only address type shipping to come through
     }
     $quote = $address->getQuote();
     $quote->setDepositpprAmount(0);
     $depositAmt = ITwebexperts_Payperrentals_Helper_Data::getDeposit($quote);
     if ($depositAmt > 0) {
         $address->setDepositpprAmount($depositAmt);
         $address->setBaseDepositpprAmount($depositAmt);
         $quote->setDepositpprAmount($depositAmt);
         if (Mage::helper('payperrentals/config')->isChargedDeposit()) {
             $address->setGrandTotal($address->getGrandTotal() + $address->getDepositpprAmount());
             $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseDepositpprAmount());
         }
     }
     return $this;
 }
Exemplo n.º 14
0
 /**
  * Checks if membership sku is allowed to rent the product
  *
  * @param $product
  */
 public function membershipAllowsProduct($productId, $membershipSku)
 {
     $_resExcludedMembership = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($productId, 'res_excluded_membership');
     $disabledMemberships = explode(',', $_resExcludedMembership);
     if (!in_array($membershipSku, $disabledMemberships)) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 15
0
 /**
  * Check padding days
  *
  * @param string $_testId
  * @param int $product_id
  * @param int $timestamp
  * @test
  * @loadFixture
  * @loadExpectation
  * @dataProvider dataProvider
  */
 public function checkPaddingDays($_testId, $product_id, $timestamp)
 {
     $product = Mage::getModel('catalog/product')->load($product_id);
     $_expected = $this->expected('testId' . $_testId);
     $paddingDays = ITwebexperts_Payperrentals_Helper_Data::getProductPaddingDays($product, $timestamp);
     if (empty($paddingDays)) {
         $this->assertEquals($_expected->getValues(), '');
     } else {
         $this->assertCount(count($_expected->getValues()), $paddingDays);
         foreach ($_expected->getValues() as $value) {
             $this->assertContains('"' . $value . '"', $paddingDays);
         }
     }
 }
Exemplo n.º 16
0
 /**
  * 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;
 }
Exemplo n.º 17
0
 public function getExtendPopupAction()
 {
     if (!$this->getRequest()->getParam('order_id')) {
         return;
     }
     $order = Mage::getModel('sales/order')->load($this->getRequest()->getParam('order_id'));
     $orderDatesArr = ITwebexperts_Payperrentals_Helper_Data::isSingleOrder($order);
     $html = ITwebexperts_Payperrentals_Helper_Extend::getExtendHtml($this->getRequest()->getParam('order_id'));
     $jsonReturn = array('content' => $html, 'minDate' => date('r', strtotime('+1 day', strtotime($orderDatesArr['end_date']))));
     $this->getResponse()->setBody(Zend_Json::encode($jsonReturn));
 }
Exemplo n.º 18
0
 /**
  * Checks if newly added product to cart uses same start and end dates as the other products
  *
  * @param Varien_Event_Observer $_observer
  */
 public function sameDatesAllProducts(Varien_Event_Observer $observer)
 {
     $helper = Mage::helper('payperrentals');
     if (!ITwebexperts_Payperrentals_Helper_Data::isUsingGlobalDatesShoppingCart() && Mage::getStoreConfig('payperrentals/calendar_options/enforce_same_dates') == 1) {
         if ($observer->getEvent()->getQuote()) {
             $quote = $observer->getEvent()->getQuote();
         } else {
             $quote = Mage::getSingleton('checkout/session')->getQuote();
         }
         $quoteItems = $quote->getAllItems();
         $firstQuoteItem = false;
         foreach ($quoteItems as $quoteItem) {
             if ($quoteItem->getParentItem()) {
                 continue;
             }
             $options = $quoteItem->getOptionsByCode();
             $buyRequest = $options['info_buyRequest'];
             if (Mage::getSingleton('checkout/session')->getIsExtendedQuote() && !isset($buyRequest['is_extended'])) {
                 Mage::getSingleton('checkout/session')->addError($helper->__('This is an extended order you cannot add other items!'));
                 Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
                 Mage::app()->getResponse()->sendResponse();
                 exit;
             }
             $buyRequest = $quoteItem->getBuyRequest();
             if ($buyRequest->getStartDate() && $buyRequest->getEndDate()) {
                 if (!$firstQuoteItem) {
                     $startdatetime = new DateTime($buyRequest->getStartDate());
                     $startFormatted = $startdatetime->format('Y-m-d H:i:s');
                     $enddatetime = new DateTime($buyRequest->getEndDate());
                     $endFormatted = $enddatetime->format('Y-m-d H:i:s');
                     $counter = 0;
                     foreach ($quoteItems as $quoteItemNew) {
                         if ($quoteItemNew->getParentItem()) {
                             continue;
                         }
                         $buyRequestNew = $quoteItemNew->getBuyRequest();
                         if ($buyRequestNew->getStartDate() && $buyRequestNew->getEndDate()) {
                             if ($counter > 0) {
                                 $startdatetimeNew = new DateTime($buyRequestNew->getStartDate());
                                 $startFormattedNew = $startdatetimeNew->format('Y-m-d H:i:s');
                                 $enddatetimeNew = new DateTime($buyRequestNew->getEndDate());
                                 $endFormattedNew = $enddatetimeNew->format('Y-m-d H:i:s');
                                 if ($startFormatted != $startFormattedNew || $endFormatted != $endFormattedNew) {
                                     Mage::getSingleton('checkout/session')->addError($helper->__('All products must use the same start and end dates'));
                                     Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
                                     Mage::app()->getResponse()->sendResponse();
                                     exit;
                                 }
                             }
                             $counter++;
                         }
                     }
                 }
             }
             break;
         }
     }
 }
Exemplo n.º 19
0
 /**
  * @param ITwebexperts_Payperrentals_Model_Reservationorders $reservationOrder
  * @param array $serialNumbers
  * @param array $orderItems
  * @param int $reservationId
  *
  * @return array
  */
 private function getAllTheSerialNumbersForOrder($reservationOrder, $serialNumbers, $orderItems, $reservationId, $shipQty)
 {
     /** @var $payperrentalsUseSerials bool */
     $payperrentalsUseSerials = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($reservationOrder->getProductId(), 'payperrentals_use_serials');
     /** @var array $serialNumbersForOrderItems */
     $serialNumbersForOrderItems = array();
     /**
      * Get a list of manually entered serial numbers in the shipment form
      */
     if ($payperrentalsUseSerials) {
         foreach ($serialNumbers as $salesOrderItemId => $serialArr) {
             if ($salesOrderItemId == $orderItems[$reservationId]) {
                 foreach ($serialArr as $enteredSerial) {
                     if ($enteredSerial != '') {
                         if (!in_array($enteredSerial, $serialNumbersForOrderItems)) {
                             $serialNumbersForOrderItems[] = $enteredSerial;
                         }
                     }
                 }
             }
         }
         /*
          * Completes the array of entered serial numbers with non broken and not under maintenance serial numbers
          * */
         if (count($serialNumbersForOrderItems) < $shipQty) {
             $collectionSerials = Mage::getModel('payperrentals/serialnumbers')->getCollection()->addEntityIdFilter($reservationOrder->getProductId())->addSelectFilter("NOT FIND_IN_SET(sn, '" . implode(',', $serialNumbersForOrderItems) . "') AND (status = 'A')");
             $j = 0;
             foreach ($collectionSerials as $item) {
                 /** @var $item ITwebexperts_Payperrentals_Model_Serialnumbers */
                 if (!in_array($item->getSn(), $serialNumbersForOrderItems)) {
                     $serialNumbersForOrderItems[] = $item->getSn();
                     if ($j >= $shipQty - count($serialNumbersForOrderItems)) {
                         break;
                     }
                     $j++;
                 }
             }
         }
         $this->updateSerialNumbersStatus($serialNumbersForOrderItems);
     }
     return $serialNumbersForOrderItems;
 }
Exemplo n.º 20
0
 public function isVirtual($product = null)
 {
     $hasShipping = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($this->getProduct($product)->getId(), 'payperrentals_has_shipping');
     return Mage::helper('payperrentals/config')->removeShipping() || $hasShipping == ITwebexperts_Payperrentals_Model_Product_Hasshipping::STATUS_DISABLED;
 }
Exemplo n.º 21
0
 /**
  * Draw item line
  */
 public function draw()
 {
     $order = $this->getOrder();
     $item = $this->getItem();
     $pdf = $this->getPdf();
     $page = $this->getPage();
     $lines = array();
     // draw Product name
     $name = array();
     $name[] = $item->getName();
     //get order and check if it has items with different dates
     $isSingle = ITwebexperts_Payperrentals_Helper_Data::isSingleOrder($order);
     if ($options = $item->getOrderItem()->getProductOptions()) {
         //$startDateLabel = $this->getItem()->getIsVirtual() ? $this->__("Subscription start:") : $this->__("First delivery:");
         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];
             }
             if (!$isSingle['bool']) {
                 if (isset($start_date)) {
                     $name[] = 'Start date: ' . $start_date;
                 }
                 if (isset($end_date)) {
                     $name[] = 'End date: ' . $end_date;
                 }
             }
         }
     }
     foreach ($name as $j1 => $namen) {
         if ($order->getIsSingle() == 0 && $j1 > 0) {
             $lines[$j1] = array(array('text' => Mage::helper('core/string')->str_split($namen, 35, true, true), 'feed' => 35));
         } elseif ($j1 == 0) {
             $lines[$j1] = array(array('text' => Mage::helper('core/string')->str_split($namen . ($order->getIsSingle() == 1 ? '(reservation)' : ''), 35, true, true), 'feed' => 35));
         }
     }
     // draw SKU
     $lines[0][] = array('text' => Mage::helper('core/string')->str_split($this->getSku($item), 17), 'feed' => 290, 'align' => 'right');
     // draw QTY
     $lines[0][] = array('text' => $item->getQty() * 1, 'feed' => 435, 'align' => 'right');
     // draw item Prices
     $i = 0;
     $prices = $this->getItemPricesForDisplay();
     $feedPrice = 395;
     $feedSubtotal = $feedPrice + 170;
     foreach ($prices as $priceData) {
         if (isset($priceData['label'])) {
             // draw Price label
             $lines[$i][] = array('text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right');
             // draw Subtotal label
             $lines[$i][] = array('text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right');
             $i++;
         }
         // draw Price
         $lines[$i][] = array('text' => $priceData['price'], 'feed' => $feedPrice, 'font' => 'bold', 'align' => 'right');
         // draw Subtotal
         $lines[$i][] = array('text' => $priceData['subtotal'], 'feed' => $feedSubtotal, 'font' => 'bold', 'align' => 'right');
         $i++;
     }
     // draw Tax
     $lines[0][] = array('text' => $order->formatPriceTxt($item->getTaxAmount()), 'feed' => 495, 'font' => 'bold', 'align' => 'right');
     // custom options
     $options = $this->getItemOptions();
     if ($options) {
         foreach ($options as $option) {
             // draw options label
             $lines[][] = array('text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 40, true, true), 'font' => 'italic', 'feed' => 35);
             if ($option['value']) {
                 if (isset($option['print_value'])) {
                     $_printValue = $option['print_value'];
                 } else {
                     $_printValue = strip_tags($option['value']);
                 }
                 $values = explode(', ', $_printValue);
                 foreach ($values as $value) {
                     $lines[][] = array('text' => Mage::helper('core/string')->str_split($value, 30, true, true), 'feed' => 40);
                 }
             }
         }
     }
     $lineBlock = array('lines' => $lines, 'height' => 20);
     $page = $pdf->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
     $this->setPage($page);
 }
Exemplo n.º 22
0
 /**
  * override for changing the current stock qty based on the quote_item
  * (this is a bad design from Magento, checkQuoteItemQty should receive the quoteItem in the original code too)
  *
  * @param mixed $qty
  * @param mixed $summaryQty
  * @param int $origQty
  * @param Mage_Sales_Model_Quote_Item $quoteItem
  *
  * @return Varien_Object
  */
 public function checkQuoteItemQty($qty, $summaryQty, $origQty = 0, $quoteItem = null, $product = null)
 {
     if ($quoteItem && ITwebexperts_Payperrentals_Helper_Data::isReservationOnly($product) && (!$quoteItem->getChildren() || Mage::app()->getStore()->isAdmin())) {
         $qtyOption = 1;
         if ($quoteItem->getParentProductQty()) {
             $qty = $quoteItem->getParentProductQty();
             $qtyOption = $quoteItem->getParentProductQtyOption();
         }
         $quoteItemId = $quoteItem->getId();
         if ($quoteItem->getParentItem() && $quoteItem->getParentItem()->getProduct()) {
             if ($quoteItem->getParentItem()->getProduct()->getTypeId() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_BUNDLE) {
                 $quoteItemId = $quoteItem->getParentItem()->getItemId();
             }
         }
         $turnoverArr = ITwebexperts_Payperrentals_Helper_Data::getTurnoverFromQuoteItemOrBuyRequest($product, $quoteItem);
         list($startDate, $endDate) = array($turnoverArr['before'], $turnoverArr['after']);
         $result = new Varien_Object();
         $result->setHasError(false);
         if (!is_numeric($qty)) {
             $qty = Mage::app()->getLocale()->getNumber($qty);
         }
         /**
          * Check quantity type
          */
         $result->setItemIsQtyDecimal($this->getIsQtyDecimal());
         if (!$this->getIsQtyDecimal()) {
             $result->setHasQtyOptionUpdate(true);
             $qty = intval($qty);
             /**
              * Adding stock data to quote item
              */
             $result->setItemQty($qty);
             if (!is_numeric($qty)) {
                 $qty = Mage::app()->getLocale()->getNumber($qty);
             }
             $origQty = intval($origQty);
             $result->setOrigQty($origQty);
         }
         if ($qty < ITwebexperts_Payperrentals_Helper_Inventory::getMinSaleQuantity($product)) {
             $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('The minimum quantity allowed for purchase is %s.', ITwebexperts_Payperrentals_Helper_Inventory::getMinSaleQuantity($product)))->setErrorCode('qty_min')->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))->setQuoteMessageIndex('qty');
             return $result;
         }
         if ($qty > ITwebexperts_Payperrentals_Helper_Inventory::getMaxSaleQuantity($product)) {
             $result->setHasError(true)->setMessage(Mage::helper('cataloginventory')->__('The maximum quantity allowed for purchase is %s.', ITwebexperts_Payperrentals_Helper_Inventory::getMaxSaleQuantity($product)))->setErrorCode('qty_max')->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))->setQuoteMessageIndex('qty');
             return $result;
         }
         $result->addData($this->checkQtyIncrements($qty)->getData());
         if ($result->getHasError()) {
             return $result;
         }
         $option = $quoteItem->getOptionByCode('info_buyRequest');
         $buyRequest = $option ? unserialize($option->getValue()) : null;
         if (Mage::app()->getStore()->isAdmin() && Mage::getSingleton('adminhtml/session_quote')->getOrderId()) {
             $editedOrderId = Mage::getSingleton('adminhtml/session_quote')->getOrderId();
             $order = Mage::getModel('sales/order')->load($editedOrderId);
             $buyRequestArray = (array) $buyRequest;
             foreach ($order->getAllItems() as $oItem) {
                 if ($oItem->getProduct()->getId() != $product->getId()) {
                     continue;
                 }
                 if (is_object($oItem->getOrderItem())) {
                     $item = $oItem->getOrderItem();
                 } else {
                     $item = $oItem;
                 }
                 if ($item->getParentItem()) {
                     continue;
                 }
                 //check for bundles
                 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' => $item->getQtyOrdered());
                     }
                 } 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' => $item->getQtyOrdered());
                 }
             }
             $buyRequest = new Varien_Object($buyRequestArray);
         }
         if (isset($buyRequest['start_date']) && isset($buyRequest['end_date'])) {
             if (strtotime($buyRequest['start_date']) > strtotime($buyRequest['end_date'])) {
                 $message = Mage::helper('payperrentals')->__('Start Date is bigger then End Date. Please change!');
                 $result->setHasError(true)->setMessage($message)->setQuoteMessage($message);
                 return $result;
             }
         }
         $isAvailable = false;
         if (ITwebexperts_Payperrentals_Helper_Inventory::isAllowedOverbook($product->getId())) {
             $isAvailable = true;
         }
         if (ITwebexperts_Payperrentals_Helper_Data::isBuyout($buyRequest)) {
             if (!$isAvailable) {
                 Mage::register('quote_item_id', $quoteItemId);
                 $maxQty = ITwebexperts_Payperrentals_Helper_Inventory::getQuantity($product, null, null, $buyRequest);
                 Mage::unregister('quote_item_id');
                 if ($maxQty >= $qty) {
                     $isAvailable = true;
                 }
             }
             if ($isAvailable) {
                 return $result;
             } else {
                 $message = Mage::helper('payperrentals')->__('There is not enough quantity for buy this product');
                 $result->setHasError(true)->setMessage($message)->setQuoteMessage($message);
                 return $result;
             }
         }
         if (!Mage::app()->getStore()->isAdmin() && !Mage::getSingleton('checkout/session')->getIsExtendedQuote() && isset($buyRequest['start_date']) && isset($buyRequest['end_date']) && ITwebexperts_Payperrentals_Helper_Inventory::isExcludedDay($product->getId(), $buyRequest['start_date'], $buyRequest['end_date'])) {
             $message = Mage::helper('payperrentals')->__('There are blocked dates or excluded days on your selected dates!');
             $result->setHasError(true)->setMessage($message)->setQuoteMessage($message);
             return $result;
         } else {
             if (!$isAvailable && isset($buyRequest['start_date']) && isset($buyRequest['end_date'])) {
                 Mage::register('quote_item_id', $quoteItemId);
                 $maxQty = ITwebexperts_Payperrentals_Helper_Inventory::getQuantity($product, $startDate, $endDate, $buyRequest);
                 Mage::unregister('quote_item_id');
                 if ($maxQty >= $qty) {
                     $isAvailable = true;
                 }
             }
         }
         if (ITwebexperts_Payperrentals_Helper_Data::isUsingGlobalDatesShoppingCart($product) && !$buyRequest['start_date']) {
             $message = Mage::helper('payperrentals')->__('Please select Global Dates!');
             $result->setHasError(true)->setMessage($message)->setQuoteMessage($message);
             return $result;
         }
         if (!Mage::app()->getStore()->isAdmin() && !ITwebexperts_Payperrentals_Helper_Data::isBuyout($buyRequest) && (isset($buyRequest['start_date']) && strtotime($buyRequest['start_date']) < strtotime(date('Y-m-d')) || isset($buyRequest['end_date']) && strtotime($buyRequest['end_date']) < strtotime(date('Y-m-d')))) {
             $message = Mage::helper('payperrentals')->__('The selected Dates are in the past. Please select new dates!');
             $result->setHasError(true)->setMessage($message)->setQuoteMessage($message);
             return $result;
         }
         if (Mage::app()->getStore()->isAdmin() && ITwebexperts_Payperrentals_Helper_Inventory::isAllowedOverbook($product->getId()) && ITwebexperts_Payperrentals_Helper_Inventory::showAdminOverbookWarning()) {
             Mage::register('quote_item_id', $quoteItemId);
             $maxQty = ITwebexperts_Payperrentals_Helper_Inventory::getQuantity($product, $startDate, $endDate, $buyRequest, true);
             Mage::unregister('quote_item_id');
             if ($maxQty < $qty) {
                 $message = Mage::helper('cataloginventory')->__('Product is not available for the selected dates');
                 $result->setHasError(false)->setMessage($message)->setQuoteMessage($message)->setQuoteMessageIndex('qtyppr');
                 return $result;
             }
         }
         Mage::dispatchEvent('before_stock_check', array('buyrequest' => $buyRequest, 'isavailable' => &$isAvailable));
         if (!$isAvailable) {
             if (isset($buyRequest['start_date']) && isset($buyRequest['end_date'])) {
                 //Mage::register('no_quote', 1);
                 Mage::register('quote_item_id', $quoteItemId);
                 $maxQty = ITwebexperts_Payperrentals_Helper_Inventory::getQuantity($product, $startDate, $endDate, $buyRequest);
                 Mage::unregister('quote_item_id');
                 $maxQty = intval($maxQty / $qtyOption);
                 //Mage::unregister('no_quote', 1);
                 if ($maxQty > 0) {
                     $message = Mage::helper('payperrentals')->__('Max quantity available for these dates is: ' . $maxQty . ', your quantity has been adjusted.');
                     // Mage::getSingleton('checkout/session')->addError($message);
                     $result->setHasQtyOptionUpdate(true);
                     //$result->setOrigQty($maxQty);
                     $result->setQty($maxQty);
                     $result->setItemQty($maxQty);
                     $result->setMessage($message)->setQuoteMessage($message);
                     return $result;
                 }
                 $message = Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProductName());
             } else {
                 $message = Mage::helper('cataloginventory')->__('Please select Start and End Dates');
             }
             $result->setHasError(true)->setMessage($message)->setQuoteMessage($message)->setQuoteMessageIndex('qtyppr');
             return $result;
         }
         return $result;
     }
     $return = parent::checkQuoteItemQty($qty, $summaryQty, $origQty);
     return $return;
 }
Exemplo n.º 23
0
 public static function isDeliveryDatesInstalled()
 {
     if (is_null(self::$_isDeliveryDatesInstalled)) {
         self::$_isDeliveryDatesInstalled = Mage::helper('core')->isModuleEnabled('ITwebexperts_Deliverydates');
     }
     return self::$_isDeliveryDatesInstalled;
 }
Exemplo n.º 24
0
 public static function getBuyoutPrice($product, $configurableParent = null)
 {
     if (is_object($configurableParent) && $configurableParent->getPayperrentalsBuyoutprice()) {
         $buyoutPrice = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($configurableParent->getId(), 'payperrentals_buyoutprice');
     } else {
         $buyoutPrice = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($product->getId(), 'payperrentals_buyoutprice');
     }
     return $buyoutPrice;
 }
Exemplo n.º 25
0
 public function getFutureReservationLimit($product = null, $storeId = null)
 {
     if (is_object($product)) {
         $productId = $product->getId();
     } else {
         $productId = $product;
     }
     $useGlobalFutureLimit = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($productId, 'use_global_future_limit');
     if ($useGlobalFutureLimit == 0) {
         $futureLimit = ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($productId, 'future_reservation_limit');
         return (int) $futureLimit;
     } else {
         if ($storeId) {
             return (int) Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_FUTURE_LIMIT, $storeId);
         } else {
             return (int) Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_FUTURE_LIMIT);
         }
     }
 }
Exemplo n.º 26
0
 /**
  * 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;
 }
Exemplo n.º 27
0
 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');
 }
Exemplo n.º 28
0
 public static function showGridColumns($_item)
 {
     $return = '';
     $nonSequential = Mage::helper('payperrentals/config')->isNonSequentialSelect(Mage::app()->getStore()->getId());
     if (ITwebexperts_Payperrentals_Helper_Data::isReservationType($_item->getProductId())) {
         if ($_item->getProductType() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE || $_item->getProductType() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_CONFIGURABLE || $_item->getProductType() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_BUNDLE) {
             $buyRequest = $_item->getBuyRequest();
             $_showTime = (bool) Mage::getResourceModel('catalog/product')->getAttributeRawValue($_item->getProductId(), 'payperrentals_use_times', $_item->getStoreId());
             if ($nonSequential) {
                 $stDate = ITwebexperts_Payperrentals_Helper_Date::localiseNonsequentialBuyRequest($buyRequest->getStartDate(), $_showTime);
             } else {
                 if ($buyRequest->getStartTime()) {
                     $buyStartDate = str_replace('00:00:00', $buyRequest->getStartTime(), $buyRequest->getStartDate());
                     $buyEndDate = str_replace('23:59:59', $buyRequest->getEndTime(), $buyRequest->getEndDate());
                 } else {
                     $buyStartDate = $buyRequest->getStartDate();
                     $buyEndDate = $buyRequest->getEndDate();
                 }
                 $stDate = ITwebexperts_Payperrentals_Helper_Date::formatDbDate($buyStartDate, !$_showTime);
                 $enDate = ITwebexperts_Payperrentals_Helper_Date::formatDbDate($buyEndDate, !$_showTime);
             }
             if ($nonSequential) {
                 $return .= '<td class="">' . $stDate . '</td>';
             } else {
                 $return .= '<td class="">' . $stDate . '</td>';
                 $return .= '<td class="">' . $enDate . '</td>';
             }
             $resultObject = new Varien_Object();
             //$resultObject->setReturn($return);
             Mage::dispatchEvent('options_grid', array('item' => $_item, 'result' => $resultObject));
             $return .= $resultObject->getReturn();
         }
     } else {
         if ($nonSequential) {
             $return .= '<td class="">' . '' . '</td>';
         } else {
             $return .= '<td class="">' . '' . '</td>';
             $return .= '<td class="">' . '' . '</td>';
         }
     }
     return $return;
 }
Exemplo n.º 29
0
 /**
  * @param Varien_Object $row
  * @return mixed
  */
 public function render(Varien_Object $row)
 {
     $data = $row->getData($this->getColumn()->getIndex());
     //$product = Mage::getModel('catalog/product')->load($data);
     return ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($data, 'name');
 }
Exemplo n.º 30
0
 /**
  * Check product inventory data when quote item quantity declaring
  *
  * @param  Varien_Event_Observer $observer
  * @return Mage_CatalogInventory_Model_Observer
  */
 public function checkQuoteItemQty($observer)
 {
     $quoteItem = $observer->getEvent()->getItem();
     /* @var $quoteItem Mage_Sales_Model_Quote_Item */
     if (!$quoteItem || !$quoteItem->getProductId() || !$quoteItem->getQuote() || $quoteItem->getQuote()->getIsSuperMode()) {
         return $this;
     }
     /**
      * Get Qty
      */
     $qty = $quoteItem->getQty();
     /**
      * Check if product in stock. For composite products check base (parent) item stosk status
      */
     $stockItem = $quoteItem->getProduct()->getStockItem();
     $parentStockItem = false;
     if ($quoteItem->getParentItem()) {
         $parentStockItem = $quoteItem->getParentItem()->getProduct()->getStockItem();
     }
     if ($stockItem) {
         if (!$stockItem->getIsInStock() || $parentStockItem && !$parentStockItem->getIsInStock()) {
             $quoteItem->addErrorInfo('cataloginventory', Mage_CatalogInventory_Helper_Data::ERROR_QTY, Mage::helper('cataloginventory')->__('This product is currently out of stock.'));
             $quoteItem->getQuote()->addErrorInfo('stock', 'cataloginventory', Mage_CatalogInventory_Helper_Data::ERROR_QTY, Mage::helper('cataloginventory')->__('Some of the products are currently out of stock.'));
             return $this;
         } else {
             // Delete error from item and its quote, if it was set due to item out of stock
             $this->_removeErrorsFromQuoteAndItem($quoteItem, Mage_CatalogInventory_Helper_Data::ERROR_QTY);
         }
     }
     /**
      * Check item for options
      */
     $options = $quoteItem->getQtyOptions();
     if ($options && $qty > 0) {
         $qty = $quoteItem->getProduct()->getTypeInstance(true)->prepareQuoteItemQty($qty, $quoteItem->getProduct());
         $quoteItem->setData('qty', $qty);
         if ($stockItem) {
             $result = $stockItem->checkQtyIncrements($qty);
             if ($result->getHasError()) {
                 $quoteItem->addErrorInfo('cataloginventory', Mage_CatalogInventory_Helper_Data::ERROR_QTY_INCREMENTS, $result->getMessage());
                 $quoteItem->getQuote()->addErrorInfo($result->getQuoteMessageIndex(), 'cataloginventory', Mage_CatalogInventory_Helper_Data::ERROR_QTY_INCREMENTS, $result->getQuoteMessage());
             } else {
                 // Delete error from item and its quote, if it was set due to qty problems
                 $this->_removeErrorsFromQuoteAndItem($quoteItem, Mage_CatalogInventory_Helper_Data::ERROR_QTY_INCREMENTS);
             }
         }
         $quoteItemHasErrors = false;
         foreach ($options as $option) {
             $optionValue = $option->getValue();
             /* @var $option Mage_Sales_Model_Quote_Item_Option */
             $optionQty = $qty * $optionValue;
             $increaseOptionQty = ($quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty) * $optionValue;
             $stockItem = $option->getProduct()->getStockItem();
             if ($quoteItem->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
                 $stockItem->setProductName($quoteItem->getName());
             }
             /* @var $stockItem Mage_CatalogInventory_Model_Stock_Item */
             if (!$stockItem instanceof Mage_CatalogInventory_Model_Stock_Item) {
                 Mage::throwException(Mage::helper('cataloginventory')->__('The stock item for Product in option is not valid.'));
             }
             /**
              * define that stock item is child for composite product
              */
             $stockItem->setIsChildItem(true);
             /**
              * don't check qty increments value for option product
              */
             $stockItem->setSuppressCheckQtyIncrements(true);
             $qtyForCheck = $this->_getQuoteItemQtyForCheck($option->getProduct()->getId(), $quoteItem->getId(), $increaseOptionQty);
             $result = $stockItem->checkQuoteItemQty($optionQty, $qtyForCheck, $optionValue, $quoteItem, $option->getProduct(), true);
             foreach ($quoteItem->getChildren() as $children) {
                 $children->setParentProductQty($qtyForCheck);
                 $children->setParentProductQtyOption(intval($qtyForCheck / $qty));
             }
             if (!is_null($result->getItemIsQtyDecimal())) {
                 $option->setIsQtyDecimal($result->getItemIsQtyDecimal());
             }
             if ($result->getHasQtyOptionUpdate()) {
                 $option->setHasQtyOptionUpdate(true);
                 $quoteItem->updateQtyOption($option, $result->getOrigQty());
                 $option->setValue($result->getOrigQty());
                 if ($result->getQty()) {
                     $qty = $result->getQty();
                 }
                 /**
                  * if option's qty was updates we also need to update quote item qty
                  */
                 $quoteItem->setData('qty', intval($qty));
             }
             if (!is_null($result->getMessage())) {
                 $option->setMessage($result->getMessage());
                 $quoteItem->setMessage($result->getMessage());
             }
             if (!is_null($result->getItemBackorders())) {
                 $option->setBackorders($result->getItemBackorders());
             }
             if ($result->getHasError()) {
                 $option->setHasError(true);
                 $quoteItemHasErrors = true;
                 $quoteItem->addErrorInfo('cataloginventory', Mage_CatalogInventory_Helper_Data::ERROR_QTY, $result->getMessage());
                 $quoteItem->getQuote()->addErrorInfo($result->getQuoteMessageIndex(), 'cataloginventory', Mage_CatalogInventory_Helper_Data::ERROR_QTY, $result->getQuoteMessage());
             } elseif (!$quoteItemHasErrors) {
                 // Delete error from item and its quote, if it was set due to qty lack
                 $this->_removeErrorsFromQuoteAndItem($quoteItem, Mage_CatalogInventory_Helper_Data::ERROR_QTY);
             }
             $stockItem->unsIsChildItem();
         }
     } else {
         /* @var $stockItem Mage_CatalogInventory_Model_Stock_Item */
         if (!$stockItem instanceof Mage_CatalogInventory_Model_Stock_Item) {
             Mage::throwException(Mage::helper('cataloginventory')->__('The stock item for Product is not valid.'));
         }
         /**
          * When we work with subitem (as subproduct of bundle or configurable product)
          */
         if ($quoteItem->getParentItem()) {
             $rowQty = $quoteItem->getParentItem()->getQty() * $qty;
             /**
              * we are using 0 because original qty was processed
              */
             $qtyForCheck = $this->_getQuoteItemQtyForCheck($quoteItem->getProduct()->getId(), $quoteItem->getId(), 0);
         } else {
             $increaseQty = $quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty;
             $rowQty = $qty;
             $qtyForCheck = $this->_getQuoteItemQtyForCheck($quoteItem->getProduct()->getId(), $quoteItem->getId(), $increaseQty);
         }
         $productTypeCustomOption = $quoteItem->getProduct()->getCustomOption('product_type');
         if (!is_null($productTypeCustomOption)) {
             // Check if product related to current item is a part of grouped product
             if ($productTypeCustomOption->getValue() == Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE) {
                 $stockItem->setProductName($quoteItem->getProduct()->getName());
                 $stockItem->setIsChildItem(true);
             }
         }
         $result = $stockItem->checkQuoteItemQty($rowQty, $qtyForCheck, $qty, $quoteItem, $quoteItem->getProduct());
         if ($stockItem->hasIsChildItem()) {
             $stockItem->unsIsChildItem();
         }
         if (!is_null($result->getItemIsQtyDecimal())) {
             $quoteItem->setIsQtyDecimal($result->getItemIsQtyDecimal());
             if ($quoteItem->getParentItem()) {
                 $quoteItem->getParentItem()->setIsQtyDecimal($result->getItemIsQtyDecimal());
             }
         }
         /**
          * Just base (parent) item qty can be changed
          * qty of child products are declared just during add process
          * exception for updating also managed by product type
          */
         if ($result->getHasQtyOptionUpdate() && (!$quoteItem->getParentItem() || $quoteItem->getParentItem()->getProduct()->getTypeInstance(true)->getForceChildItemQtyChanges($quoteItem->getParentItem()->getProduct()))) {
             $quoteItem->setData('qty', $result->getOrigQty());
         }
         if ($result->getQty()) {
             $qty = $result->getQty();
             if ($quoteItem->getParentItem()) {
                 $quoteItem->getParentItem()->setData('qty', intval($qty));
                 $quoteItem->getParentItem()->addErrorInfo('cataloginventory', 3, $result->getMessage());
                 Mage::getSingleton('checkout/session')->addNotice(Mage::helper('payperrentals')->__('For some products in cart the quantities has been adjusted'));
             } else {
                 $quoteItem->setData('qty', intval($qty));
                 $quoteItem->addErrorInfo('cataloginventory', 3, $result->getMessage());
                 Mage::getSingleton('checkout/session')->addNotice(Mage::helper('payperrentals')->__('For some products in cart the quantities has been adjusted'));
             }
         }
         if (!is_null($result->getItemUseOldQty())) {
             $quoteItem->setUseOldQty($result->getItemUseOldQty());
         }
         if (!is_null($result->getMessage())) {
             $quoteItem->setMessage($result->getMessage());
         }
         if (!is_null($result->getItemBackorders())) {
             $quoteItem->setBackorders($result->getItemBackorders());
         }
         if ($result->getHasError()) {
             if (!ITwebexperts_Payperrentals_Helper_Data::isUsingGlobalDatesShoppingCart()) {
                 $quoteItem->addErrorInfo('cataloginventory', Mage_CatalogInventory_Helper_Data::ERROR_QTY, $result->getMessage());
             }
             $quoteItem->getQuote()->addErrorInfo($result->getQuoteMessageIndex(), 'cataloginventory', Mage_CatalogInventory_Helper_Data::ERROR_QTY, $result->getQuoteMessage());
         } else {
             // Delete error from item and its quote, if it was set due to qty lack
             $this->_removeErrorsFromQuoteAndItem($quoteItem, Mage_CatalogInventory_Helper_Data::ERROR_QTY);
         }
     }
     return $this;
 }