/** * Create new order * * @return Mage_Sales_Model_Order */ public function createOrder() { if (version_compare(Mage::getVersion(), '1.4.0.0', '>=') && version_compare(Mage::getVersion(), '1.4.1.0', '<')) { // START AITOC DELIVERY DATE $errors = Mage::getModel('adjdeliverydate/step')->process(); if (!empty($errors)) { foreach ($errors as $error) { $this->getSession()->addError($error); } Mage::throwException(''); } $quoteAddress = $this->getQuote()->getShippingAddress(); Mage::getModel('adjdeliverydate/quote')->saveDelivery($quoteAddress); // FINISH AITOC DELIVERY DATE $this->_validate(); if (!$this->getQuote()->getCustomerIsGuest()) { $this->_putCustomerIntoQuote(); } $quoteConvert = Mage::getModel('sales/convert_quote'); /* @var $quoteConvert Mage_Sales_Model_Convert_Quote */ $quote = $this->getQuote(); if (!$this->getSession()->getOrder()->getId()) { $quote->reserveOrderId(); } if ($this->getQuote()->getIsVirtual()) { $order = $quoteConvert->addressToOrder($quote->getBillingAddress()); } else { $order = $quoteConvert->addressToOrder($quote->getShippingAddress()); } $order->setBillingAddress($quoteConvert->addressToOrderAddress($quote->getBillingAddress()))->setPayment($quoteConvert->paymentToOrderPayment($quote->getPayment())); if (!$this->getQuote()->getIsVirtual()) { $order->setShippingAddress($quoteConvert->addressToOrderAddress($quote->getShippingAddress())); } if (!$this->getQuote()->getIsVirtual()) { foreach ($quote->getShippingAddress()->getAllItems() as $item) { /* @var $item Mage_Sales_Model_Quote_Item */ $orderItem = $quoteConvert->itemToOrderItem($item); $options = array(); if ($productOptions = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct())) { $productOptions['info_buyRequest']['options'] = $this->_prepareOptionsForRequest($item); $options = $productOptions; } if ($addOptions = $item->getOptionByCode('additional_options')) { $options['additional_options'] = unserialize($addOptions->getValue()); } if ($options) { $orderItem->setProductOptions($options); } if ($item->getParentItem()) { $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId())); } $order->addItem($orderItem); } } if ($this->getQuote()->hasVirtualItems()) { foreach ($quote->getBillingAddress()->getAllItems() as $item) { /* @var $item Mage_Sales_Model_Quote_Item */ $orderItem = $quoteConvert->itemToOrderItem($item); $options = array(); if ($productOptions = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct())) { $productOptions['info_buyRequest']['options'] = $this->_prepareOptionsForRequest($item); $options = $productOptions; } if ($addOptions = $item->getOptionByCode('additional_options')) { $options['additional_options'] = unserialize($addOptions->getValue()); } if ($options) { $orderItem->setProductOptions($options); } if ($item->getParentItem()) { $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId())); } $order->addItem($orderItem); } } if ($this->getSendConfirmation()) { $order->setEmailSent(true); } if ($this->getSession()->getOrder()->getId()) { $oldOrder = $this->getSession()->getOrder(); $originalId = $oldOrder->getOriginalIncrementId() ? $oldOrder->getOriginalIncrementId() : $oldOrder->getIncrementId(); $order->setOriginalIncrementId($originalId); $order->setRelationParentId($oldOrder->getId()); $order->setRelationParentRealId($oldOrder->getIncrementId()); $order->setEditIncrement($oldOrder->getEditIncrement() + 1); $order->setIncrementId($originalId . '-' . $order->getEditIncrement()); } $order->place(); $this->_saveCustomerAfterOrder($order); $order->save(); if ($this->getSession()->getOrder()->getId()) { $oldOrder = $this->getSession()->getOrder(); $this->getSession()->getOrder()->setRelationChildId($order->getId()); $this->getSession()->getOrder()->setRelationChildRealId($order->getIncrementId()); $this->getSession()->getOrder()->cancel()->save(); $order->save(); } if ($this->getSendConfirmation()) { $order->sendNewOrderEmail(); } return $order; } elseif (version_compare(Mage::getVersion(), '1.4.1.0', '>=')) { // START AITOC DELIVERY DATE $errors = Mage::getModel('adjdeliverydate/step')->process(); if (!empty($errors)) { foreach ($errors as $error) { $this->getSession()->addError($error); } Mage::throwException(''); } // FINISH AITOC DELIVERY DATE $quoteAddress = $this->getQuote()->getShippingAddress(); Mage::getModel('adjdeliverydate/quote')->saveDelivery($quoteAddress); $order = parent::createOrder(); return $order; } }
public function createOrder() { $mainModel = Mage::getModel('aitcheckoutfields/aitcheckoutfields'); $oldOrderId = ''; /* {#AITOC_COMMENT_END#} if(isset($_SESSION['adminhtml_quote']['order_id'])||isset($_SESSION['adminhtml_quote']['reordered'])) { $oldOrderId=isset($_SESSION['adminhtml_quote']['order_id'])?$_SESSION['adminhtml_quote']['order_id']:$_SESSION['adminhtml_quote']['reordered']; $oldOrder = Mage::getModel('sales/order')->load($oldOrderId); $storeId = $oldOrder->getStoreId(); $websiteId = $oldOrder->getStore()->getWebsiteId(); }else{ $quote = $this->getQuote(); $storeId = $quote->getStoreId(); $websiteId = $quote->getStore()->getWebsiteId(); } $performer = Aitoc_Aitsys_Abstract_Service::get()->platform()->getModule('Aitoc_Aitcheckoutfields')->getLicense()->getPerformer(); $ruler = $performer->getRuler(); if (!($ruler->checkRule('store',$storeId,'store') || $ruler->checkRule('store',$websiteId,'website'))) { if($oldOrderId) { $oldData = $mainModel->getOrderCustomData($oldOrderId, $storeId, true); foreach ($oldData as $oldAttr){ if(in_array($oldAttr['type'],array('checkbox','radio','select','multiselect'))) { $oldAttr['rawval'] = explode(',',$oldAttr['rawval']); } $_SESSION['aitoc_checkout_used']['adminorderfields'][$oldAttr['id']]=$oldAttr['rawval']; } } } else { {#AITOC_COMMENT_START#} */ $attributeCollection = $mainModel->getAttributeCollecton(); $data = Mage::app()->getRequest()->getPost('aitoc_checkout_fields'); foreach ($attributeCollection as $attribute) { if (isset($data[$attribute->getAttributeCode()])) { if ($attribute->getFrontend()->getInputType() !== 'static') { $_SESSION['aitoc_checkout_used']['adminorderfields'][$attribute->getId()] = $data[$attribute->getAttributeCode()]; } } } /* {#AITOC_COMMENT_END#} } {#AITOC_COMMENT_START#} */ $order = parent::createOrder(); if (isset($_SESSION['aitoc_checkout_used']['new_customer'])) { $_SESSION['aitoc_checkout_used']['register'] = $_SESSION['aitoc_checkout_used']['adminorderfields']; $customerId = $order->getCustomerId(); $mainModel->saveCustomerData($customerId); } $orderId = $order->getId(); $mainModel->saveCustomOrderData($orderId, 'adminorderfields'); Mage::dispatchEvent('aitcfm_order_save_after', array('order' => $order, 'checkoutfields' => $order->getCustomFields())); $mainModel->clearCheckoutSession('adminorderfields'); Mage::getSingleton('adminhtml/session')->unsetData('aitcheckoutfields_admin_post_data'); return $order; }