Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function saveOrder()
- {
- $this->validate();
- $isNewCustomer = false;
- switch ($this->getCheckoutMethod()) {
- case self::METHOD_GUEST:
- $this->_prepareGuestQuote();
- break;
- case self::METHOD_REGISTER:
- $this->_prepareNewCustomerQuote();
- $isNewCustomer = true;
- break;
- default:
- $this->_prepareCustomerQuote();
- break;
- }
- $service = Mage::getModel('sales/service_quote', $this->getQuote());
- $service->submitAll();
- if ($isNewCustomer) {
- try {
- $this->_involveNewCustomer();
- } catch (Exception $e) {
- Mage::logException($e);
- }
- }
- $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId())
- ->setLastSuccessQuoteId($this->getQuote()->getId())
- ->clearHelperData();
- $order = $service->getOrder();
- if ($order) {
- Mage::dispatchEvent('checkout_type_onepage_save_order_after',
- array('order'=>$order, 'quote'=>$this->getQuote()));
- /**
- * a flag to set that there will be redirect to third party after confirmation
- * eg: paypal standard ipn
- */
- $redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
- /**
- * we only want to send to customer about new order when there is no redirect to third party
- */
- if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {
- try {
- $order->queueNewOrderEmail();
- } catch (Exception $e) {
- Mage::logException($e);
- }
- }
- // add order information to the session
- $this->_checkoutSession->setLastOrderId($order->getId())
- ->setRedirectUrl($redirectUrl)
- ->setLastRealOrderId($order->getIncrementId());
- // as well a billing agreement can be created
- $agreement = $order->getPayment()->getBillingAgreement();
- if ($agreement) {
- $this->_checkoutSession->setLastBillingAgreementId($agreement->getId());
- }
- }
- // add recurring profiles information to the session
- $profiles = $service->getRecurringPaymentProfiles();
- if ($profiles) {
- $ids = array();
- foreach ($profiles as $profile) {
- $ids[] = $profile->getId();
- }
- $this->_checkoutSession->setLastRecurringProfileIds($ids);
- // TODO: send recurring profile emails
- }
- Mage::dispatchEvent(
- 'checkout_submit_all_after',
- array('order' => $order, 'quote' => $this->getQuote(), 'recurring_profiles' => $profiles)
- );
- return $this;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement