Exemplo n.º 1
0
 /**
  * @return array
  */
 protected function _prepareCustomerData()
 {
     $customer_id = null;
     $customer = null;
     $customer_log = null;
     $billing_address = $this->_order->getBillingAddress();
     $customer_verified = false;
     $customer_orders_count = 0;
     $gender = $this->_order->getCustomerGender();
     if (!$this->_order->getCustomerIsGuest()) {
         $customer_id = $this->_order->getCustomerId();
         if ($customer_id) {
             /** @var Mage_Customer_Model_Customer $customer */
             $customer = Mage::getModel("customer/customer");
             $customer->load($customer_id);
             /** @var Mage_Log_Model_Customer $customer_log */
             $customer_log = Mage::getModel('log/customer')->load($customer_id);
         }
         $customer_verified = $this->getCustomerIsConfirmedStatus($customer);
         $orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id', $customer_id);
         /** @noinspection PhpUndefinedMethodInspection */
         $customer_orders_count = $orders->count();
     }
     $data = array_filter(array('customer_id' => $customer_id, 'customer_is_guest' => $this->_order->getCustomerIsGuest(), 'verified' => $customer_verified, 'language_code' => $this->_language_code, 'last_login_on' => $customer_log ? $customer_log->getLoginAt() : null, 'created_on' => $customer ? $customer->getData('created_at') : null, 'updated_on' => $customer ? $customer->getData('updated_at') : null, 'birthdate' => $this->_order->getCustomerDob(), 'email' => $this->_order->getCustomerEmail(), 'title' => '', 'prefix' => $this->_order->getCustomerPrefix(), 'suffix' => $this->_order->getCustomerSuffix(), 'first_name' => $this->_order->getCustomerFirstname(), 'middle_name' => $this->_order->getCustomerMiddlename(), 'last_name' => $this->_order->getCustomerLastname(), 'company_name' => $billing_address ? $billing_address->getCompany() : null, 'gender' => $gender == 1 ? 'male' : ($gender == 2 ? 'female' : null), 'telephone1' => $billing_address ? $billing_address->getTelephone() : null, 'telephone2' => '', 'telephone3' => '', 'fax' => $billing_address ? $billing_address->getFax() : null, 'vat_number' => $this->_order->getCustomerTaxvat(), 'reg_ip_address' => '', 'customer_orders_count' => $customer_orders_count));
     return $data;
 }
Exemplo n.º 2
0
 /**
  * @param Mage_Sales_Model_Order $order
  * @return int
  */
 protected function _createCustomer(Mage_Sales_Model_Order $order)
 {
     /** @var $customer Mage_Customer_Model_Customer */
     $customer = Mage::getModel('customer/customer')->setWebsiteId($order->getStore()->getWebsiteId())->loadByEmail($order->getCustomerEmail());
     $customerGroupId = 1;
     // @todo load general customer group ID?
     if (!$customer->getId()) {
         $customer->addData(array('prefix' => $order->getCustomerPrefix(), 'firstname' => $order->getCustomerFirstname(), 'middlename' => $order->getCustomerMiddlename(), 'lastname' => $order->getCustomerLastname(), 'suffix' => $order->getCustomerSuffix(), 'email' => $order->getCustomerEmail(), 'group_id' => $customerGroupId, 'taxvat' => $order->getCustomerTaxvat(), 'website_id' => $order->getStore()->getWebsiteId(), 'default_billing' => '_item1', 'default_shipping' => '_item2'));
         // Billing Address
         /** @var $billingAddress Mage_Sales_Model_Order_Address */
         $billingAddress = $order->getBillingAddress();
         /** @var $customerBillingAddress Mage_Customer_Model_Address */
         $customerBillingAddress = Mage::getModel('customer/address');
         $billingAddressArray = $billingAddress->toArray();
         unset($billingAddressArray['entity_id']);
         unset($billingAddressArray['parent_id']);
         unset($billingAddressArray['customer_id']);
         unset($billingAddressArray['customer_address_id']);
         unset($billingAddressArray['quote_address_id']);
         $customerBillingAddress->addData($billingAddressArray);
         $customerBillingAddress->setPostIndex('_item1');
         $customer->addAddress($customerBillingAddress);
         // Shipping Address
         /** @var $shippingAddress Mage_Sales_Model_Order_Address */
         $shippingAddress = $order->getShippingAddress();
         /** @var $customerShippingAddress Mage_Customer_Model_Address */
         $customerShippingAddress = Mage::getModel('customer/address');
         $shippingAddressArray = $shippingAddress->toArray();
         unset($shippingAddressArray['entity_id']);
         unset($shippingAddressArray['parent_id']);
         unset($shippingAddressArray['customer_id']);
         unset($shippingAddressArray['customer_address_id']);
         unset($shippingAddressArray['quote_address_id']);
         $customerShippingAddress->addData($shippingAddressArray);
         $customerShippingAddress->setPostIndex('_item2');
         $customer->addAddress($customerShippingAddress);
         // Save the customer
         $customer->setPassword($customer->generatePassword());
         $customer->save();
     }
     // Link customer to order
     $order->setCustomerId($customer->getId());
     $order->setCustomerIsGuest(0);
     $order->setCustomerGroupId($customerGroupId);
     $order->save();
     return $customer->getId();
 }
Exemplo n.º 3
0
 /**
  * Creates new customer from order, adds order addresses as customer addresses
  *
  * @param Mage_Sales_Model_Order|bool $order
  * @return Mage_Customer_Model_Customer
  */
 protected function _createCustomerFromOrder($order)
 {
     if (!$order instanceof Mage_Sales_Model_Order) {
         return false;
     }
     // Check if customer with email address exists
     $existingCustomer = Mage::getResourceModel('customer/customer_collection')->addFieldToFilter('email', $order->getCustomerEmail());
     if (Mage::getSingleton('customer/config_share')->isWebsiteScope()) {
         $existingCustomer->addFieldToFilter('website_id', $order->getWebsiteId());
     }
     $existingCustomer = $existingCustomer->getFirstItem();
     if (!$existingCustomer instanceof Mage_Customer_Model_Customer || !$existingCustomer->getId()) {
         return Mage::getModel('customer/customer');
     }
     // Create customer
     /** @var Mage_Customer_Model_Customer $customer */
     $customer = Mage::getModel('customer/customer')->setEmail($order->getCustomerEmail())->setStoreId($order->getStoreId())->setPrefix($order->getCustomerPrefix())->setFirstname($order->getCustomerFirstname())->setLastname($order->getCustomerLastname());
     $customer->save();
     // Create customer addresses
     foreach ($order->getAddressesCollection() as $orderAddress) {
         /** @var Mage_Sales_Model_Order_Address $orderAddress */
         /** @var Mage_Customer_Model_Address $address */
         $address = Mage::getModel('customer/address')->setParentId($customer->getEntityId())->setCustomerId($customer->getEntityId())->setIsActive(true)->setPrefix($orderAddress->getPrefix())->setFirstname($orderAddress->getFirstname())->setMiddlename($orderAddress->getMiddlename())->setLastname($orderAddress->getLastname())->setSuffix($orderAddress->getSuffix())->setStreet($orderAddress->getStreet())->setCity($orderAddress->getCity())->setPostcode($orderAddress->getPostcode())->setCountryId($orderAddress->getCountryId())->setTelephone($orderAddress->getTelephone())->setCompany($orderAddress->getCompany())->setRegion($orderAddress->getRegion())->setRegionId($orderAddress->getRegionId());
         $address->save();
         // Save default billing and shipping
         if ($orderAddress->getAddressType() == 'billing') {
             $customer->setDefaultBilling($address->getEntityId());
         } elseif ($orderAddress->getAddressType() == 'shipping') {
             $customer->setDefaultShipping($address->getEntityId());
         }
     }
     // Force confirmation
     $customer->setConfirmation($customer->getRandomConfirmationKey());
     $customer->save();
     return $customer;
 }
Exemplo n.º 4
0
 protected function _createCustomerName(Mage_Sales_Model_Order $order)
 {
     $data = array('firstName' => $order->getCustomerFirstname(), 'middleName' => strlen($order->getCustomerMiddlename()) > 0 ? $order->getCustomerMiddlename() : null, 'lastName' => $order->getCustomerLastname(), 'prefix' => strlen($order->getCustomerPrefix()) > 0 ? $order->getCustomerPrefix() : null, 'suffix' => strlen($order->getCustomerSuffix()) > 0 ? $order->getCustomerSuffix() : null);
     return $data;
 }
 /**
  * Set Customer information on the payload
  *
  * @param Mage_Sales_Model_Order
  * @param IOrderCustomer
  * @return self
  */
 protected function _setCustomerData(Mage_Sales_Model_Order $order, IOrderCustomer $payload)
 {
     $payload->setFirstName($order->getCustomerFirstname())->setLastName($order->getCustomerLastname())->setMiddleName($order->getCustomerMiddlename())->setHonorificName($order->getCustomerPrefix())->setGender($this->_getCustomerGender($order))->setCustomerId($this->_getCustomerId($order))->setEmailAddress($order->getCustomerEmail())->setTaxId($order->getCustomerTaxvat())->setIsTaxExempt($order->getCustomer()->getTaxExempt());
     $dob = $this->_getAsDateTime($order->getCustomerDob());
     if ($dob) {
         $payload->setDateOfBirth($dob);
     }
     return $this;
 }
Exemplo n.º 6
0
 /**
  * This method returns the customer gender code
  *
  * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $quote
  * @return string
  */
 public function getGenderCode($quote)
 {
     $gender = $quote->getCustomerGender();
     if ($gender) {
         $attribute = Mage::getModel('eav/entity_attribute')->loadByCode('customer', 'gender');
         $option = $attribute->getFrontend()->getOption($gender);
         switch (strtolower($option)) {
             case 'male':
                 return 'M';
             case 'female':
                 return 'F';
         }
     }
     $gender = $quote->getCustomerPrefix();
     if ($gender) {
         switch (strtolower($gender)) {
             case 'herr':
             case 'mr':
                 return 'M';
             case 'frau':
             case 'mrs':
                 return 'F';
         }
     }
     return 'U';
 }
Exemplo n.º 7
0
 /**
  * Retrieve the prefix
  *
  * @param Mage_Sales_Model_Order $order
  * @return string
  */
 public function getPrefix(Mage_Sales_Model_Order $order)
 {
     $gender = $order->getCustomerPrefix();
     if ($gender) {
         switch (strtolower($gender)) {
             case 'herr':
             case 'mr':
                 return 'MR';
             case 'frau':
             case 'mrs':
                 return 'MRS';
             case 'fräulein':
             case 'ms':
                 return 'MS';
         }
     }
     return '';
 }