/** * Prepare quote, reserve order ID for specified quote * * @return string */ public function initCheckout() { $this->_quote->reserveOrderId()->save(); /** * Reset multishipping flag before any manipulations with quote address * addAddress method for quote object related on this flag */ if ($this->_quote->getIsMultiShipping()) { $this->_quote->setIsMultiShipping(false); $this->_quote->save(); } /* * want to load the correct customer information by assigning to address * instead of just loading from sales/quote_address */ $customer = Mage::getSingleton('Mage_Customer_Model_Session')->getCustomer(); if ($customer) { $this->_quote->assignCustomer($customer); } $quote = Mage::getSingleton('Mage_Checkout_Model_Session')->getQuote(); if (!Mage::getSingleton('Mage_Customer_Model_Session')->isLoggedIn() && Mage::helper('Mage_Checkout_Helper_Data')->isAllowedGuestCheckout($quote)) { $this->_prepareGuestQuote(); } return $this->_quote->getReservedOrderId(); }
/** * Reserve order ID for specified quote and start checkout on PayPal * @return string */ public function start($returnUrl, $cancelUrl) { $this->_quote->reserveOrderId()->save(); // prepare API $this->_getApi(); $this->_api->setAmount($this->_quote->getBaseGrandTotal())->setCurrencyCode($this->_quote->getBaseCurrencyCode())->setInvNum($this->_quote->getReservedOrderId())->setReturnUrl($returnUrl)->setCancelUrl($cancelUrl)->setSolutionType($this->_config->solutionType)->setPaymentAction($this->_config->paymentAction); // supress or export shipping address if ($this->_quote->getIsVirtual()) { $this->_api->setSuppressShipping(true); } else { $address = $this->_quote->getShippingAddress(); $isOverriden = 0; if (true === $address->validate()) { $isOverriden = 1; $this->_api->setAddress($address); } $this->_quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDEN, $isOverriden); $this->_quote->getPayment()->save(); } // add line items if ($this->_config->lineItemsEnabled) { list($items, $totals) = Mage::helper('paypal')->prepareLineItems($this->_quote); $this->_api->setLineItems($items)->setLineItemTotals($totals); } $this->_config->exportExpressCheckoutStyleSettings($this->_api); // call API and redirect with token $this->_api->callSetExpressCheckout(); $token = $this->_api->getToken(); $this->_redirectUrl = $this->_config->getExpressCheckoutStartUrl($token); return $token; }
/** * Reserve order ID for specified quote and start checkout on PayPal * @return string */ public function start($returnUrl, $cancelUrl) { $this->_quote->collectTotals(); if (!$this->_quote->getGrandTotal() && !$this->_quote->hasNominalItems()) { Mage::throwException(Mage::helper('paypal')->__('PayPal does not support processing orders with zero amount. To complete your purchase, proceed to the standard checkout process.')); } $this->_quote->reserveOrderId()->save(); // prepare API $this->_getApi(); $this->_api->setAmount($this->_quote->getBaseGrandTotal())->setCurrencyCode($this->_quote->getBaseCurrencyCode())->setInvNum($this->_quote->getReservedOrderId())->setReturnUrl($returnUrl)->setCancelUrl($cancelUrl)->setSolutionType($this->_config->solutionType)->setPaymentAction($this->_config->paymentAction); if ($this->_giropayUrls) { list($successUrl, $cancelUrl, $pendingUrl) = $this->_giropayUrls; $this->_api->addData(array('giropay_cancel_url' => $cancelUrl, 'giropay_success_url' => $successUrl, 'giropay_bank_txn_pending_url' => $pendingUrl)); } $this->_setBillingAgreementRequest(); // supress or export shipping address if ($this->_quote->getIsVirtual()) { $this->_api->setSuppressShipping(true); } else { $address = $this->_quote->getShippingAddress(); $isOverriden = 0; if (true === $address->validate()) { $isOverriden = 1; $this->_api->setAddress($address); } $this->_quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDEN, $isOverriden); $this->_quote->getPayment()->save(); } // add line items $paypalCart = Mage::getModel('paypal/cart', array($this->_quote)); $this->_api->setPaypalCart($paypalCart)->setIsLineItemsEnabled($this->_config->lineItemsEnabled); // add shipping options if needed and line items are available if ($this->_config->lineItemsEnabled && $this->_config->transferShippingOptions && $paypalCart->getItems()) { if (!$this->_quote->getIsVirtual() && !$this->_quote->hasNominalItems()) { if ($options = $this->_prepareShippingOptions($address, true)) { $this->_api->setShippingOptionsCallbackUrl(Mage::getUrl('*/*/shippingOptionsCallback', array('quote_id' => $this->_quote->getId())))->setShippingOptions($options); } } } // add recurring payment profiles information if ($profiles = $this->_quote->prepareRecurringPaymentProfiles()) { foreach ($profiles as $profile) { $profile->setMethodCode(Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS); if (!$profile->isValid()) { Mage::throwException($profile->getValidationErrors(true, true)); } } $this->_api->addRecurringPaymentProfiles($profiles); } $this->_config->exportExpressCheckoutStyleSettings($this->_api); // call API and redirect with token $this->_api->callSetExpressCheckout(); $token = $this->_api->getToken(); $this->_redirectUrl = $this->_config->getExpressCheckoutStartUrl($token); $this->_quote->getPayment()->unsAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT); $this->_quote->getPayment()->save(); return $token; }
/** * Convert quote model to order model * * @param Mage_Sales_Model_Quote $quote * @return Mage_Sales_Model_Order */ public function toOrder(Mage_Sales_Model_Quote $quote, $order = null) { if (!$order instanceof Mage_Sales_Model_Order) { $order = Mage::getModel('sales/order'); } /* @var $order Mage_Sales_Model_Order */ $order->setIncrementId($quote->getReservedOrderId())->setStoreId($quote->getStoreId())->setQuoteId($quote->getId())->setCustomer($quote->getCustomer()); Mage::helper('core')->copyFieldset('sales_convert_quote', 'to_order', $quote, $order); Mage::dispatchEvent('sales_convert_quote_to_order', array('order' => $order, 'quote' => $quote)); return $order; }
/** * Convert quote model to order model * * @param Mage_Sales_Model_Quote $quote * @return Mage_Sales_Model_Order */ public function toOrder(Mage_Sales_Model_Quote $quote, $order = null) { if (!$order instanceof Mage_Sales_Model_Order) { $order = Mage::getModel('sales/order'); } /* @var $order Mage_Sales_Model_Order */ $order->setIncrementId($quote->getReservedOrderId())->setStoreId($quote->getStoreId())->setQuoteId($quote->getId()); Mage::helper('core')->copyFieldset('sales_convert_quote', 'to_order', $quote, $order); if (!$quote->getCustomerId()) { $order->setCustomerId(null); } // // ->setRemoteIp($quote->getRemoteIp()) // // /** // * Customer data // */ // ->setCustomerId($quote->getCustomerId()) // ->setCustomerEmail($quote->getCustomerEmail()) // ->setCustomerPrefix($quote->getCustomerPrefix()) // ->setCustomerFirstname($quote->getCustomerFirstname()) // ->setCustomerMiddlename($quote->getCustomerMiddlename()) // ->setCustomerLastname($quote->getCustomerLastname()) // ->setCustomerSuffix($quote->getCustomerSuffix()) // ->setCustomerGroupId($quote->getCustomerGroupId()) // ->setCustomerTaxClassId($quote->getCustomerTaxClassId()) // ->setCustomerNote($quote->getCustomerNote()) // ->setCustomerNoteNotify($quote->getCustomerNoteNotify()) // ->setCustomerIsGuest($quote->getCustomerIsGuest()) // ->setCustomerDob($quote->getCustomerDob()) // // /** // * Currency data // */ // ->setBaseCurrencyCode($quote->getBaseCurrencyCode()) // ->setStoreCurrencyCode($quote->getStoreCurrencyCode()) // ->setOrderCurrencyCode($quote->getQuoteCurrencyCode()) // ->setStoreToBaseRate($quote->getStoreToBaseRate()) // ->setStoreToOrderRate($quote->getStoreToQuoteRate()) // // /** // * Another data // */ // ->setCouponCode($quote->getCouponCode()) // ->setGiftcertCode($quote->getGiftcertCode()) // ->setIsVirtual($quote->getIsVirtual()) // ->setIsMultiPayment($quote->getIsMultiPayment()) // ->setAppliedRuleIds($quote->getAppliedRuleIds()); Mage::dispatchEvent('sales_convert_quote_to_order', array('order' => $order, 'quote' => $quote)); return $order; }
private function prepareOrderNumber() { if ($this->proxyOrder->isOrderNumberPrefixSourceChannel()) { $orderNumber = $this->addPrefixToOrderNumberIfNeed($this->proxyOrder->getChannelOrderNumber()); if (Mage::helper('M2ePro/Magento')->isMagentoOrderIdUsed($orderNumber)) { $orderNumber .= '(1)'; } $this->quote->setReservedOrderId($orderNumber); return; } $orderNumber = $this->quote->getReservedOrderId(); if (empty($orderNumber)) { $orderNumber = $this->quote->getResource()->getReservedOrderId($this->quote); } $orderNumber = $this->addPrefixToOrderNumberIfNeed($orderNumber); if ($this->quote->getResource()->isOrderIncrementIdUsed($orderNumber)) { $orderNumber = $this->quote->getResource()->getReservedOrderId($this->quote); } $this->quote->setReservedOrderId($orderNumber); }
/** * Reserve order ID for specified quote and start checkout on PayPal * @return string */ public function start($returnUrl, $cancelUrl) { $this->_quote->reserveOrderId()->save(); // prepare API $this->_getApi(); $this->_api->setAmount($this->_quote->getBaseGrandTotal())->setCurrencyCode($this->_quote->getBaseCurrencyCode())->setInvNum($this->_quote->getReservedOrderId())->setReturnUrl($returnUrl)->setCancelUrl($cancelUrl)->setSolutionType($this->_config->solutionType)->setPaymentAction($this->_config->paymentAction); if ($this->_giropayUrls) { list($successUrl, $cancelUrl, $pendingUrl) = $this->_giropayUrls; $this->_api->addData(array('giropay_cancel_url' => $cancelUrl, 'giropay_success_url' => $successUrl, 'giropay_bank_txn_pending_url' => $pendingUrl)); } // supress or export shipping address if ($this->_quote->getIsVirtual()) { $this->_api->setSuppressShipping(true); } else { $address = $this->_quote->getShippingAddress(); $isOverriden = 0; if (true === $address->validate()) { $isOverriden = 1; $this->_api->setAddress($address); } $this->_quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDEN, $isOverriden); $this->_quote->getPayment()->save(); } // add line items if ($this->_config->lineItemsEnabled && Mage::helper('paypal')->doLineItemsMatchAmount($this->_quote, $this->_quote->getBaseGrandTotal())) { //For transfering line items order amount must be equal to cart total amount list($items, $totals) = Mage::helper('paypal')->prepareLineItems($this->_quote); $this->_api->setLineItems($items)->setLineItemTotals($totals); } $this->_config->exportExpressCheckoutStyleSettings($this->_api); // call API and redirect with token $this->_api->callSetExpressCheckout(); $token = $this->_api->getToken(); $this->_redirectUrl = $this->_config->getExpressCheckoutStartUrl($token); return $token; }
/** * Returns the reserved order id * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $object * @return String OrderId */ public function getOrderId($object) { $orderId = null; if ($object instanceof Mage_Sales_Model_Order) { $orderId = $object->getIncrementId(); } if ($object instanceof Mage_Sales_Model_Quote) { $orderId = $object->getReservedOrderId(); } return $orderId; }