/**
  * Validate customer data and set some its data for further usage in quote
  * Will return either true or array with error messages
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param array $data
  * @return true|array
  */
 public function validateCustomerData($quote, array $data, $registerMethod)
 {
     /** @var $customerForm Mage_Customer_Model_Form */
     $customerForm = Mage::getModel('customer/form');
     $customerForm->setFormCode('customer_account_create');
     if ($quote->getCustomerId()) {
         $customer = $quote->getCustomer();
         $customerForm->setEntity($customer);
         $customerData = $quote->getCustomer()->getData();
     } else {
         /* @var $customer Mage_Customer_Model_Customer */
         $customer = Mage::getModel('customer/customer');
         $customerForm->setEntity($customer);
         $customerRequest = $customerForm->prepareRequest($data);
         $customerData = $customerForm->extractData($customerRequest);
     }
     $customerErrors = $customerForm->validateData($customerData);
     if ($customerErrors !== true) {
         return $customerErrors;
     }
     if ($quote->getCustomerId()) {
         return true;
     }
     $customerForm->compactData($customerData);
     if ($registerMethod == 'register') {
         // set customer password
         $customer->setPassword($customerRequest->getParam('customer_password'));
         $customer->setConfirmation($customerRequest->getParam('confirm_password'));
         $customer->setPasswordConfirmation($customerRequest->getParam('confirm_password'));
     } else {
         // spoof customer password for guest
         $password = $customer->generatePassword();
         $customer->setPassword($password);
         $customer->setConfirmation($password);
         $customer->setPasswordConfirmation($password);
         // set NOT LOGGED IN group id explicitly,
         // otherwise copyFieldset('customer_account', 'to_quote') will fill it with default group id value
         $customer->setGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
     }
     $result = $customer->validate();
     if (true !== $result && is_array($result)) {
         return implode(', ', $result);
     }
     if ($registerMethod == 'register') {
         // save customer encrypted password in quote
         $quote->setPasswordHash($customer->encryptPassword($customer->getPassword()));
     }
     // copy customer/guest email to address
     $quote->getBillingAddress()->setEmail($customer->getEmail());
     // copy customer data to quote
     Mage::helper('core')->copyFieldset('customer_account', 'to_quote', $customer, $quote);
     return true;
 }
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * Validates alias for in quote provided addresses
  * @param Mage_Sales_Model_Quote $quote
  * @param Varien_Object $payment
  * @throws Mage_Core_Exception
  */
 protected function validateAlias($quote, $payment)
 {
     $alias = $payment->getAdditionalInformation('alias');
     if (0 < strlen(trim($alias)) && is_numeric($payment->getAdditionalInformation('cvc')) && false === Mage::helper('ops/alias')->isAliasValidForAddresses($quote->getCustomerId(), $alias, $quote->getBillingAddress(), $quote->getShippingAddress(), $quote->getStoreId())) {
         $this->getOnepage()->getCheckout()->setGotoSection('payment');
         Mage::throwException($this->getHelper()->__('Invalid payment information provided!'));
     }
 }
Exemplo n.º 4
0
 /**
  * Update Quote Email Address if is guest and current email address assigned doesn't match new email
  *
  * @param Mage_Sales_Model_Quote $quote
  */
 public function updateQuote(Mage_Sales_Model_Quote $quote)
 {
     $queue = Mage::getModel('bronto_emailcapture/queue');
     $currentEmail = $queue->getCurrentEmail();
     if (is_null($quote->getCustomerId()) && $queue->isValidEmail($currentEmail) && $quote->getCustomerEmail() !== $currentEmail) {
         $quote->setCustomerEmail(Mage::getModel('bronto_emailcapture/queue')->getCurrentEmail())->save();
     }
 }
Exemplo n.º 5
0
 /**
  * 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->setStoreId($quote->getStoreId())->setQuoteId($quote->getId())->setRemoteIp($quote->getRemoteIp())->setCustomerId($quote->getCustomerId())->setCustomerEmail($quote->getCustomerEmail())->setCustomerFirstname($quote->getCustomerFirstname())->setCustomerLastname($quote->getCustomerLastname())->setCustomerGroupId($quote->getCustomerGroupId())->setCustomerTaxClassId($quote->getCustomerTaxClassId())->setCustomerNote($quote->getCustomerNote())->setCustomerNoteNotify($quote->getCustomerNoteNotify())->setCustomerIsGuest($quote->getCustomerIsGuest())->setBaseCurrencyCode($quote->getBaseCurrencyCode())->setStoreCurrencyCode($quote->getStoreCurrencyCode())->setOrderCurrencyCode($quote->getQuoteCurrencyCode())->setStoreToBaseRate($quote->getStoreToBaseRate())->setStoreToOrderRate($quote->getStoreToQuoteRate())->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;
 }
 /**
  * @param Mage_Sales_Model_Quote $quote
  * @return Payone_Api_Request_Parameter_ManageMandate_PersonalData
  */
 protected function mapPersonalData(Mage_Sales_Model_Quote $quote)
 {
     $billingAddress = $quote->getBillingAddress();
     $helper = $this->helper();
     $personalData = new Payone_Api_Request_Parameter_ManageMandate_PersonalData();
     if ($quote->getCustomerId()) {
         $personalData->setCustomerid($quote->getCustomerId());
     }
     $personalData->setLastname($billingAddress->getLastname());
     $personalData->setFirstname($billingAddress->getFirstname());
     if ($billingAddress->getCompany()) {
         $personalData->setCompany($billingAddress->getCompany());
     }
     $personalData->setStreet($helper->normalizeStreet($billingAddress->getStreet()));
     $personalData->setZip($billingAddress->getPostcode());
     $personalData->setCity($billingAddress->getCity());
     $personalData->setCountry($billingAddress->getCountry());
     $personalData->setEmail($billingAddress->getEmail());
     $personalData->setLanguage($helper->getDefaultLanguage());
     return $personalData;
 }
Exemplo n.º 7
0
 public function getGiftMessage()
 {
     if (!is_null($this->giftMessage)) {
         return $this->giftMessage;
     }
     $giftMessageData = $this->proxyItem->getGiftMessage();
     if (!is_array($giftMessageData)) {
         return NULL;
     }
     $giftMessageData['customer_id'] = (int) $this->quote->getCustomerId();
     /** @var $giftMessage Mage_GiftMessage_Model_Message */
     $giftMessage = Mage::getModel('giftmessage/message')->addData($giftMessageData);
     if ($giftMessage->isMessageEmpty()) {
         return NULL;
     }
     $this->giftMessage = $giftMessage->save();
     return $this->giftMessage;
 }
 /**
  * Post transaction to SagePay - PayPal
  */
 public function goAction()
 {
     try {
         $this->_initCheckout();
         $customer = Mage::getSingleton('customer/session')->getCustomer();
         if (!$this->_quote->getCustomerId() && $customer && $customer->getId()) {
             $this->_checkout->setCustomer($customer);
         }
         $rs = $this->_checkout->start();
         if (is_string($rs)) {
             $this->_redirectUrl($rs);
             return;
         }
     } catch (Exception $e) {
         $this->_getCheckoutSession()->addError($e->getMessage());
         Ebizmarts_SagePaySuite_Log::we($e);
     }
     $this->_redirect('checkout/cart', array('_secure' => true));
     return;
 }
Exemplo n.º 9
0
 /**
  * Get customer balance model using sales entity
  *
  * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $salesEntity
  *
  * @return Enterprise_CustomerBalance_Model_Balance|bool
  */
 public function getCustomerBalanceModelFromSalesEntity($salesEntity)
 {
     if ($salesEntity instanceof Mage_Sales_Model_Order) {
         $customerId = $salesEntity->getCustomerId();
         $quote = $salesEntity->getQuote();
     } elseif ($salesEntity instanceof Mage_Sales_Model_Quote) {
         $customerId = $salesEntity->getCustomer()->getId();
         $quote = $salesEntity;
     } else {
         return false;
     }
     if (!$customerId) {
         return false;
     }
     $customerBalanceModel = Mage::getModel('enterprise_customerbalance/balance')->setCustomerId($customerId)->setWebsiteId(Mage::app()->getStore($salesEntity->getStoreId())->getWebsiteId())->loadByCustomer();
     if ($quote->getBaseCustomerBalanceVirtualAmount() > 0) {
         $customerBalanceModel->setAmount($customerBalanceModel->getAmount() + $quote->getBaseCustomerBalanceVirtualAmount());
     }
     return $customerBalanceModel;
 }
Exemplo n.º 10
0
 /**
  * Sets the vat id into the customer if not guest and always into the Quote/Order
  *
  * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $quote
  * @param string $taxvat
  */
 public function setTaxvat($quote, $taxvat)
 {
     if ($quote->getCustomerId()) {
         $quote->getCustomer()->setTaxvat($taxvat)->save();
     }
     $quote->setCustomerTaxvat($taxvat)->save();
 }
Exemplo n.º 11
0
 /**
  * Prepare and set to quote reward balance instance,
  * set zero subtotal checkout payment if need
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param Varien_Object $payment
  * @param boolean $useRewardPoints
  * @return Enterprise_Reward_Model_Observer
  */
 protected function _paymentDataImport($quote, $payment, $useRewardPoints)
 {
     if (!$quote || !$quote->getCustomerId()) {
         return $this;
     }
     $quote->setUseRewardPoints((bool) $useRewardPoints);
     if ($quote->getUseRewardPoints()) {
         /* @var $reward Enterprise_Reward_Model_Reward */
         $reward = Mage::getModel('enterprise_reward/reward')->setCustomer($quote->getCustomer())->setWebsiteId($quote->getStore()->getWebsiteId())->loadByCustomer();
         if ($reward->getId()) {
             $quote->setRewardInstance($reward);
             if (!$payment->getMethod()) {
                 $payment->setMethod('free');
             }
         } else {
             $quote->setUseRewardPoints(false);
         }
     }
     return $this;
 }
Exemplo n.º 12
0
 /**
  * @param array $data
  * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $object
  */
 private function _fillCartInformation(&$data, $object)
 {
     $productIids = array();
     $productQtys = array();
     $productStyleIds = array();
     /** @var Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item $item */
     foreach ($object->getAllVisibleItems() as $item) {
         $productIids[] = $item->getProduct()->getIid();
         $productQtys[] = is_null($item->getQtyOrdered()) ? (int) $item->getQty() : (int) $item->getQtyOrdered();
         $productStyleIds[] = $item->getProduct()->getNumber() . '-' . $item->getProduct()->getColorCode();
     }
     $data['productStyleId'] = implode(',', $productStyleIds);
     $data['cartProductIds'] = implode(',', $productIids);
     $data['cartProductQtys'] = implode(',', $productQtys);
     $data['cartTotalNetto'] = round($object->getBaseSubtotal(), 2);
     $data['cartTotalBrutto'] = round($object->getBaseGrandTotal(), 2);
     $data['customerId'] = (int) $object->getCustomerId();
     // For zanox tracking
     if (array_key_exists('zanpid', $_COOKIE) && $_COOKIE['zanpid'] != '') {
         $data['zanpid'] = $_COOKIE['zanpid'];
     }
 }
 /**
  * register quote with connector
  *
  * @param Mage_Sales_Model_Quote $quote
  */
 protected function _registerQuote(Mage_Sales_Model_Quote $quote)
 {
     try {
         $connectorQuote = Mage::getModel('ddg_automation/quote');
         $connectorQuote->setQuoteId($quote->getId())->setCustomerId($quote->getCustomerId())->setStoreId($quote->getStoreId())->save();
     } catch (Exception $e) {
         Mage::logException($e);
     }
 }
Exemplo n.º 14
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.º 15
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;
 }
 /**
  * Prepare and set to quote reward balance instance,
  * set zero subtotal checkout payment if need
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param Varien_Object $payment
  * @param boolean $useRewardPoints
  * @return Enterprise_Reward_Model_Observer
  */
 protected function _paymentDataImport($quote, $payment, $useRewardPoints)
 {
     if (!$quote || !$quote->getCustomerId() || $quote->getBaseGrandTotal() + $quote->getBaseRewardCurrencyAmount() <= 0) {
         return $this;
     }
     $quote->setUseRewardPoints((bool) $useRewardPoints);
     if ($quote->getUseRewardPoints()) {
         /* @var $reward Enterprise_Reward_Model_Reward */
         $reward = Mage::getModel('enterprise_reward/reward')->setCustomer($quote->getCustomer())->setWebsiteId($quote->getStore()->getWebsiteId())->loadByCustomer();
         $minPointsBalance = (int) Mage::getStoreConfig(Enterprise_Reward_Model_Reward::XML_PATH_MIN_POINTS_BALANCE, $quote->getStoreId());
         if ($reward->getId() && $reward->getPointsBalance() >= $minPointsBalance) {
             $quote->setRewardInstance($reward);
             if (!$payment->getMethod()) {
                 $payment->setMethod('free');
             }
         } else {
             $quote->setUseRewardPoints(false);
         }
     }
     return $this;
 }
Exemplo n.º 17
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);
 }
 /**
  * Get Customer ID from Quote/Wishlist
  *
  * @param int                          $ruleId
  * @param Mage_Sales_Model_Quote       $quote
  * @param Mage_Wishlist_Model_Wishlist $wishlist
  *
  * @return int
  */
 protected function _getCustomerId($ruleId, $quote, $wishlist)
 {
     if (!$ruleId || !$quote && !$wishlist) {
         return 0;
     }
     if ($quote) {
         return $quote->getCustomerId() ? $quote->getCustomerId() : 0;
     }
     if ($wishlist) {
         return $wishlist->getCustomerId() ? $wishlist->getCustomerId() : 0;
     }
     return 0;
 }
Exemplo n.º 19
0
 /**
  * Sets the customer info if available
  *
  * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $object
  * @return $this
  */
 protected function _addCustomer($object)
 {
     $format = Mage::getStoreConfig('tax/avatax/cust_code_format', $object->getStoreId());
     $customer = Mage::getModel('customer/customer');
     if ($object->getCustomerId()) {
         $customer->load($object->getCustomerId());
         $taxClass = Mage::getModel('tax/class')->load($customer->getTaxClassId())->getOpAvataxCode();
         $this->_request->setCustomerUsageType($taxClass);
     }
     switch ($format) {
         case OnePica_AvaTax_Model_Source_Customercodeformat::LEGACY:
             if ($customer->getId()) {
                 $customerCode = $customer->getName() . ' (' . $customer->getId() . ')';
             } else {
                 $address = $object->getBillingAddress() ? $object->getBillingAddress() : $object;
                 $customerCode = $address->getFirstname() . ' ' . $address->getLastname() . ' (Guest)';
             }
             break;
         case OnePica_AvaTax_Model_Source_Customercodeformat::CUST_EMAIL:
             $customerCode = $object->getCustomerEmail() ? $object->getCustomerEmail() : $customer->getEmail();
             break;
         case OnePica_AvaTax_Model_Source_Customercodeformat::CUST_ID:
         default:
             $customerCode = $object->getCustomerId() ? $object->getCustomerId() : 'guest-' . $object->getId();
             break;
     }
     $this->_request->setCustomerCode($customerCode);
     return $this;
 }
 /**
  * Analyze payment data for quote and set free shipping if grand total is covered by balance
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param Varien_Object|Mage_Sales_Model_Quote_Payment $payment
  * @param bool $shouldUseBalance
  */
 protected function _importPaymentData($quote, $payment, $shouldUseBalance)
 {
     $store = Mage::app()->getStore($quote->getStoreId());
     if (!$quote || !$quote->getCustomerId() || $quote->getBaseGrandTotal() + $quote->getBaseCustomerBalanceAmountUsed() <= 0) {
         return;
     }
     $quote->setUseCustomerBalance($shouldUseBalance);
     if ($shouldUseBalance) {
         $balance = Mage::getModel('enterprise_customerbalance/balance')->setCustomerId($quote->getCustomerId())->setWebsiteId($store->getWebsiteId())->loadByCustomer();
         if ($balance) {
             $quote->setCustomerBalanceInstance($balance);
             if (!$payment->getMethod()) {
                 $payment->setMethod('free');
             }
         } else {
             $quote->setUseCustomerBalance(false);
         }
     }
 }
 /**
  * set the quote information
  * @param Mage_Sales_Model_Quote $quoteData
  */
 public function __construct(Mage_Sales_Model_Quote $quoteData)
 {
     $customerModel = Mage::getModel('customer/customer');
     $customerModel->load($quoteData->getCustomerId());
     $this->id = $quoteData->getId();
     $this->email = $quoteData->getCustomerEmail();
     $this->store_name = $quoteData->getStore()->getName();
     $created_at = new Zend_Date($quoteData->getCreatedAt(), Zend_Date::ISO_8601);
     $this->created_date = $created_at->toString(Zend_Date::ISO_8601);
     if ($quoteData->getShippingAddress()) {
         $this->delivery_method = $quoteData->getShippingAddress()->getShippingDescription();
         $this->delivery_total = $quoteData->getShippingAddress()->getShippingAmount();
     }
     $this->currency = $quoteData->getStoreCurrencyCode();
     if ($payment = $quoteData->getPayment()) {
         $this->payment = $payment->getMethod();
     }
     $this->couponCode = $quoteData->getCouponCode();
     /**
      * custom quote attributes
      */
     $helper = Mage::helper('ddg');
     $website = Mage::app()->getStore($quoteData->getStore())->getWebsite();
     $customAttributes = $helper->getConfigSelectedCustomQuoteAttributes($website);
     if ($customAttributes) {
         $fields = Mage::getResourceModel('ddg_automation/quote')->getQuoteTableDescription();
         foreach ($customAttributes as $customAttribute) {
             if (isset($fields[$customAttribute])) {
                 $field = $fields[$customAttribute];
                 $value = $this->_getCustomAttributeValue($field, $quoteData);
                 if ($value) {
                     $this->_assignCustom($field, $value);
                 }
             }
         }
     }
     /**
      * Billing address.
      */
     if ($quoteData->getBillingAddress()) {
         $billingData = $quoteData->getBillingAddress()->getData();
         $this->billing_address = array('billing_address_1' => $this->_getStreet($billingData['street'], 1), 'billing_address_2' => $this->_getStreet($billingData['street'], 2), 'billing_city' => $billingData['city'], 'billing_region' => $billingData['region'], 'billing_country' => $billingData['country_id'], 'billing_postcode' => $billingData['postcode']);
     }
     /**
      * Shipping address.
      */
     if ($quoteData->getShippingAddress()) {
         $shippingData = $quoteData->getShippingAddress()->getData();
         $this->delivery_address = array('delivery_address_1' => $this->_getStreet($shippingData['street'], 1), 'delivery_address_2' => $this->_getStreet($shippingData['street'], 2), 'delivery_city' => $shippingData['city'], 'delivery_region' => $shippingData['region'], 'delivery_country' => $shippingData['country_id'], 'delivery_postcode' => $shippingData['postcode']);
     }
     /**
      * Quote items.
      * @var Mage_Sales_Model_Quote_Item $productItem
      */
     foreach ($quoteData->getAllItems() as $productItem) {
         $product = $productItem->getProduct();
         if ($product) {
             // category names
             $categoryCollection = $product->getCategoryCollection()->addAttributeToSelect('name');
             foreach ($categoryCollection as $cat) {
                 $categories = array();
                 $categories[] = $cat->getName();
                 $this->categories[]['Name'] = substr(implode(', ', $categories), 0, 244);
             }
             //get attribute set name
             $attributeSetName = $this->_getAttributeSetName($product);
             $this->products[] = array('name' => $productItem->getName(), 'sku' => $productItem->getSku(), 'qty' => (int) number_format($productItem->getData('qty'), 2), 'price' => (double) number_format($productItem->getPrice(), 2, '.', ''), 'attribute-set' => $attributeSetName);
         } else {
             // when no product information is available limit to this data
             $this->products[] = array('name' => $productItem->getName(), 'sku' => $productItem->getSku(), 'qty' => (int) number_format($productItem->getData('qty'), 2), 'price' => (double) number_format($productItem->getPrice(), 2, '.', ''));
         }
     }
     $this->quote_subtotal = (double) number_format($quoteData->getData('subtotal'), 2, '.', '');
     $discountAmount = $quoteData->getData('subtotal') - $quoteData->getData('subtotal_with_discount');
     $this->discount_amount = (double) number_format($discountAmount, 2, '.', '');
     $this->quote_total = (double) number_format($quoteData->getData('grand_total'), 2, '.', '');
     return true;
 }