/**
  * Set shipping method to quote, if needed
  *
  * @param string $methodCode
  */
 public function updateShippingMethod($methodCode)
 {
     $shippingAddress = $this->_quote->getShippingAddress();
     if ($methodCode && !$this->_quote->getIsVirtual() && $shippingAddress) {
         if ($methodCode != $shippingAddress->getShippingMethod()) {
             $this->_ignoreAddressValidation();
             $shippingAddress->setShippingMethod($methodCode)->setCollectShippingRates(true);
             // Know shipping method has changed which will likely trigger
             // total changes. Ensure that totals are collected again by
             // setting the flag to false before triggering the collect.
             $this->_quote->setTotalsCollectedFlag(false)->collectTotals()->save();
         }
     }
 }
Esempio n. 2
0
 /**
  * Update order data
  *
  * @param array $data
  */
 public function updateOrder($data)
 {
     /** @var $checkout Mage_Checkout_Model_Type_Onepage */
     $checkout = Mage::getModel('checkout/type_onepage');
     $this->_quote->setTotalsCollectedFlag(true);
     $checkout->setQuote($this->_quote);
     if (isset($data['billing'])) {
         if (isset($data['customer-email'])) {
             $data['billing']['email'] = $data['customer-email'];
         }
         $checkout->saveBilling($data['billing'], 0);
     }
     if (!$this->_quote->getIsVirtual() && isset($data['shipping'])) {
         $checkout->saveShipping($data['shipping'], 0);
     }
     if (isset($data['shipping_method'])) {
         $this->updateShippingMethod($data['shipping_method']);
     }
     $this->_quote->setTotalsCollectedFlag(false);
     $this->_quote->collectTotals();
     $this->_quote->setDataChanges(true);
     $this->_quote->save();
 }
Esempio n. 3
0
 /**
  * @param Mage_Sales_Model_Quote $quote
  *
  * @return Mage_Sales_Model_Order
  */
 public function createNewOrder($quote)
 {
     $shopgateOrder = $this->getShopgateOrder();
     $convert = Mage::getModel('sales/convert_quote');
     $transaction = Mage::getModel('core/resource_transaction');
     $SgPaymentInfos = $shopgateOrder->getPaymentInfos();
     if ($quote->getCustomerId()) {
         $transaction->addObject($quote->getCustomer());
     }
     $quote->setTotalsCollectedFlag(true);
     $transaction->addObject($quote);
     if ($quote->isVirtual()) {
         $order = $convert->addressToOrder($quote->getBillingAddress());
     } else {
         $order = $convert->addressToOrder($quote->getShippingAddress());
     }
     $order->setBillingAddress($convert->addressToOrderAddress($quote->getBillingAddress()));
     if ($quote->getBillingAddress()->getCustomerAddress()) {
         $order->getBillingAddress()->setCustomerAddress($quote->getBillingAddress()->getCustomerAddress());
     }
     if (!$quote->isVirtual()) {
         $order->setShippingAddress($convert->addressToOrderAddress($quote->getShippingAddress()));
         if ($quote->getShippingAddress()->getCustomerAddress()) {
             $order->getShippingAddress()->setCustomerAddress($quote->getShippingAddress()->getCustomerAddress());
         }
     }
     $order->setPayment($convert->paymentToOrderPayment($quote->getPayment()));
     $order->getPayment()->setTransactionId($quote->getPayment()->getLastTransId());
     $order->getPayment()->setLastTransId($quote->getPayment()->getLastTransId());
     $order->setPayoneTransactionStatus($SgPaymentInfos['status']);
     foreach ($quote->getAllItems() as $item) {
         /** @var Mage_Sales_Model_Order_Item $item */
         $orderItem = $convert->itemToOrderItem($item);
         if ($item->getParentItem()) {
             $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
         }
         $order->addItem($orderItem);
     }
     $order->setQuote($quote);
     $order->setExtOrderId($quote->getPayment()->getTransactionId());
     $order->setCanSendNewEmailFlag(false);
     $order->getPayment()->setData('payone_config_payment_method_id', $this->_getMethodId());
     return $this->setOrder($order);
 }
Esempio n. 4
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;
 }
Esempio n. 5
0
 /**
  * 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();
 }