/** * Initialize quote objects */ private function initializeQuote() { $this->quote = Mage::getModel('sales/quote'); $this->quote->setCheckoutMethod($this->proxyOrder->getCheckoutMethod()); $this->quote->setStore($this->proxyOrder->getStore()); $this->quote->save(); }
private function initializeQuote() { $this->quote = Mage::getModel('sales/quote'); $this->quote->setCheckoutMethod($this->proxyOrder->getCheckoutMethod()); $this->quote->setStore($this->proxyOrder->getStore()); $this->quote->getStore()->setData('current_currency', $this->quote->getStore()->getBaseCurrency()); $this->quote->save(); Mage::getSingleton('checkout/session')->replaceQuote($this->quote); }
/** * Place the order when customer returned from paypal * Until this moment all quote data must be valid * * @param string $token * @param string $shippingMethodCode * @return Mage_Sales_Model_Order */ public function placeOrder($token, $shippingMethodCode = null) { if ($shippingMethodCode) { $this->updateShippingMethod($shippingMethodCode); } if (!$this->_quote->getCustomerId()) { $this->_quote->setCustomerIsGuest(true)->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)->setCustomerEmail($this->_quote->getBillingAddress()->getEmail()); } $this->_ignoreAddressValidation(); $order = Mage::getModel('sales/service_quote', $this->_quote)->submit(); $this->_quote->save(); // 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: $order->sendNewOrderEmail(); break; } return $order; }
/** * Set shipping method for order. * Perform price convert and tax decr/inc * @param array $shippingDetails information about selected eBay shipping method * * @return void */ protected function _initShippingMethod($shippingDetails) { $store = $this->_quote->getStore(); // getConfig will initialize requested key with default value $store->getConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS); // Calculate shipping tax if ($this->_taxPercent > 0) { $store->setConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, $this->_productTaxClassId); if ($this->_taxIncludesShipping && $this->isShippingIncludesTax()) { $shippingDetails['price'] += $shippingDetails['price'] * $this->_taxPercent / 100; } if (!$this->_taxIncludesShipping && !$this->isShippingIncludesTax()) { $shippingDetails['price'] -= $shippingDetails['price'] / (100 + $this->_taxPercent) * $this->_taxPercent; } } else { $store->setConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, 0); } // Convert shipping price to currency $shippingConvertRate = $this->_shippingCurrencyRate == 0 ? 1 : $this->_shippingCurrencyRate; $shippingDetails['price'] = $shippingDetails['price'] / $shippingConvertRate; // Round price to 2 digs after comma $shippingDetails['price'] = round($shippingDetails['price'], 2); // Register information about shipping Mage::unregister('ebayShippingData'); Mage::register('ebayShippingData', $shippingDetails); $this->_quote->getShippingAddress()->setShippingMethod('m2eproshipping_m2eproshipping'); $this->_quote->getShippingAddress()->setCollectShippingRates(true); $this->_quote->collectTotals(); $this->_quote->save(); }
/** * 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->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(); $parameters = array('quote' => $this->_quote); $service = Mage::getModel('Mage_Sales_Model_Service_Quote', $parameters); $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 // 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; }
/** * Makes Quote available for Magento Core classes * * @param Mage_Sales_Model_Quote $quote */ public function populuateQuote(Mage_Sales_Model_Quote &$quote) { $quote->save(); $quote = Mage::getModel('sales/quote')->load($quote->getId()); Mage::getSingleton('checkout/cart')->setQuote($quote); Mage::getSingleton('checkout/session')->setQuoteId($quote->getId()); Mage::getSingleton('checkout/type_onepage')->setQuote($quote); }
public function save() { $this->_order->setStoreId($this->_getStore()->getId()); $this->_order->createFromQuoteAddress($this->_quote->getShippingAddress()); $this->_order->validate(); $this->_order->setInitialStatus(); $this->_order->save(); $this->_order->setCreatedAt($this->_getRandomDate()); $this->_order->save(); $this->_quote->setIsActive(false); $this->_quote->save(); return $this; }
/** * Place the order and recurring payment profiles when customer returned from paypal * Until this moment all quote data must be valid * * @param string $workOrderId * @param string $shippingMethodCode */ public function place($workOrderId, $shippingMethodCode = null) { if ($shippingMethodCode) { $this->updateShippingMethod($shippingMethodCode); } $isNewCustomer = false; switch ($this->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(); $order = $service->getOrder(); if (!$order) { return; } $this->_billingAgreement = $order->getPayment()->getBillingAgreement(); 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; }
/** * 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) { $this->updateShippingMethod($shippingMethodCode); $isNewCustomer = $this->_prepareQuote(); $this->_ignoreAddressValidation(); $this->_quote->collectTotals(); $this->_getApi(); $payerId = $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_PAYER_ID); $doExpressReply = $this->_api->doExpressCheckout($this->_quote, $token, $payerId); $doAuthorizationReply = $this->_api->doAuthorization($this->_quote); $this->_quote->getPayment()->importData(array_merge($doExpressReply, $doAuthorizationReply)); $service = Mage::getModel('sales/service_quote', $this->_quote); try { $service->submitAll(); // Any exceptions thrown from submitAll indicate an order that failed // to be created. In any such cases, the payment auth needs to be voided. } catch (Exception $e) { $this->_api->doVoidQuote($this->_quote); // Throw an exception for the controller to handle. Needs to indicate // the failure to complete the PayPal payment as the PayPal process // needs to be restarted once the auth was performed. throw Mage::exception('EbayEnterprise_PayPal', $this->_helper->__(EbayEnterprise_Paypal_Model_Express_Api::EBAYENTERPRISE_PAYPAL_API_FAILED)); } $this->_quote->save(); if ($isNewCustomer) { try { $this->_involveNewCustomer(); } catch (Exception $e) { $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e)); } } $order = $service->getOrder(); if (!$order) { return; } switch ($order->getState()) { // Even after placement, paypal can disallow authorize/capture case Mage_Sales_Model_Order::STATE_PENDING_PAYMENT: 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; Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $this->_quote)); }
/** * Retrieve customer cart quote object model * * @return Mage_Sales_Model_Quote */ public function getCustomerCart() { if (!is_null($this->_cart)) { return $this->_cart; } $this->_cart = Mage::getModel('sales/quote'); if ($this->getSession()->getCustomer()->getId()) { $this->_cart->setStore($this->getSession()->getStore())->loadByCustomer($this->getSession()->getCustomer()->getId()); if (!$this->_cart->getId()) { $this->_cart->assignCustomer($this->getSession()->getCustomer()); $this->_cart->save(); } } return $this->_cart; }
/** * Place the order when customer returned from paypal * Until this moment all quote data must be valid * * @return array */ public function saveOrder() { $this->_ignoreAddressValidation(); $order = Mage::getModel('sales/service_quote', $this->_quote)->submit(); $this->_quote->save(); /** * Prepare session to success or cancellation page */ $quoteId = $this->_quote->getId(); $this->_getCheckoutSession()->setLastQuoteId($quoteId)->setLastSuccessQuoteId($quoteId)->setLastOrderId($order->getId())->setLastRealOrderId($order->getIncrementId()); if ($order->getState() == Mage_Sales_Model_Order::STATE_PROCESSING) { try { $order->sendNewOrderEmail(); } catch (Exception $e) { Mage::logException($e); } } return array(); }
/** * 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) { $this->updateShippingMethod($shippingMethodCode); $isNewCustomer = $this->_prepareQuote(); $this->_ignoreAddressValidation(); $this->_quote->collectTotals(); $this->_getApi(); $payerId = $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_PAYER_ID); $doExpressReply = $this->_api->doExpressCheckout($this->_quote, $token, $payerId); $doAuthorizationReply = $this->_api->doAuthorization($this->_quote); $this->_quote->getPayment()->importData(array_merge($doExpressReply, $doAuthorizationReply)); $service = Mage::getModel('sales/service_quote', $this->_quote); $service->submitAll(); $this->_quote->save(); if ($isNewCustomer) { try { $this->_involveNewCustomer(); } catch (Exception $e) { $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e)); } } $order = $service->getOrder(); if (!$order) { return; } switch ($order->getState()) { // Even after placement, paypal can disallow authorize/capture case Mage_Sales_Model_Order::STATE_PENDING_PAYMENT: 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; Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $this->_quote)); }
/** * Place the order when customer returned from paypal * Until this moment all quote data must be valid * * @param string $token * @param string $shippingMethodCode * @return Mage_Sales_Model_Order */ public function placeOrder($token, $shippingMethodCode = null) { if ($shippingMethodCode) { $this->updateShippingMethod($shippingMethodCode); } $this->_ignoreAddressValidation(); $order = Mage::getModel('sales/service_quote', $this->_quote)->submit(); $this->_quote->save(); 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: if ($this->_config->invoiceEmailCopy && $order->getPayment()->getCreatedInvoice()) { $order->sendNewOrderEmail(); } break; } return $order; }
/** * 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; }
/** * Set the coupon code on the quote * * @param Mage_Sales_Model_Quote * @param $couponCode */ public function setCouponCode(Mage_Sales_Model_Quote $quote, $couponCode) { $quote->setCouponCode($couponCode); $quote->setTotalsCollectedFlag(false)->collectTotals(); $quote->save(); }
/** * Add coupon from this system to quote * * @param Mage_Sales_Model_Quote $quote * @param ShopgateCartBase $order * * @return Mage_Sales_Model_Quote * @throws ShopgateLibraryException */ protected function _setQuoteShopCoupons($quote, $order) { if (count($order->getExternalCoupons()) > 1) { throw new ShopgateLibraryException(ShopgateLibraryException::COUPON_TOO_MANY_COUPONS); } foreach ($order->getExternalCoupons() as $coupon) { /* @var $coupon ShopgateShopgateCoupon */ $couponInfos = $this->jsonDecode($coupon->getInternalInfo(), true); if ($order instanceof ShopgateOrder) { if (!$coupon->getInternalInfo()) { throw new ShopgateLibraryException(ShopgateLibraryException::COUPON_NOT_VALID, 'Field "internal_info" is empty.'); } /** @var Mage_SalesRule_Model_Coupon $mageCoupon */ if ($this->_getConfigHelper()->getIsMagentoVersionLower1410()) { $mageCoupon = Mage::getModel('salesrule/rule')->load($couponInfos["coupon_id"]); } else { $mageCoupon = Mage::getModel('salesrule/coupon')->load($couponInfos["coupon_id"]); } $count = (int) $mageCoupon->getTimesUsed(); $count--; $mageCoupon->setTimesUsed($count); $mageCoupon->save(); } $quote->setCouponCode($coupon->getCode()); foreach ($quote->getAllAddresses() as $address) { $address->setCouponCode($coupon->getCode()); } $quote->setTotalsCollectedFlag(false); $quote->collectTotals(); if ($this->_errorOnInvalidCoupon) { if ($coupon->getCode() != $quote->getCouponCode()) { throw new ShopgateLibraryException(ShopgateLibraryException::COUPON_NOT_VALID, 'Code transferred by Shopgate"' . $coupon->getCode() . '" != "' . $quote->getCouponCode() . '" code in Magento'); } } $quote->save(); } return $quote; }
/** * @param Mage_Sales_Model_Quote $quote */ protected function reactivateQuote(Mage_Sales_Model_Quote $quote) { if ($quote->getId()) { /* @note: Reset reserved_order_id, Magento up to and including version 1.7 has a bug in Mage_Sales_Model_Resource_Quote::isOrderIncrementIdUsed() * They cast the orderIncrementId to (int), which breaks the checkout/cart for all non-numerical incrementIds * (Causes Integrity Constraint Violation, because orderIncrementId already exists */ $quote->setData('reserved_order_id', ''); $quote->setIsActive(true); $quote->save(); } }
/** * 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; }
/** * Save quote with prevention checking * * @return Ikantam_Buyback_Model_Quote */ public function save() { if ($this->_preventSaving) { return $this; } return parent::save(); }
* http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * * @category Magento * @package Mage_Sales * @subpackage integration_tests * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $product = new Mage_Catalog_Model_Product(); $product->setTypeId('simple')->setId(1)->setAttributeSetId(4)->setName('Simple Product')->setSku('simple')->setPrice(10)->setStockData(array('use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1))->setMetaTitle('meta title')->setMetaKeyword('meta keyword')->setMetaDescription('meta description')->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->save(); $product->load(1); $addressData = (include __DIR__ . '/address_data.php'); $billingAddress = new Mage_Sales_Model_Quote_Address($addressData); $billingAddress->setAddressType('billing'); $shippingAddress = clone $billingAddress; $shippingAddress->setId(null)->setAddressType('shipping'); $quote = new Mage_Sales_Model_Quote(); $quote->setCustomerIsGuest(true)->setStoreId(Mage::app()->getStore()->getId())->setReservedOrderId('test01')->setBillingAddress($billingAddress)->setShippingAddress($shippingAddress)->addProduct($product); $quote->getPayment()->setMethod('checkmo'); $quote->setIsMultiShipping('1'); $quote->save();
/** * Call Capture API (do the Capture only, must Authorized previously) * * @param Mage_Sales_Model_Order_Payment $payment * @param $amount * @return Eway_Rapid31_Model_Request_Direct */ public function doCapturePayment(Mage_Sales_Model_Quote $quote, $amount) { // Empty Varien_Object's data $this->unsetData(); $paymentParam = Mage::getModel('ewayrapid/field_payment'); $paymentParam->setTotalAmount($amount)->setCurrencyCode($quote->getBaseCurrencyCode()); $this->setPayment($paymentParam); $this->setTransactionId($quote->getTransactionId()); $this->setMethod(Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT); $response = $this->_doRapidAPI('CapturePayment'); if ($response->isSuccess()) { $quote->setTransactionId($response->getTransactionID()); $quote->save(); return $quote; } else { Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while doing the capture. Please try again. (Error message: %s)', $response->getMessage())); } }