/**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * update customer when edit shipping address to paypal
  *
  * @param $accessCode
  */
 public function updateCustomer($accessCode)
 {
     $response = $this->_doRapidAPI('Transaction/' . $accessCode, 'GET');
     if ($response->isSuccess()) {
         $customer = $this->_quote->getCustomer();
         $billingAddress = $this->_quote->getBillingAddress();
         $shippingAddress = $this->_quote->getShippingAddress();
         $trans = $response->getTransactions();
         if (isset($trans[0]['Customer'])) {
             $billing = $trans[0]['Customer'];
             $billingAddress->setFirstname($billing['FirstName'])->setLastName($billing['LastName'])->setCompany($billing['CompanyName'])->setJobDescription($billing['JobDescription'])->setStreet($billing['Street1'])->setStreet2($billing['Street2'])->setCity($billing['City'])->setState($billing['State'])->setPostcode($billing['PostalCode'])->setCountryId(strtoupper($billing['Country']))->setEmail($billing['Email'])->setTelephone($billing['Phone'])->setMobile($billing['Mobile'])->setComments($billing['Comments'])->setFax($billing['Fax'])->setUrl($billing['Url']);
         }
         if (isset($trans[0]['ShippingAddress'])) {
             $shipping = $trans[0]['ShippingAddress'];
             $shippingAddress->setFirstname($shipping['FirstName'])->setLastname($shipping['LastName'])->setStreet($shipping['Street1'])->setStreet2($shipping['Street2'])->setCity($shipping['City'])->setPostcode($shipping['PostalCode'])->setCountryId(strtoupper($shipping['Country']))->setEmail($shipping['Email'])->setFax($shipping['Fax']);
             if ($shipping['State'] && $shipping['Country'] && ($region = Mage::getModel('directory/region')->loadByCode($shipping['State'], $shipping['Country']))) {
                 $shippingAddress->setRegion($region->getName())->setRegionId($region->getId());
             }
             if ($shipping['Phone']) {
                 $shippingAddress->setTelephone($shipping['Phone']);
             }
         }
         $this->_quote->assignCustomerWithAddressChange($customer, $billingAddress, $shippingAddress)->save();
     }
 }
Exemplo n.º 3
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->setIncrementId($quote->getReservedOrderId())->setStoreId($quote->getStoreId())->setQuoteId($quote->getId())->setCustomer($quote->getCustomer());
     Mage::helper('core')->copyFieldset('sales_convert_quote', 'to_order', $quote, $order);
     Mage::dispatchEvent('sales_convert_quote_to_order', array('order' => $order, 'quote' => $quote));
     return $order;
 }
 /**
  * Involve new customer to system
  *
  * @return self
  */
 protected function _involveNewCustomer()
 {
     $customer = $this->_quote->getCustomer();
     if ($customer->isConfirmationRequired()) {
         $customer->sendNewAccountEmail('confirmation');
         $url = Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail());
         $this->_getCustomerSession()->addSuccess(Mage::helper('customer')->__('Account confirmation is required. Please, check your e-mail for confirmation link. To resend confirmation email please <a href="%s">click here</a>.', $url));
     } else {
         $customer->sendNewAccountEmail();
         $this->_getCustomerSession()->loginById($customer->getId());
     }
     return $this;
 }
Exemplo n.º 5
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.º 6
0
 /**
  * set the last pending alias to active and remove other aliases for customer based on address
  * 
  * @param Mage_Sales_Model_Quote $quote
  */
 public function setAliasActive(Mage_Sales_Model_Quote $quote, Mage_Sales_Model_Order $order = null, $saveSalesObjects = false)
 {
     if (is_null($quote->getPayment()->getAdditionalInformation('userIsRegistering')) || false === $quote->getPayment()->getAdditionalInformation('userIsRegistering')) {
         $aliasesToDelete = Mage::helper('ops/alias')->getAliasesForAddresses($quote->getCustomer()->getId(), $quote->getBillingAddress(), $quote->getShippingAddress())->addFieldToFilter('state', Netresearch_OPS_Model_Alias_State::ACTIVE);
         $lastPendingAlias = Mage::helper('ops/alias')->getAliasesForAddresses($quote->getCustomer()->getId(), $quote->getBillingAddress(), $quote->getShippingAddress(), $quote->getStoreId())->addFieldToFilter('alias', $quote->getPayment()->getAdditionalInformation('alias'))->addFieldToFilter('state', Netresearch_OPS_Model_Alias_State::PENDING)->setOrder('created_at', Varien_Data_Collection::SORT_ORDER_DESC)->getFirstItem();
         if (0 < $lastPendingAlias->getId()) {
             foreach ($aliasesToDelete as $alias) {
                 $alias->delete();
             }
             $lastPendingAlias->setState(Netresearch_OPS_Model_Alias_State::ACTIVE);
             $lastPendingAlias->save();
         }
     } else {
         $this->setAliasToActiveAfterUserRegisters($order, $quote);
     }
     $this->cleanUpAdditionalInformation($order->getPayment(), false, $saveSalesObjects);
     $this->cleanUpAdditionalInformation($quote->getPayment(), false, $saveSalesObjects);
 }
Exemplo n.º 7
0
 /**
  * Involve new customer to system
  *
  * @param Mage_Sales_Model_Quote $quote
  * @return Mage_Checkout_Model_Api_Resource_Customer
  */
 public function involveNewCustomer(Mage_Sales_Model_Quote $quote)
 {
     $customer = $quote->getCustomer();
     if ($customer->isConfirmationRequired()) {
         $customer->sendNewAccountEmail('confirmation');
     } else {
         $customer->sendNewAccountEmail();
     }
     return $this;
 }
Exemplo n.º 8
0
 /**
  * Abort registration during checkout if default activation status is false.
  *
  * Should work with: onepage checkout, multishipping checkout and custom
  * checkout types, as long as they use the standard converter model
  * Mage_Sales_Model_Convert_Quote.
  *
  * Expected state after checkout:
  * - Customer saved
  * - No order placed
  * - Guest quote still contains items
  * - Customer quote contains no items
  * - Customer redirected to login page
  * - Customer sees message
  *
  * @param Mage_Sales_Model_Quote $quote
  */
 protected function _abortCheckoutRegistration(Mage_Sales_Model_Quote $quote)
 {
     $helper = Mage::helper('customeractivation');
     if (!$helper->isModuleActive($quote->getStoreId())) {
         return;
     }
     if ($this->_isApiRequest()) {
         return;
     }
     if (!Mage::getSingleton('customer/session')->isLoggedIn() && !$quote->getCustomerIsGuest()) {
         // Order is being created by non-activated customer
         $customer = $quote->getCustomer()->save();
         if (!$customer->getCustomerActivated()) {
             // Abort order placement
             // Exception handling can not be assumed to be useful
             // Todo: merge guest quote to customer quote and save customer quote, but don't log customer in
             // Add message
             $message = $helper->__('Please wait for your account to be activated, then log in and continue with the checkout');
             Mage::getSingleton('core/session')->addSuccess($message);
             // Handle redirect to login page
             $targetUrl = Mage::getUrl('customer/account/login');
             $response = Mage::app()->getResponse();
             if (Mage::app()->getRequest()->isAjax()) {
                 // Assume one page checkout
                 $result = array('redirect' => $targetUrl);
                 $response->setBody(Mage::helper('core')->jsonEncode($result));
             } else {
                 if ($response->canSendHeaders(true)) {
                     // Assume multishipping checkout
                     $response->clearHeader('location')->setRedirect($targetUrl);
                 }
             }
             $response->sendResponse();
             /* ugly, but we need to stop the further order processing */
             exit;
         }
     }
 }
Exemplo n.º 9
0
 /**
  * Update customer info
  * @param $transId
  * @return mixed
  */
 public function updateCustomer($accessCode, Mage_Sales_Model_Quote $quote)
 {
     try {
         $results = $this->_doRapidAPI("Transaction/{$accessCode}", 'GET');
         if (!$results->isSuccess()) {
             Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later. (Error message: %s)', $results->getMessage()));
         }
         $customer = $quote->getCustomer();
         $billingAddress = $quote->getBillingAddress();
         $shippingAddress = $quote->getShippingAddress();
         if ($results->isSuccess()) {
             $trans = $results->getTransactions();
             if (isset($trans[0]['Customer'])) {
                 $billing = $trans[0]['Customer'];
                 $billingAddress->setFirstname($billing['FirstName'])->setLastName($billing['LastName'])->setCompany($billing['CompanyName'])->setJobDescription($billing['JobDescription'])->setStreet($billing['Street1'])->setStreet2($billing['Street2'])->setCity($billing['City'])->setState($billing['State'])->setPostcode($billing['PostalCode'])->setCountryId(strtoupper($billing['Country']))->setEmail($billing['Email'])->setTelephone($billing['Phone'])->setMobile($billing['Mobile'])->setComments($billing['Comments'])->setFax($billing['Fax'])->setUrl($billing['Url']);
             }
             if (isset($trans[0]['ShippingAddress'])) {
                 $shipping = $trans[0]['ShippingAddress'];
                 $shippingAddress->setFirstname($shipping['FirstName'])->setLastname($shipping['LastName'])->setStreet($shipping['Street1'])->setStreet2($shipping['Street2'])->setCity($shipping['City'])->setPostcode($shipping['PostalCode'])->setCountryId(strtoupper($shipping['Country']))->setEmail($shipping['Email'])->setFax($shipping['Fax']);
                 if ($shipping['State'] && $shipping['Country'] && ($region = Mage::getModel('directory/region')->loadByCode($shipping['State'], $shipping['Country']))) {
                     $shippingAddress->setRegion($region->getName())->setRegionId($region->getId());
                 }
                 if ($shipping['Phone']) {
                     $shippingAddress->setTelephone($shipping['Phone']);
                 }
             }
             return $quote->assignCustomerWithAddressChange($customer, $billingAddress, $shippingAddress)->save();
         }
         return false;
     } catch (Exception $e) {
         Mage::throwException($e->getMessage());
         return false;
     }
 }
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();
 }
 /**
  * get an alternate address to use if the address an item is attached to
  * does not have enough data for the payload
  *
  * @param Mage_Sales_Model_Quote
  * @return Mage_Customer_Model_Address_Abstract|null
  */
 protected function getAlternateAddress(Mage_Sales_Model_Quote $quote)
 {
     $address = $quote->getCustomer()->getDefaultShippingAddress();
     return $address ?: null;
 }
Exemplo n.º 12
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);
 }
Exemplo n.º 13
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.º 14
0
 public function callGetTaxForQuote(Mage_Sales_Model_Quote $quote)
 {
     /** @var Aoe_AvaTax_Helper_Soap $helper */
     $helper = Mage::helper('Aoe_AvaTax/Soap');
     $address = $quote->getShippingAddress();
     if ($address->validate() !== true) {
         $resultArray = array('ResultCode' => 'Skip', 'Messages' => array(), 'TaxLines' => array());
         return $resultArray;
     }
     $store = $quote->getStore();
     $hideDiscountAmount = Mage::getStoreConfigFlag(Mage_Tax_Model_Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT, $store);
     $timestamp = $quote->getCreatedAt() ? Varien_Date::toTimestamp($quote->getCreatedAt()) : now();
     $date = new Zend_Date($timestamp);
     $request = new AvaTax\GetTaxRequest();
     $request->setCompanyCode($this->limit($helper->getConfig('company_code', $store), 25));
     $request->setDocType(AvaTax\DocumentType::$SalesOrder);
     $request->setCommit(false);
     $request->setDetailLevel(AvaTax\DetailLevel::$Tax);
     $request->setDocDate($date->toString('yyyy-MM-dd'));
     $request->setCustomerCode($helper->getCustomerDocCode($quote->getCustomer()) ?: $helper->getQuoteDocCode($quote));
     $request->setCurrencyCode($this->limit($quote->getBaseCurrencyCode(), 3));
     $request->setDiscount($hideDiscountAmount ? 0.0 : $store->roundPrice($address->getBaseDiscountAmount()));
     if ($quote->getCustomerTaxvat()) {
         $request->setBusinessIdentificationNo($this->limit($quote->getCustomerTaxvat(), 25));
     }
     $request->setOriginAddress($this->getOriginAddress($store));
     $request->setDestinationAddress($this->getAddress($address));
     $taxLines = array();
     $itemPriceIncludesTax = Mage::getStoreConfigFlag(Mage_Tax_Model_Config::CONFIG_XML_PATH_PRICE_INCLUDES_TAX, $store);
     foreach ($this->getHelper()->getActionableQuoteAddressItems($address) as $k => $item) {
         /** @var Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Quote_Address_Item $item */
         $itemAmount = $store->roundPrice($itemPriceIncludesTax ? $item->getBaseRowTotalInclTax() : $item->getBaseRowTotal());
         //$itemAmount = $store->roundPrice($item->getBaseRowTotal());
         $itemAmount -= $store->roundPrice($item->getBaseDiscountAmount());
         $taxLine = new AvaTax\Line();
         $taxLine->setNo($this->limit($k, 50));
         $taxLine->setItemCode($this->limit($item->getSku(), 50));
         $taxLine->setQty(round($item->getQty(), 4));
         $taxLine->setAmount($itemAmount);
         $taxLine->setDescription($this->limit($item->getName(), 255));
         $taxLine->setTaxCode($this->limit($helper->getProductTaxCode($item->getProduct()), 25));
         $taxLine->setDiscounted($item->getBaseDiscountAmount() > 0.0);
         $taxLine->setTaxIncluded($itemPriceIncludesTax);
         $taxLine->setRef1($this->limit($helper->getQuoteItemRef1($item, $store), 250));
         $taxLine->setRef2($this->limit($helper->getQuoteItemRef2($item, $store), 250));
         $taxLines[] = $taxLine;
     }
     $shippingPriceIncludesTax = Mage::getStoreConfigFlag(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX, $store);
     $shippingAmount = $store->roundPrice($shippingPriceIncludesTax ? $address->getBaseShippingInclTax() : $address->getBaseShippingAmount());
     //$shippingAmount = $store->roundPrice($address->getBaseShippingAmount());
     $shippingAmount -= $store->roundPrice($address->getBaseShippingDiscountAmount());
     $taxLine = new AvaTax\Line();
     $taxLine->setNo('SHIPPING');
     $taxLine->setItemCode('SHIPPING');
     $taxLine->setQty(1);
     $taxLine->setAmount($shippingAmount);
     $taxLine->setDescription($this->limit("Shipping: " . $address->getShippingMethod(), 255));
     $taxLine->setTaxCode($this->limit($helper->getShippingTaxCode($store), 25));
     $taxLine->setDiscounted($address->getBaseShippingDiscountAmount() > 0.0);
     $taxLine->setTaxIncluded($shippingPriceIncludesTax);
     $taxLine->setRef1($this->limit($address->getShippingMethod(), 25));
     $taxLines[] = $taxLine;
     $request->setLines($taxLines);
     Mage::dispatchEvent('aoe_avatax_soapapi_get_tax_for_quote_before', array('request' => $request, 'quote' => $quote));
     // TODO: Handle giftwrapping
     return $this->callGetTax($store, $request);
 }
Exemplo n.º 15
0
 /**
  * Return customer data in xml format.
  *
  * @param Mage_Sales_Model_Quote $quote
  * @return string Xml data
  */
 public function getCustomerXml($quote)
 {
     $_xml = null;
     $checkoutMethod = Mage::getSingleton('checkout/type_onepage')->getCheckoutMethod();
     if ($checkoutMethod) {
         $customer = new Varien_Object();
         switch ($checkoutMethod) {
             case 'register':
             case 'guest':
                 $customer->setMiddlename($quote->getBillingAddress()->getMiddlename());
                 $customer->setPreviousCustomer('0');
                 break;
             case 'customer':
                 //Load customer by Id
                 $customer = $quote->getCustomer();
                 $customer->setPreviousCustomer('1');
                 break;
             default:
                 $customer = $quote->getCustomer();
                 $customer->setPreviousCustomer('0');
                 break;
         }
         $customer->setWorkPhone($quote->getBillingAddress()->getFax());
         $customer->setMobilePhone($quote->getBillingAddress()->getTelephone());
         $xml = new Ebizmarts_Simplexml_Element('<customer />');
         if ($customer->getMiddlename()) {
             $xml->addChild('customerMiddleInitial', substr($customer->getMiddlename(), 0, 1));
         }
         if ($customer->getDob()) {
             $_dob = substr($customer->getDob(), 0, strpos($customer->getDob(), ' '));
             if ($_dob != "0000-00-00") {
                 $xml->addChildCData('customerBirth', $_dob);
                 //YYYY-MM-DD
             }
         }
         if ($customer->getWorkPhone()) {
             $xml->addChildCData('customerWorkPhone', substr(str_pad($customer->getWorkPhone(), 11, '0', STR_PAD_RIGHT), 0, 19));
         }
         if ($customer->getMobilePhone()) {
             $xml->addChildCData('customerMobilePhone', substr(str_pad($customer->getMobilePhone(), 11, '0', STR_PAD_RIGHT), 0, 19));
         }
         $xml->addChild('previousCust', $customer->getPreviousCustomer());
         if ($customer->getId()) {
             $xml->addChild('customerId', $customer->getId());
         }
         //$xml->addChild('timeOnFile', 10);
         $_xml = str_replace("\n", "", trim($xml->asXml()));
     }
     return $_xml;
 }
 /**
  * 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
 private function configureTaxCalculation()
 {
     // this prevents customer session initialization (which affects cookies)
     // see Mage_Tax_Model_Calculation::getCustomer()
     Mage::getSingleton('tax/calculation')->setCustomer($this->quote->getCustomer());
 }
Exemplo n.º 18
0
 function CreateMagentoShopRequest(Mage_Sales_Model_Quote $quote)
 {
     $request = new Byjuno_Cdp_Helper_Api_Classes_ByjunoRequest();
     $request->setClientId(Mage::getStoreConfig('byjuno/api/clientid', Mage::app()->getStore()));
     $request->setUserID(Mage::getStoreConfig('byjuno/api/userid', Mage::app()->getStore()));
     $request->setPassword(Mage::getStoreConfig('byjuno/api/password', Mage::app()->getStore()));
     $request->setVersion("1.00");
     try {
         $request->setRequestEmail(Mage::getStoreConfig('byjuno/api/mail', Mage::app()->getStore()));
     } catch (Exception $e) {
     }
     $b = $quote->getCustomerDob();
     if (!empty($b)) {
         $request->setDateOfBirth(Mage::getModel('core/date')->date('Y-m-d', strtotime($b)));
     }
     Mage::getSingleton('checkout/session')->setData('dob_amasty', '');
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["dob"])) {
         $request->setDateOfBirth(Mage::getModel('core/date')->date('Y-m-d', strtotime($_POST["billing"]["dob"])));
         Mage::getSingleton('checkout/session')->setData('dob_amasty', $_POST["billing"]["dob"]);
     }
     $g = $quote->getCustomerGender();
     if (!empty($g)) {
         if ($g == '1') {
             $request->setGender('1');
         } else {
             if ($g == '2') {
                 $request->setGender('2');
             }
         }
     }
     $request->setRequestId(uniqid((string) $quote->getBillingAddress()->getId() . "_"));
     $reference = $quote->getCustomer()->getId();
     if (empty($reference)) {
         $request->setCustomerReference("guest_" . $quote->getBillingAddress()->getId());
     } else {
         $request->setCustomerReference($quote->getCustomer()->getId());
     }
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["method"]) && $_POST["method"] == 'guest') {
         $request->setCustomerReference(uniqid("guest_"));
     }
     $request->setFirstName((string) $quote->getBillingAddress()->getFirstname());
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["firstname"])) {
         $request->setFirstName((string) $_POST["billing"]["firstname"]);
     }
     $request->setLastName((string) $quote->getBillingAddress()->getLastname());
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["lastname"])) {
         $request->setLastName((string) $_POST["billing"]["lastname"]);
     }
     $request->setFirstLine(trim((string) $quote->getBillingAddress()->getStreetFull()));
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["street"])) {
         $street = '';
         if (!empty($_POST["billing"]["street"][0])) {
             $street .= $_POST["billing"]["street"][0];
         }
         if (!empty($_POST["billing"]["street"][1])) {
             $street .= $_POST["billing"]["street"][1];
         }
         $request->setFirstLine((string) trim($street));
     }
     $request->setCountryCode(strtoupper((string) $quote->getBillingAddress()->getCountry()));
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["country_id"])) {
         $request->setCountryCode((string) $_POST["billing"]["country_id"]);
     }
     $request->setPostCode((string) $quote->getBillingAddress()->getPostcode());
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["postcode"])) {
         $request->setPostCode($_POST["billing"]["postcode"]);
     }
     $request->setTown((string) $quote->getBillingAddress()->getCity());
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["city"])) {
         $request->setTown($_POST["billing"]["city"]);
     }
     $request->setFax((string) trim($quote->getBillingAddress()->getFax(), '-'));
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["fax"])) {
         $request->setFax(trim($_POST["billing"]["fax"], '-'));
     }
     $request->setLanguage((string) substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2));
     if ($quote->getBillingAddress()->getCompany()) {
         $request->setCompanyName1($quote->getBillingAddress()->getCompany());
     }
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["company"])) {
         $request->setCompanyName1(trim($_POST["billing"]["company"], '-'));
     }
     $request->setTelephonePrivate((string) trim($quote->getBillingAddress()->getTelephone(), '-'));
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["telephone"])) {
         $request->setTelephonePrivate(trim($_POST["billing"]["telephone"], '-'));
     }
     $request->setEmail((string) $quote->getBillingAddress()->getEmail());
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["email"])) {
         $request->setEmail((string) $_POST["billing"]["email"]);
     }
     Mage::getSingleton('checkout/session')->setData('gender_amasty', '');
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty') {
         $g = isset($_POST["billing"]["gender"]) ? $_POST["billing"]["gender"] : '';
         $request->setGender($g);
         Mage::getSingleton('checkout/session')->setData('gender_amasty', $g);
     }
     if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && !empty($_POST["billing"]["prefix"])) {
         if (strtolower($_POST["billing"]["prefix"]) == 'herr') {
             $request->setGender('1');
             Mage::getSingleton('checkout/session')->setData('gender_amasty', '1');
         } else {
             if (strtolower($_POST["billing"]["prefix"]) == 'frau') {
                 $request->setGender('2');
                 Mage::getSingleton('checkout/session')->setData('gender_amasty', '2');
             }
         }
     }
     $extraInfo["Name"] = 'ORDERCLOSED';
     $extraInfo["Value"] = 'NO';
     $request->setExtraInfo($extraInfo);
     $extraInfo["Name"] = 'ORDERAMOUNT';
     $extraInfo["Value"] = number_format($quote->getGrandTotal(), 2, '.', '');
     $request->setExtraInfo($extraInfo);
     $extraInfo["Name"] = 'ORDERCURRENCY';
     $extraInfo["Value"] = $quote->getBaseCurrencyCode();
     $request->setExtraInfo($extraInfo);
     $extraInfo["Name"] = 'IP';
     $extraInfo["Value"] = $this->getClientIp();
     $request->setExtraInfo($extraInfo);
     $sesId = Mage::getSingleton('checkout/session')->getData("byjuno_session_id");
     if (Mage::getStoreConfig('byjuno/api/tmxenabled', Mage::app()->getStore()) == 'enable' && !empty($sesId)) {
         $extraInfo["Name"] = 'DEVICE_FINGERPRINT_ID';
         $extraInfo["Value"] = Mage::getSingleton('checkout/session')->getData("byjuno_session_id");
         $request->setExtraInfo($extraInfo);
     }
     /* shipping information */
     if (!$quote->isVirtual()) {
         $extraInfo["Name"] = 'DELIVERY_FIRSTNAME';
         $extraInfo["Value"] = $quote->getShippingAddress()->getFirstname();
         if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && empty($_POST["shipping"]["same_as_billing"])) {
             if (!empty($_POST["shipping"]["firstname"])) {
                 $extraInfo["Value"] = $_POST["shipping"]["firstname"];
             }
         }
         $request->setExtraInfo($extraInfo);
         $extraInfo["Name"] = 'DELIVERY_LASTNAME';
         $extraInfo["Value"] = $quote->getShippingAddress()->getLastname();
         if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && empty($_POST["shipping"]["same_as_billing"])) {
             if (!empty($_POST["shipping"]["lastname"])) {
                 $extraInfo["Value"] = $_POST["shipping"]["lastname"];
             }
         }
         $request->setExtraInfo($extraInfo);
         $extraInfo["Name"] = 'DELIVERY_FIRSTLINE';
         $extraInfo["Value"] = trim($quote->getShippingAddress()->getStreetFull());
         if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && empty($_POST["shipping"]["same_as_billing"])) {
             $extraInfo["Value"] = '';
             if (!empty($_POST["shipping"]["street"][0])) {
                 $extraInfo["Value"] = $_POST["shipping"]["street"][0];
             }
             if (!empty($_POST["shipping"]["street"][1])) {
                 $extraInfo["Value"] .= ' ' . $_POST["shipping"]["street"][1];
             }
             $extraInfo["Value"] = trim($extraInfo["Value"]);
         }
         $request->setExtraInfo($extraInfo);
         $extraInfo["Name"] = 'DELIVERY_HOUSENUMBER';
         $extraInfo["Value"] = '';
         $request->setExtraInfo($extraInfo);
         $extraInfo["Name"] = 'DELIVERY_COUNTRYCODE';
         $extraInfo["Value"] = strtoupper($quote->getShippingAddress()->getCountry());
         if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && empty($_POST["shipping"]["same_as_billing"])) {
             if (!empty($_POST["shipping"]["country_id"])) {
                 $extraInfo["Value"] = $_POST["shipping"]["country_id"];
             }
         }
         $request->setExtraInfo($extraInfo);
         $extraInfo["Name"] = 'DELIVERY_POSTCODE';
         $extraInfo["Value"] = $quote->getShippingAddress()->getPostcode();
         if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty' && empty($_POST["shipping"]["same_as_billing"])) {
             if (!empty($_POST["shipping"]["postcode"])) {
                 $extraInfo["Value"] = $_POST["shipping"]["postcode"];
             }
         }
         $request->setExtraInfo($extraInfo);
         $extraInfo["Name"] = 'DELIVERY_TOWN';
         $extraInfo["Value"] = $quote->getShippingAddress()->getCity();
         if (Mage::getStoreConfig('byjuno/api/plugincheckouttype', Mage::app()->getStore()) == 'amasty') {
             if (!empty($_POST["shipping"]["same_as_billing"]) && $_POST["shipping"]["same_as_billing"] == '1' && !empty($_POST["billing"]["city"])) {
                 $extraInfo["Value"] = $_POST["billing"]["city"];
             } else {
                 if (!empty($_POST["shipping"]["city"])) {
                     $extraInfo["Value"] = $_POST["shipping"]["city"];
                 }
             }
         }
         $request->setExtraInfo($extraInfo);
         if ($quote->getShippingAddress()->getCompany() != '' && Mage::getStoreConfig('byjuno/api/businesstobusiness', Mage::app()->getStore()) == 'enable') {
             $extraInfo["Name"] = 'DELIVERY_COMPANYNAME';
             $extraInfo["Value"] = $quote->getShippingAddress()->getCompany();
             $request->setExtraInfo($extraInfo);
         }
     }
     $extraInfo["Name"] = 'CONNECTIVTY_MODULE';
     $extraInfo["Value"] = 'Byjuno Magento module 4.0.0';
     $request->setExtraInfo($extraInfo);
     return $request;
 }