Exemplo n.º 1
0
 protected function _afterLoad()
 {
     $productCollection = $this->_getProductCollection();
     $recollectQuote = false;
     foreach ($this as $item) {
         $product = $productCollection->getItemById($item->getProductId());
         if ($this->_quote) {
             $item->setQuote($this->_quote);
         }
         if (!$product) {
             $item->isDeleted(true);
             $recollectQuote = true;
             continue;
         }
         if ($item->getSuperProductId()) {
             $superProduct = $productCollection->getItemById($item->getSuperProductId());
         } else {
             $superProduct = null;
         }
         $itemProduct = clone $product;
         if ($superProduct) {
             $itemProduct->setSuperProduct($superProduct);
             $item->setSuperProduct($superProduct);
         }
         $item->importCatalogProduct($itemProduct);
         $item->checkData();
     }
     if ($recollectQuote && $this->_quote) {
         $this->_quote->collectTotals();
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Add products to items and item options
  *
  * @return Mage_Sales_Model_Mysql4_Quote_Item_Collection
  */
 protected function _assignProducts()
 {
     Varien_Profiler::start('QUOTE:' . __METHOD__);
     $productIds = array();
     foreach ($this as $item) {
         $productIds[] = $item->getProductId();
     }
     $this->_productIds = array_merge($this->_productIds, $productIds);
     $productCollection = Mage::getModel('catalog/product')->getCollection()->setStoreId($this->getStoreId())->addIdFilter($this->_productIds)->addAttributeToSelect(Mage::getSingleton('sales/quote_config')->getProductAttributes())->addOptionsToResult()->addStoreFilter()->addUrlRewrite();
     Mage::dispatchEvent('sales_quote_item_collection_products_after_load', array('product_collection' => $productCollection));
     $recollectQuote = false;
     foreach ($this as $item) {
         if ($product = $productCollection->getItemById($item->getProductId())) {
             $product->setCustomOptions(array());
             foreach ($item->getOptions() as $option) {
                 /**
                  * Call type specified logic for product associated with quote item
                  */
                 $product->getTypeInstance(true)->assignProductToOption($productCollection->getItemById($option->getProductId()), $option, $product);
             }
             $item->setProduct($product);
         } else {
             $item->isDeleted(true);
             $recollectQuote = true;
         }
         $item->checkData();
     }
     if ($recollectQuote && $this->_quote) {
         $this->_quote->collectTotals();
     }
     Varien_Profiler::stop('QUOTE:' . __METHOD__);
     return $this;
 }
Exemplo n.º 3
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->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;
 }
Exemplo n.º 4
0
 protected function _placeOrder($checkoutMessage, $orderStatus = 'pending', $notifyCreateOrder = false)
 {
     $this->_quote->collectTotals();
     $this->_quote->reserveOrderId();
     error_reporting(E_ERROR);
     $service = Mage::getModel('sales/service_quote', $this->_quote);
     // If file not exist may catch warring
     error_reporting(E_ALL);
     if ($service != false && method_exists($service, 'submitAll')) {
         // Magento version 1.4.1.x
         //  $service = Mage::getModel('sales/service_quote', $quote);
         $service->submitAll();
         $orderObj = $service->getOrder();
     } else {
         // Magento version 1.4.0.x , 1.3.x
         $convertQuoteObj = Mage::getSingleton('sales/convert_quote');
         $orderObj = $convertQuoteObj->addressToOrder($this->_quote->getShippingAddress());
         $orderObj->setBillingAddress($convertQuoteObj->addressToOrderAddress($this->_quote->getBillingAddress()));
         $orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($this->_quote->getShippingAddress()));
         $orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($this->_quote->getPayment()));
         $items = $this->_quote->getShippingAddress()->getAllItems();
         foreach ($items as $item) {
             //@var $item Mage_Sales_Model_Quote_Item
             $orderItem = $convertQuoteObj->itemToOrderItem($item);
             if ($item->getParentItem()) {
                 $orderItem->setParentItem($orderObj->getItemByQuoteItemId($item->getParentItem()->getId()));
             }
             $orderObj->addItem($orderItem);
         }
         $orderObj->setCanShipPartiallyItem(false);
         $orderObj->place();
     }
     $orderMessages = '';
     $notifyMessages = $this->_processNotifyMessage();
     if ($checkoutMessage || $notifyMessages) {
         $orderMessages .= '<br /><b><u>' . Mage::helper('M2ePro')->__('M2E Pro Notes') . ':</u></b><br /><br />';
         if ($checkoutMessage) {
             $orderMessages .= '<b>' . Mage::helper('M2ePro')->__('Checkout Message From Buyer') . ':</b>';
             $orderMessages .= $checkoutMessage . '<br />';
         }
         if ($notifyMessages) {
             $orderMessages .= $notifyMessages;
         }
     }
     // Adding notification to order
     $orderObj->addStatusToHistory($orderStatus, $orderMessages, false);
     $orderObj->save();
     // --------------------
     Mage::helper('M2ePro/Module')->getConfig()->setGroupValue('/synchronization/orders/', 'current_magento_order_id', $orderObj->getId());
     $this->setFatalErrorHandler();
     // --------------------
     // Send Notification to customer after create order
     if ($notifyCreateOrder) {
         // Send new order E-mail only if select such mode
         $orderObj->sendNewOrderEmail();
     }
     return $orderObj;
 }
 /**
  * Set shipping method to quote, if needed
  * @param string $methodCode
  */
 public function updateShippingMethod($methodCode)
 {
     if (!$this->_quote->getIsVirtual() && ($shippingAddress = $this->_quote->getShippingAddress())) {
         if ($methodCode != $shippingAddress->getShippingMethod()) {
             $this->_ignoreAddressValidation();
             $shippingAddress->setShippingMethod($methodCode)->setCollectShippingRates(true);
             $this->_quote->collectTotals()->save();
         }
     }
 }
 protected function _afterLoad()
 {
     if (VPROF) {
         Varien_Profiler::start('TEST1: ' . __METHOD__);
     }
     $productCollection = $this->_getProductCollection();
     if (VPROF) {
         Varien_Profiler::stop('TEST1: ' . __METHOD__);
     }
     $recollectQuote = false;
     foreach ($this as $item) {
         if (VPROF) {
             Varien_Profiler::start('TEST2: ' . __METHOD__);
         }
         if ($productCollection) {
             $product = $productCollection->getItemById($item->getProductId());
         } else {
             $product = false;
         }
         if ($this->_quote) {
             $item->setQuote($this->_quote);
         }
         if (!$product) {
             $item->isDeleted(true);
             $recollectQuote = true;
             continue;
         }
         if ($item->getSuperProductId()) {
             $superProduct = $productCollection->getItemById($item->getSuperProductId());
             if (!$superProduct) {
                 $item->isDeleted(true);
                 $recollectQuote = true;
                 continue;
             }
         } else {
             $superProduct = null;
         }
         $itemProduct = clone $product;
         if ($superProduct) {
             $itemProduct->setSuperProduct($superProduct);
             $item->setSuperProduct($superProduct);
         }
         $item->importCatalogProduct($itemProduct);
         $item->checkData();
         if (VPROF) {
             Varien_Profiler::stop('TEST2: ' . __METHOD__);
         }
     }
     if ($recollectQuote && $this->_quote) {
         $this->_quote->collectTotals();
     }
     return $this;
 }
Exemplo n.º 7
0
 /**
  * @magentoDataFixture Mage/Catalog/_files/product_virtual.php
  * @magentoDataFixture Mage/Sales/_files/quote.php
  */
 public function testCollectTotalsWithVirtual()
 {
     $quote = new Mage_Sales_Model_Quote();
     $quote->load('test01', 'reserved_order_id');
     $product = new Mage_Catalog_Model_Product();
     $product->load(21);
     $quote->addProduct($product);
     $quote->collectTotals();
     $this->assertEquals(2, $quote->getItemsQty());
     $this->assertEquals(1, $quote->getVirtualItemsQty());
     $this->assertEquals(20, $quote->getGrandTotal());
     $this->assertEquals(20, $quote->getBaseGrandTotal());
 }
Exemplo n.º 8
0
 /**
  * Build quote object
  *
  * @throws Exception
  */
 public function buildQuote()
 {
     try {
         // do not change invoke order
         // --------------------
         $this->initializeQuote();
         $this->initializeCustomer();
         $this->initializeAddresses();
         $this->configureStore();
         $this->initializeCurrency();
         $this->initializeShippingMethodData();
         $this->initializeQuoteItems();
         $this->initializePaymentMethodData();
         //$this->quote->setTotalsCollectedFlag(false);
         $this->quote->collectTotals()->save();
         $this->quote->reserveOrderId();
         // --------------------
     } catch (Exception $e) {
         $this->quote->setIsActive(false)->save();
         throw $e;
     }
 }
 /**
  * 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));
 }
Exemplo n.º 10
0
 /**
  * Add products to items and item options
  *
  * @return Mage_Sales_Model_Resource_Quote_Item_Collection
  */
 protected function _assignProducts()
 {
     Magento_Profiler::start('QUOTE:' . __METHOD__);
     $productIds = array();
     foreach ($this as $item) {
         $productIds[] = (int) $item->getProductId();
     }
     $this->_productIds = array_merge($this->_productIds, $productIds);
     $productCollection = Mage::getModel('Mage_Catalog_Model_Product')->getCollection()->setStoreId($this->getStoreId())->addIdFilter($this->_productIds)->addAttributeToSelect(Mage::getSingleton('Mage_Sales_Model_Quote_Config')->getProductAttributes())->addOptionsToResult()->addStoreFilter()->addUrlRewrite()->addTierPriceData();
     Mage::dispatchEvent('prepare_catalog_product_collection_prices', array('collection' => $productCollection, 'store_id' => $this->getStoreId()));
     Mage::dispatchEvent('sales_quote_item_collection_products_after_load', array('product_collection' => $productCollection));
     $recollectQuote = false;
     foreach ($this as $item) {
         $product = $productCollection->getItemById($item->getProductId());
         if ($product) {
             $product->setCustomOptions(array());
             $qtyOptions = array();
             $optionProductIds = array();
             foreach ($item->getOptions() as $option) {
                 /**
                  * Call type specified logic for product associated with quote item
                  */
                 $product->getTypeInstance()->assignProductToOption($productCollection->getItemById($option->getProductId()), $option, $product);
                 if (is_object($option->getProduct()) && $option->getProduct()->getId() != $product->getId()) {
                     $optionProductIds[$option->getProduct()->getId()] = $option->getProduct()->getId();
                 }
             }
             if ($optionProductIds) {
                 foreach ($optionProductIds as $optionProductId) {
                     $qtyOption = $item->getOptionByCode('product_qty_' . $optionProductId);
                     if ($qtyOption) {
                         $qtyOptions[$optionProductId] = $qtyOption;
                     }
                 }
             }
             $item->setQtyOptions($qtyOptions);
             $item->setProduct($product);
         } else {
             $item->isDeleted(true);
             $recollectQuote = true;
         }
         $item->checkData();
     }
     if ($recollectQuote && $this->_quote) {
         $this->_quote->collectTotals();
     }
     Magento_Profiler::stop('QUOTE:' . __METHOD__);
     return $this;
 }
Exemplo n.º 11
0
 /**
  * Collect totals patched for magento issue #26145
  *
  * @return Mage_Sales_Model_Quote
  */
 public function collectTotals()
 {
     /**
      * patch for magento issue #26145
      */
     if (!$this->getTotalsCollectedFlag()) {
         $items = $this->getAllItems();
         foreach ($items as $item) {
             $item->setData('calculation_price', null);
             $item->setData('original_price', null);
         }
     }
     parent::collectTotals();
     return $this;
 }
Exemplo n.º 12
0
 /**
  * Specify quote payment method
  *
  * @param array $data
  * @return array
  */
 public function savePayment($data)
 {
     if ($this->_quote->isVirtual()) {
         $this->_quote->getBillingAddress()->setPaymentMethod($this->_methodType);
     } else {
         $this->_quote->getShippingAddress()->setPaymentMethod($this->_methodType);
     }
     $payment = $this->_quote->getPayment();
     $data['method'] = $this->_methodType;
     $payment->importData($data);
     $email = isset($data['payer']) ? $data['payer'] : null;
     $payment->setAdditionalInformation(self::PAYMENT_INFO_PAYER_EMAIL, $email);
     $payment->setAdditionalInformation(self::PAYMENT_INFO_TRANSACTION_ID, isset($data['transaction_id']) ? $data['transaction_id'] : null);
     $this->_quote->setCustomerEmail($email);
     $this->_quote->collectTotals()->save();
     return array();
 }
Exemplo n.º 13
0
 /**
  * IFrame handler for submitted configuration for quote item
  *
  * @return Mage_Adminhtml_Customer_Cart_Product_Composite_CartController
  */
 public function updateAction()
 {
     $updateResult = new Varien_Object();
     try {
         $this->_initData();
         $buyRequest = new Varien_Object($this->getRequest()->getParams());
         $this->_quote->updateItem($this->_quoteItem->getId(), $buyRequest);
         $this->_quote->collectTotals()->save();
         $updateResult->setOk(true);
     } catch (Exception $e) {
         $updateResult->setError(true);
         $updateResult->setMessage($e->getMessage());
     }
     $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname'));
     Mage::getSingleton('Mage_Adminhtml_Model_Session')->setCompositeProductResult($updateResult);
     $this->_redirect('*/catalog_product/showUpdateResult');
     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 $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));
 }
Exemplo n.º 15
0
 public function render()
 {
     $customer = $this->_getCustomer();
     $this->_quote->setStore($this->_getStore())->setCustomer($customer);
     $this->_quote->getBillingAddress()->importCustomerAddress($customer->getDefaultBillingAddress());
     $this->_quote->getShippingAddress()->importCustomerAddress($customer->getDefaultShippingAddress());
     $productCount = rand(3, 10);
     for ($i = 0; $i < $productCount; $i++) {
         $product = $this->_getRandomProduct();
         if ($product) {
             $product->setQuoteQty(1);
             $this->_quote->addCatalogProduct($product);
         }
     }
     $this->_quote->getPayment()->setMethod('checkmo');
     $this->_quote->getShippingAddress()->setShippingMethod('freeshipping_freeshipping');
     //->collectTotals()->save();
     $this->_quote->getShippingAddress()->setCollectShippingRates(true);
     $this->_quote->collectTotals()->save();
     $this->_quote->save();
     return $this;
 }
Exemplo n.º 16
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);
     }
     if (!$this->_quote->getCustomerId()) {
         $this->_quote->setCustomerIsGuest(true)->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)->setCustomerEmail($this->_quote->getBillingAddress()->getEmail());
     }
     $this->_ignoreAddressValidation();
     $this->_quote->collectTotals();
     $service = Mage::getModel('sales/service_quote', $this->_quote);
     $service->submitAll();
     $this->_quote->save();
     $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;
 }
Exemplo n.º 17
0
 /**
  * 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;
 }
 /**
  * Send do express PayPal checkout request and do authorize PayPal request for the given
  * multi-shipping quote and import the reply data to the quote payment.
  *
  * @param  Mage_Sales_Model_Quote
  * @return self
  */
 public function processPaypalExpressPayment(Mage_Sales_Model_Quote $quote)
 {
     /** @var Mage_Sales_Model_Quote_Payment */
     $payment = $quote->getPayment();
     /** @var Varien_Object */
     $paypalData = new Varien_Object($payment->getAdditionalInformation());
     /** @var string */
     $token = $paypalData->getPaypalExpressCheckoutToken();
     /** @var string */
     $payerId = $paypalData->getPaypalExpressCheckoutPayerId();
     /** @var string */
     $paymentMethod = $payment->getMethod();
     if ($quote->getIsMultiShipping() && $paymentMethod === EbayEnterprise_PayPal_Model_Method_Express::CODE) {
         // Collecting totals in order to get eBay Enterprise Tax total for this quote
         $quote->collectTotals();
         /** @var array */
         $data = array_merge($this->api->doExpressCheckout($quote, $token, $payerId), $this->api->doAuthorization($quote));
         $payment->importData($data);
     }
     return $this;
 }
 /**
  * Recollect quote totals to update amounts based on newly received tax
  * data. This collect totals call is expected to happen recursively within
  * collect totals. The flags in eb2ccore/session are expected to prevent
  * going beyond a single recursive call to collect totals. As an additional
  * precaution, a lock is also used to prevent unexpected recursion.
  *
  * @param Mage_Sales_Model_Quote
  * @return Mage_Sales_Model_Quote
  */
 protected function recollectTotals(Mage_Sales_Model_Quote $quote)
 {
     // Guard against unexpected recursion. Session flags should prevent
     // this but need to be sure this can't trigger infinite recursion.
     // If the lock is free (set to false), expect to not be within a recursive
     // collectTotals triggered by taxes.
     if (!self::$lockRecollectTotals) {
         // Acquire the lock prior to triggering the recursion. Prevents taxes
         // from being able to trigger further recursion.
         self::$lockRecollectTotals = true;
         $quote->collectTotals();
         // Free the lock once we're clear of the recursive collectTotals.
         self::$lockRecollectTotals = false;
     } else {
         // Do not expect further recursive attempts to occur. Something
         // would be potentially wrong with the session flags if it does.
         $this->logger->warning('Attempted to recollect totals for taxes during a recursive collection. Additional collection averted to prevent further recursion.', $this->logContext->getMetaData(__CLASS__));
     }
     return $quote;
 }
Exemplo n.º 20
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;
 }
Exemplo n.º 21
0
 /**
  * Returns all items from quote and validates
  * them by quantity and addresses.
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param ShopgateCart           $cart
  *
  * @return array
  */
 public function getItems($quote, ShopgateCart $cart)
 {
     $validator = Mage::getModel('shopgate/shopgate_cart_validation_stock');
     $items = array();
     $quote->collectTotals();
     /** @var Mage_Sales_Model_Quote_Item $_item */
     foreach ($quote->getAllVisibleItems() as $_item) {
         /** @var Mage_Catalog_Model_Product $_item */
         $items[] = $validator->validateStock($_item, $_item->getPriceInclTax(), $_item->getPrice());
     }
     foreach (Mage::helper('shopgate')->fetchMissingQuoteItems($cart, $quote) as $_item) {
         $item = Mage::helper('shopgate')->generateShopgateCartItem($_item->getProduct());
         $catchedErrors = $quote->getShopgateError();
         $sgError = ShopgateLibraryException::CART_ITEM_OUT_OF_STOCK;
         if ($catchedErrors) {
             if (array_key_exists($item->getItemNumber(), $catchedErrors)) {
                 foreach ($catchedErrors[$item->getItemNumber()] as $error) {
                     if ($error == Mage::helper('catalog')->__('The text is too long')) {
                         $sgError = ShopgateLibraryException::CART_ITEM_INPUT_VALIDATION_FAILED;
                     }
                 }
             }
         }
         $item->setError($sgError);
         $item->setErrorText(ShopgateLibraryException::getMessageFor($sgError));
         $items[] = $item;
     }
     return $items;
 }
 /**
  * @param Mage_Sales_Model_Quote     $quote
  * @param Adyen_Subscription_Model_Subscription $subscription
  *
  * @return Mage_Sales_Model_Order
  * @throws Adyen_Subscription_Exception|Exception
  */
 public function createOrder(Mage_Sales_Model_Quote $quote, Adyen_Subscription_Model_Subscription $subscription)
 {
     Mage::dispatchEvent('adyen_subscription_quote_createorder_before', array('subscription' => $subscription, 'quote' => $quote));
     try {
         if (!$subscription->canCreateOrder()) {
             Mage::helper('adyen_subscription')->logOrderCron("Not allowed to create order from quote");
             Adyen_Subscription_Exception::throwException(Mage::helper('adyen_subscription')->__('Not allowed to create order from quote'));
         }
         foreach ($quote->getAllItems() as $item) {
             /** @var Mage_Sales_Model_Quote_Item $item */
             $item->getProduct()->setData('is_created_from_subscription_item', $item->getData('subscription_item_id'));
         }
         $quote->collectTotals();
         $service = Mage::getModel('sales/service_quote', $quote);
         $service->submitAll();
         $order = $service->getOrder();
         // Save order addresses at subscription when they're currently quote addresses
         $subscriptionBillingAddress = Mage::getModel('adyen_subscription/subscription_address')->getSubscriptionAddress($subscription, self::ADDRESS_TYPE_BILLING);
         if ($subscriptionBillingAddress->getSource() == self::ADDRESS_SOURCE_QUOTE) {
             $subscriptionBillingAddress->initAddress($subscription, $order->getBillingAddress())->save();
         }
         $subscriptionShippingAddress = Mage::getModel('adyen_subscription/subscription_address')->getSubscriptionAddress($subscription, self::ADDRESS_TYPE_SHIPPING);
         if ($subscriptionShippingAddress->getSource() == self::ADDRESS_SOURCE_QUOTE) {
             $subscriptionShippingAddress->initAddress($subscription, $order->getShippingAddress())->save();
         }
         $orderAdditional = $subscription->getOrderAdditional($order, true)->save();
         $quoteAdditional = $subscription->getActiveQuoteAdditional()->setOrder($order)->save();
         $subscription->setErrorMessage(null);
         $subscriptionHistory = null;
         //Save history
         if ($subscription->getStatus() == $subscription::STATUS_ORDER_ERROR || $subscription->getStatus() == $subscription::STATUS_PAYMENT_ERROR) {
             $subscription->setStatus($subscription::STATUS_ACTIVE);
             $subscriptionHistory = Mage::getModel('adyen_subscription/subscription_history');
             $subscriptionHistory->createHistoryFromSubscription($subscription);
         }
         $subscription->setScheduledAt($subscription->calculateNextScheduleDate());
         $transaction = Mage::getModel('core/resource_transaction');
         $transaction->addObject($subscription)->addObject($orderAdditional)->addObject($quoteAdditional)->addObject($order);
         if ($subscriptionHistory) {
             $transaction->addObject($subscriptionHistory);
         }
         $transaction->save();
         Mage::helper('adyen_subscription')->logOrderCron(sprintf("Successful created order (#%s) for subscription (#%s)", $order->getId(), $subscription->getId()));
         $order = $service->getOrder();
         Mage::dispatchEvent('adyen_subscription_quote_createorder_after', array('subscription' => $subscription, 'quote' => $quote, 'order' => $order));
         return $order;
     } catch (Mage_Payment_Exception $e) {
         Mage::helper('adyen_subscription')->logOrderCron(sprintf("Error in subscription (#%s) creating order from quote (#%s) error is: %s", $subscription->getId(), $quote->getId(), $e->getMessage()));
         if (isset($order)) {
             $order->delete();
         }
         $subscription->setStatus($subscription::STATUS_PAYMENT_ERROR);
         $subscription->setErrorMessage($e->getMessage());
         $subscription->save();
         Mage::dispatchEvent('adyen_subscription_quote_createorder_fail', array('subscription' => $subscription, 'status' => $subscription::STATUS_PAYMENT_ERROR, 'error' => $e->getMessage()));
         throw $e;
     } catch (Exception $e) {
         Mage::helper('adyen_subscription')->logOrderCron(sprintf("Error in subscription (#%s) creating order from quote (#%s) error is: %s", $subscription->getId(), $quote->getId(), $e->getMessage()));
         if (isset($order)) {
             $order->delete();
         }
         $subscription->setStatus($subscription::STATUS_ORDER_ERROR);
         $subscription->setErrorMessage($e->getMessage());
         $subscription->save();
         Mage::dispatchEvent('adyen_subscription_quote_createorder_fail', array('subscription' => $subscription, 'status' => $subscription->getStatus(), 'error' => $e->getMessage()));
         throw $e;
     }
 }
Exemplo n.º 23
0
 /**
  * @param Mage_Sales_Model_Quote     $quote
  * @param Adyen_Subscription_Model_Subscription $subscription
  *
  * @return Mage_Sales_Model_Order
  * @throws Adyen_Subscription_Exception|Exception
  */
 public function createOrder(Mage_Sales_Model_Quote $quote, Adyen_Subscription_Model_Subscription $subscription)
 {
     Mage::dispatchEvent('adyen_subscription_quote_createorder_before', array('subscription' => $subscription, 'quote' => $quote));
     try {
         $subscription->getResource()->beginTransaction();
         if (!$subscription->canCreateOrder()) {
             Mage::helper('adyen_subscription')->logOrderCron("Not allowed to create order from quote");
             Adyen_Subscription_Exception::throwException(Mage::helper('adyen_subscription')->__('Not allowed to create order from quote'));
         }
         /**
          * only go into the visible items because bundles should use default final price
          */
         foreach ($quote->getAllVisableItems() as $item) {
             /** @var Mage_Sales_Model_Quote_Item $item */
             $item->getProduct()->setData('is_created_from_subscription_item', $item->getData('subscription_item_id'));
         }
         $quote->collectTotals();
         $service = Mage::getModel('sales/service_quote', $quote);
         $service->submitAll();
         $order = $service->getOrder();
         if (!$order instanceof Mage_Sales_Model_Order) {
             Adyen_Subscription_Exception::throwException(Mage::helper('adyen_subscription')->__("Couldn't create order from quote, probably no visible items"));
         }
         // Save order addresses at subscription when they're currently quote addresses
         $subscriptionBillingAddress = Mage::getModel('adyen_subscription/subscription_address')->getSubscriptionAddress($subscription, self::ADDRESS_TYPE_BILLING);
         if ($subscriptionBillingAddress->getSource() == self::ADDRESS_SOURCE_QUOTE) {
             $subscriptionBillingAddress->initAddress($subscription, $order->getBillingAddress())->save();
         }
         $subscriptionShippingAddress = Mage::getModel('adyen_subscription/subscription_address')->getSubscriptionAddress($subscription, self::ADDRESS_TYPE_SHIPPING);
         if ($subscriptionShippingAddress->getSource() == self::ADDRESS_SOURCE_QUOTE) {
             $subscriptionShippingAddress->initAddress($subscription, $order->getShippingAddress())->save();
         }
         $subscription->getOrderAdditional($order, true)->save();
         $subscription->getActiveQuoteAdditional()->setOrder($order)->save();
         $subscription->setActive();
         $subscription->setScheduledAt($subscription->calculateNextScheduleDate());
         $subscription->save();
         Mage::helper('adyen_subscription')->logOrderCron(sprintf("Successful created order (%s) for subscription (%s)", $order->getId(), $subscription->getId()));
         $order->save();
         $subscription->getResource()->commit();
     } catch (Adyen_Payment_Exception $e) {
         // 1. rollback everything
         $subscription->getResource()->rollBack();
         // 2. log the error to the debuglog
         Mage::helper('adyen_subscription')->logOrderCron(sprintf("Error in subscription (%s) creating order from quote (%s) error is: %s", $subscription->getId(), $quote->getId(), $e->getMessage()));
         // 3. save the error on the subscription
         $subscription->setStatus($subscription::STATUS_PAYMENT_ERROR);
         $subscription->setErrorMessage($e->getMessage());
         $subscription->save();
         // 4. dispatch the failure event
         Mage::dispatchEvent('adyen_subscription_quote_createorder_fail', array('subscription' => $subscription, 'status' => $subscription->getStatus(), 'error' => $e->getMessage()));
         throw $e;
     } catch (Exception $e) {
         // 1. rollback everything
         $subscription->getResource()->rollBack();
         // 2. log the error to the debuglog
         Mage::helper('adyen_subscription')->logOrderCron(sprintf("Error in subscription (%s) creating order from quote (%s) error is: %s", $subscription->getId(), $quote->getId(), $e->getMessage()));
         // 3. save the error on the subscription
         $subscription->setStatus($subscription::STATUS_ORDER_ERROR);
         $subscription->setErrorMessage($e->getMessage());
         $subscription->save();
         // 4. dispatch the failure event
         Mage::dispatchEvent('adyen_subscription_quote_createorder_fail', array('subscription' => $subscription, 'quote' => $quote, 'status' => $subscription->getStatus(), 'error' => $e->getMessage()));
         throw $e;
     }
     Mage::dispatchEvent('adyen_subscription_quote_createorder_after', array('subscription' => $subscription, 'quote' => $quote, 'order' => $order));
     return $order;
 }
Exemplo n.º 24
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;
 }
Exemplo n.º 25
0
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * 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_Paypal
 * @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)
 */
$quote = new Mage_Sales_Model_Quote();
$quote->load('test01', 'reserved_order_id');
$payment = $quote->getPayment();
$payment->setMethod(Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS);
$payment->setAdditionalInformation(Mage_Paypal_Model_Express_Checkout::PAYMENT_INFO_TRANSPORT_PAYER_ID, 123);
$quote->collectTotals()->save();