示例#1
0
 /**
  * Place the order and recurring payment profiles when customer returned from paypal
  * Until this moment all quote data must be valid
  *
  * @param string $token
  * @param string $shippingMethodCode
  */
 public function place($token, $shippingMethodCode = null)
 {
     if ($shippingMethodCode) {
         $this->updateShippingMethod($shippingMethodCode);
     }
     $isNewCustomer = false;
     switch ($this->_quote->getCheckoutMethod()) {
         case Mage_Checkout_Model_Type_Onepage::METHOD_GUEST:
             $this->_prepareGuestQuote();
             break;
         case Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER:
             $this->_prepareNewCustomerQuote();
             $isNewCustomer = true;
             break;
         default:
             $this->_prepareCustomerQuote();
             break;
     }
     $this->_ignoreAddressValidation();
     $this->_quote->collectTotals();
     $service = Mage::getModel('sales/service_quote', $this->_quote);
     $service->submitAll();
     $this->_quote->save();
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (Exception $e) {
             Mage::logException($e);
         }
     }
     $this->_recurringPaymentProfiles = $service->getRecurringPaymentProfiles();
     // TODO: send recurring profile emails
     $order = $service->getOrder();
     if (!$order) {
         return;
     }
     $this->_billingAgreement = $order->getPayment()->getBillingAgreement();
     // commence redirecting to finish payment, if paypal requires it
     if ($order->getPayment()->getAdditionalInformation(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_REDIRECT)) {
         $this->_redirectUrl = $this->_config->getExpressCheckoutCompleteUrl($token);
     }
     switch ($order->getState()) {
         // even after placement paypal can disallow to authorize/capture, but will wait until bank transfers money
         case Mage_Sales_Model_Order::STATE_PENDING_PAYMENT:
             // TODO
             break;
             // regular placement, when everything is ok
         // regular placement, when everything is ok
         case Mage_Sales_Model_Order::STATE_PROCESSING:
         case Mage_Sales_Model_Order::STATE_COMPLETE:
         case Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW:
             $order->sendNewOrderEmail();
             break;
     }
     $this->_order = $order;
 }
 /**
  * Get checkout method
  *
  * @return string
  */
 public function getCheckoutMethod()
 {
     if ($this->_getCustomerSession()->isLoggedIn()) {
         return Mage_Checkout_Model_Type_Onepage::METHOD_CUSTOMER;
     }
     if (!$this->_quote->getCheckoutMethod()) {
         if (Mage::helper('checkout')->isAllowedGuestCheckout($this->_quote)) {
             $this->_quote->setCheckoutMethod(Mage_Checkout_Model_Type_Onepage::METHOD_GUEST);
         } else {
             $this->_quote->setCheckoutMethod(Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER);
         }
     }
     return $this->_quote->getCheckoutMethod();
 }
示例#3
0
 /**
  * @param Mage_Sales_Model_Quote $quote
  * @return bool
  */
 public function prepareCustomerForQuote(Mage_Sales_Model_Quote $quote)
 {
     $isNewCustomer = false;
     switch ($quote->getCheckoutMethod()) {
         case self::MODE_GUEST:
             $this->_prepareGuestQuote($quote);
             break;
         case self::MODE_REGISTER:
             $this->_prepareNewCustomerQuote($quote);
             $isNewCustomer = true;
             break;
         default:
             $this->_prepareCustomerQuote($quote);
             break;
     }
     return $isNewCustomer;
 }
示例#4
0
 /**
  * Place the order and recurring payment profiles when customer returned from paypal
  * Until this moment all quote data must be valid
  */
 public function place()
 {
     $isNewCustomer = false;
     if ($this->_quote->getCheckoutMethod() == 'register') {
         $isNewCustomer = $this->_prepareNewCustomerQuote();
     } elseif (!$this->_quote->getCustomerId()) {
         $this->_quote->setCustomerIsGuest(true)->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)->setCustomerEmail($this->_quote->getBillingAddress()->getEmail());
     } elseif ($this->_quote->getCustomerId()) {
         if (!$this->_quote->getBillingAddress()->getCustomerAddressId()) {
             $billingAddress = Mage::getModel('customer/address');
             $billingAddress->setData($this->_quote->getBillingAddress()->getData())->setCustomerId($this->_quote->getCustomerId())->setSaveInAddressBook('0');
             //->setIsDefaultBilling('1');
             if ($this->_quote->getShippingAddress()->getData('same_as_billing')) {
                 $billingAddress->setIsDefaultShipping('0');
             } else {
                 $shippingAddress = Mage::getModel('customer/address');
                 $shippingAddress->setData($this->_quote->getShippingAddress()->getData())->setCustomerId($this->_quote->getCustomerId())->setSaveInAddressBook('0')->setIsDefaultShipping('0');
                 $shippingAddress->save();
             }
             $billingAddress->save();
         } else {
             if ($this->_quote->getBillingAddress()->getSaveInAddressBook()) {
                 $newAddress = Mage::getModel('customer/address');
                 $newAddress->setData($this->_quote->getBillingAddress()->getData())->setCustomerId($this->_quote->getCustomerId())->setSaveInAddressBook('1')->save();
             }
             if ($this->_quote->getShippingAddress()->getSaveInAddressBook() && !$this->_quote->getShippingAddress()->getData('same_as_billing')) {
                 $newAddress = Mage::getModel('customer/address');
                 $newAddress->setData($this->_quote->getShippingAddress()->getData())->setCustomerId($this->_quote->getCustomerId())->setSaveInAddressBook('1')->save();
             }
         }
     }
     $this->_ignoreAddressValidation();
     $this->_quote->collectTotals();
     //set payment method as paypal
     $this->_quote->getPayment()->setMethod("sagepaypaypal");
     // commence redirecting to finish payment
     $rs = Mage::getModel('sagepaysuite/sagePayDirectPro')->completePayPalTransaction(Mage::getSingleton('sagepaysuite/session')->getSagepaypaypalRqpost(), $this->_quote);
     $service = Mage::getModel('sales/service_quote', $this->_quote);
     $service->submitAll();
     $this->_quote->save();
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (Exception $e) {
             Mage::logException($e);
         }
     }
     $order = $service->getOrder();
     if (!$order) {
         $dbtrn = Mage::getModel('sagepaysuite2/sagepaysuite_paypaltransaction')->loadByVendorTxCode(Mage::getSingleton('sagepaysuite/session')->getLastVendorTxCode());
         if ($dbtrn->getId()) {
             $dbtrn->setStatus('MAGE_ERROR')->setStatusDetail("Could not save order. " . $dbtrn->getStatusDetail())->save();
         }
         Mage::throwException('Could not save order. Please try again.');
         return;
     }
     //Dispatching event, some modules need this to complete processing.
     Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order' => $order, 'quote' => $this->_quote));
     try {
         $order->sendNewOrderEmail();
     } catch (Exception $ex) {
         Mage::logException($ex);
     }
     $this->_order = $order;
 }
示例#5
0
 /**
  * Place the order and recurring payment profiles when customer returned from paypal
  * Until this moment all quote data must be valid
  */
 public function place()
 {
     $isNewCustomer = false;
     if ($this->_quote->getCheckoutMethod() == 'register') {
         $this->_prepareNewCustomerQuote();
         $isNewCustomer = true;
     } elseif (!$this->_quote->getCustomerId()) {
         $this->_quote->setCustomerIsGuest(true)->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)->setCustomerEmail($this->_quote->getBillingAddress()->getEmail());
     } elseif ($this->_quote->getCustomerId()) {
         if (!$this->_quote->getBillingAddress()->getCustomerAddressId()) {
             $billingAddress = Mage::getModel('customer/address');
             $billingAddress->setData($this->_quote->getBillingAddress()->getData())->setCustomerId($this->_quote->getCustomerId())->setSaveInAddressBook('1')->setIsDefaultBilling('1');
             if ($this->_quote->getShippingAddress()->getData('same_as_billing')) {
                 $billingAddress->setIsDefaultShipping('1');
             } else {
                 $shippingAddress = Mage::getModel('customer/address');
                 $shippingAddress->setData($this->_quote->getShippingAddress()->getData())->setCustomerId($this->_quote->getCustomerId())->setSaveInAddressBook('1')->setIsDefaultShipping('1');
                 $shippingAddress->save();
             }
             $billingAddress->save();
         } else {
             if ($this->_quote->getBillingAddress()->getSaveInAddressBook()) {
                 $newAddress = Mage::getModel('customer/address');
                 $newAddress->setData($this->_quote->getBillingAddress()->getData())->setCustomerId($this->_quote->getCustomerId())->setSaveInAddressBook('1')->save();
             }
             if ($this->_quote->getShippingAddress()->getSaveInAddressBook() && !$this->_quote->getShippingAddress()->getData('same_as_billing')) {
                 $newAddress = Mage::getModel('customer/address');
                 $newAddress->setData($this->_quote->getShippingAddress()->getData())->setCustomerId($this->_quote->getCustomerId())->setSaveInAddressBook('1')->save();
             }
         }
     }
     $this->_ignoreAddressValidation();
     $this->_quote->collectTotals();
     // commence redirecting to finish payment
     $rs = Mage::getModel('sagepaysuite/sagePayDirectPro')->completePayPalTransaction(Mage::getSingleton('sagepaysuite/session')->getSagepaypaypalRqpost(), $this->_quote);
     $service = Mage::getModel('sales/service_quote', $this->_quote);
     $service->submitAll();
     $this->_quote->save();
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (Exception $e) {
             Mage::logException($e);
         }
     }
     $order = $service->getOrder();
     if (!$order) {
         return;
     }
     switch ($order->getState()) {
         // even after placement paypal can disallow to authorize/capture, but will wait until bank transfers money
         case Mage_Sales_Model_Order::STATE_PENDING_PAYMENT:
             // TODO
             break;
             // regular placement, when everything is ok
         // regular placement, when everything is ok
         case Mage_Sales_Model_Order::STATE_PROCESSING:
         case Mage_Sales_Model_Order::STATE_COMPLETE:
         case Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW:
             $order->sendNewOrderEmail();
             break;
     }
     $this->_order = $order;
 }