/** * 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(); } }
/** * 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(); }
/** * @param Mage_Sales_Model_Quote $quote * @param ShopgateCartBase $order * * @return Mage_Sales_Model_Quote * @throws ShopgateLibraryException */ protected function _setQuoteCustomer($quote, $order) { /* @var $customer Mage_Customer_Model_Customer */ $customer = Mage::getModel('customer/customer'); $externalCustomerId = $order->getExternalCustomerId(); if ($externalCustomerId) { $this->log('external customer id: ' . $externalCustomerId, ShopgateLogger::LOGTYPE_DEBUG); $customer->load($externalCustomerId); if (!$customer->getId()) { throw new ShopgateLibraryException(ShopgateLibraryException::UNKNOWN_ERROR_CODE, sprintf('customer with external id \'%s\' does not exist', $externalCustomerId)); } else { $quote->setCustomer($customer); // also set customer in session some 3rd party plugins rely on it Mage::getSingleton('customer/session')->setCustomer($customer)->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId()); $this->log('external customer loaded', ShopgateLogger::LOGTYPE_DEBUG); } } $invoiceAddress = $order->getInvoiceAddress(); if ($invoiceAddress) { $this->log('invoice address start', ShopgateLogger::LOGTYPE_DEBUG); $quote->getBillingAddress()->setShouldIgnoreValidation(true); $billingAddressData = $this->_getSalesHelper()->createAddressData($order, $order->getInvoiceAddress(), true); $billingAddress = $quote->getBillingAddress()->addData($billingAddressData); $this->log('invoice address end', ShopgateLogger::LOGTYPE_DEBUG); } $deliveryAddress = $order->getDeliveryAddress(); if ($deliveryAddress) { $this->log('delivery address start', ShopgateLogger::LOGTYPE_DEBUG); $quote->getShippingAddress()->setShouldIgnoreValidation(true); $shippingAddressData = $this->_getSalesHelper()->createAddressData($order, $order->getDeliveryAddress(), false); $shippingAddress = $quote->getShippingAddress()->addData($shippingAddressData); $this->_getHelper()->setShippingMethod($shippingAddress, $order); $this->log('delivery address end', ShopgateLogger::LOGTYPE_DEBUG); } $quote->setCustomerEmail($order->getMail()); $this->log('customer email: ' . $order->getMail(), ShopgateLogger::LOGTYPE_DEBUG); if ($invoiceAddress) { $this->log('invoice address start (names)', ShopgateLogger::LOGTYPE_DEBUG); $quote->setCustomerPrefix($quote->getShippingAddress()->getPrefix()); $quote->setCustomerFirstname($invoiceAddress->getFirstName()); $quote->setCustomerLastname($invoiceAddress->getLastName()); $this->log('invoice address end (names)', ShopgateLogger::LOGTYPE_DEBUG); } $externalCustomerId = $order->getExternalCustomerId(); if (empty($externalCustomerId)) { $this->log('external customer number unavailable', ShopgateLogger::LOGTYPE_DEBUG); $quote->setCustomerIsGuest(1); $quote->getShippingAddress(); $quote->getBillingAddress(); } else { $this->log('external customer number available', ShopgateLogger::LOGTYPE_DEBUG); $quote->setCustomerIsGuest(0); if ($invoiceAddress) { $billingAddress->setCustomerAddressId($invoiceAddress->getId()); } if ($deliveryAddress) { $shippingAddress->setCustomerAddressId($deliveryAddress->getId()); } } Mage::register('rule_data', new Varien_Object(array('store_id' => Mage::app()->getStore()->getId(), 'website_id' => Mage::app()->getStore()->getWebsiteId(), 'customer_group_id' => $quote->getCustomerGroupId()))); $quote->setIsActive('0'); $quote->setRemoteIp('shopgate.com'); $quote->save(); if (empty($externalCustomerId)) { $quote->getBillingAddress()->isObjectNew(false); $quote->getShippingAddress()->isObjectNew(false); } return $quote; }