/** * Overrides the parent to validate the shipping address. * * @param array $address * @return $this * @throws OnePica_AvaTax_Exception */ public function setShippingAddress($address) { parent::setShippingAddress($address); if ($this->getQuote()->getIsVirtual()) { return $this; } if (Mage::helper('avatax')->isAvataxEnabled()) { if (!Mage::app()->getFrontController()->getRequest()->getParam('isAjax')) { $result = $this->getShippingAddress()->validate(); if ($result !== true) { $storeId = $this->_session->getStore()->getId(); if (Mage::helper('avatax')->fullStopOnError($storeId)) { foreach ($result as $error) { $this->getSession()->addError($error); } throw new OnePica_AvaTax_Exception(implode('<br />', $result)); } } elseif ($this->getShippingAddress()->getAddressNormalized() && !$this->_messageAdded) { Mage::getSingleton('avatax/session')->addNotice(Mage::helper('avatax')->__('The shipping address has been modified during the validation process. Please confirm the address below is accurate.')); $this->_messageAdded = true; // only add the message once } } } return $this; }
/** * Execute * * @param ArrayObject $settings * @param boolean $multipack * @return Dhl_Intraship_Model_Shipment $this */ public function execute(ArrayObject $settings, $multipack = null) { $helper = new Dhl_Intraship_Model_Autocreate(); $model = new Mage_Sales_Model_Order(); $myOrder = $model->loadByIncrementId($this->getOrderId()); $myOrder->setReordered(true); $data = array('currency' => 'EUR', 'account' => array('group_id' => 1, 'email' => '*****@*****.**'), 'billing_address' => $myOrder->getBillingAddress()->getData(), 'shipping_address' => $myOrder->getShippingAddress()->getData(), 'shipping_method' => 'flatrate_flatrate', 'comment' => array('customer_note' => false, 'send_confirmation' => false)); $admin = new Mage_Adminhtml_Model_Sales_Order_Create(); $order = $admin->initFromOrder($myOrder)->importPostData($data)->createOrder(); $shipment = $helper->checkOrder($order)->createShipment($order); $helper->saveShipment($shipment, $settings); $intraship = new Dhl_Intraship_Model_Shipment(); $intraship->load($shipment->getId(), 'shipment_id'); if (true === $multipack) { $intraship->setPackages(array('package_0' => array('weight' => 0.1), 'package_1' => array('weight' => 0.2), 'package_2' => array('weight' => 0.3)))->save(); } return $intraship; }
public function importPostData($data) { if (isset($data['rewardpoints']['qty'])) { if (is_numeric($data['rewardpoints']['qty'])) { $this->applyPoints($data['rewardpoints']['qty']); } } parent::importPostData($data); return $this; }
/** * Overrides the parent to validate the shipping address. * * @param array $address * @return $this */ public function setShippingAddress($address) { parent::setShippingAddress($address); if ($this->getQuote()->getIsVirtual()) { return $this; } if (!$this->_isAjaxRequest()) { $this->_validateShippingAddress(); } return $this; }
public function importPostData($data) { $toReturn = parent::importPostData($data); if ($postData = Mage::app()->getRequest()->getPost('aitoc_checkout_fields')) { if (!Mage::getSingleton('adminhtml/session')->hasData('aitcheckoutfields_admin_post_data')) { Mage::getSingleton('adminhtml/session')->addData(array('aitcheckoutfields_admin_post_data' => $postData)); } elseif ($postData != Mage::getSingleton('adminhtml/session')->getData('aitcheckoutfields_admin_post_data')) { Mage::getSingleton('adminhtml/session')->addData(array('aitcheckoutfields_admin_post_data' => $postData)); } } return $toReturn; }
public function saveQuote() { parent::saveQuote(); try { $hlp = Mage::helper('udropship/protected'); $items = $this->getQuote()->getAllItems(); //$hlp->setAllowReorginizeQuote(true); $hlp->startAddressPreparation($items); $hlp->applyDefaultVendorIds($items)->applyStockAvailability($items); //$hlp->setAllowReorginizeQuote(false); } catch (Exception $e) { // all necessary actions should be already done by now, kill the exception } return $this; }
/** * Parse data retrieved from request * * @param array $data * @return Mage_Adminhtml_Model_Sales_Order_Create */ public function importPostData($data) { parent::importPostData($data); if (isset($data['shipping_amount'])) { $shippingPrice = $this->_parseShippingPrice($data['shipping_amount']); $this->getQuote()->getShippingAddress()->setShippingAmount($shippingPrice); } if (isset($data['base_shipping_amount'])) { $baseShippingPrice = $this->_parseShippingPrice($data['base_shipping_amount']); $this->getQuote()->getShippingAddress()->setBaseShippingAmount($baseShippingPrice); } if (isset($data['shipping_description'])) { $this->getQuote()->getShippingAddress()->setShippingDescription($data['shipping_description']); } return $this; }
/** * @magentoDataFixture Mage/Sales/_files/order_paid_with_saved_cc.php */ public function testInitFromOrderSavedCcInformationNotDeleted() { $order = new Mage_Sales_Model_Order(); $order->loadByIncrementId('100000001'); $payment = $order->getPayment(); $this->assertEquals('5', $payment->getCcExpMonth()); $this->assertEquals('2016', $payment->getCcExpYear()); $this->assertEquals('AE', $payment->getCcType()); $this->assertEquals('0005', $payment->getCcLast4()); Mage::unregister('rule_data'); $payment = $this->_model->initFromOrder($order)->getQuote()->getPayment(); $this->assertEquals('5', $payment->getCcExpMonth()); $this->assertEquals('2016', $payment->getCcExpYear()); $this->assertEquals('AE', $payment->getCcType()); $this->assertEquals('0005', $payment->getCcLast4()); }
public function setShippingAddress($address) { parent::setShippingAddress($address); if (!Mage::app()->getFrontController()->getRequest()->getParam('isAjax')) { $result = $this->getShippingAddress()->validate(); if ($result !== true) { $storeId = $this->_session->getStore()->getId(); if (Mage::helper('advanced')->fullStopOnError($storeId)) { foreach ($result as $error) { $this->getSession()->addError($error); } Mage::throwException(''); } } else { if ($this->getShippingAddress()->getAddressNormalized() && !$this->_messageAdded) { Mage::getSingleton('advanced/session')->addNotice(Mage::helper('advanced')->__('The shipping address has been modified during the validation process. Please confirm the address below is accurate.')); $this->_messageAdded = true; // only add the message once } } } return $this; }
/** * 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; } }