Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. public function saveOrder()
  2. {
  3. $this->validate();
  4. $isNewCustomer = false;
  5. switch ($this->getCheckoutMethod()) {
  6. case self::METHOD_GUEST:
  7. $this->_prepareGuestQuote();
  8. break;
  9. case self::METHOD_REGISTER:
  10. $this->_prepareNewCustomerQuote();
  11. $isNewCustomer = true;
  12. break;
  13. default:
  14. $this->_prepareCustomerQuote();
  15. break;
  16. }
  17.  
  18. $service = Mage::getModel('sales/service_quote', $this->getQuote());
  19. $service->submitAll();
  20.  
  21. if ($isNewCustomer) {
  22. try {
  23. $this->_involveNewCustomer();
  24. } catch (Exception $e) {
  25. Mage::logException($e);
  26. }
  27. }
  28.  
  29. $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId())
  30. ->setLastSuccessQuoteId($this->getQuote()->getId())
  31. ->clearHelperData();
  32.  
  33. $order = $service->getOrder();
  34. if ($order) {
  35. Mage::dispatchEvent('checkout_type_onepage_save_order_after',
  36. array('order'=>$order, 'quote'=>$this->getQuote()));
  37.  
  38. /**
  39. * a flag to set that there will be redirect to third party after confirmation
  40. * eg: paypal standard ipn
  41. */
  42. $redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
  43. /**
  44. * we only want to send to customer about new order when there is no redirect to third party
  45. */
  46. if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {
  47. try {
  48. $order->queueNewOrderEmail();
  49. } catch (Exception $e) {
  50. Mage::logException($e);
  51. }
  52. }
  53.  
  54. // add order information to the session
  55. $this->_checkoutSession->setLastOrderId($order->getId())
  56. ->setRedirectUrl($redirectUrl)
  57. ->setLastRealOrderId($order->getIncrementId());
  58.  
  59. // as well a billing agreement can be created
  60. $agreement = $order->getPayment()->getBillingAgreement();
  61. if ($agreement) {
  62. $this->_checkoutSession->setLastBillingAgreementId($agreement->getId());
  63. }
  64. }
  65.  
  66. // add recurring profiles information to the session
  67. $profiles = $service->getRecurringPaymentProfiles();
  68. if ($profiles) {
  69. $ids = array();
  70. foreach ($profiles as $profile) {
  71. $ids[] = $profile->getId();
  72. }
  73. $this->_checkoutSession->setLastRecurringProfileIds($ids);
  74. // TODO: send recurring profile emails
  75. }
  76.  
  77. Mage::dispatchEvent(
  78. 'checkout_submit_all_after',
  79. array('order' => $order, 'quote' => $this->getQuote(), 'recurring_profiles' => $profiles)
  80. );
  81.  
  82. return $this;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement