Пример #1
0
 /**
  * @param $user
  * @param $pass
  * @param ShopgateCustomer $customer
  * @throws ShopgateLibraryException
  */
 public function registerCustomer($user, $pass, ShopgateCustomer $customer)
 {
     if (!Validate::isEmail($user)) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_REGISTER_CUSTOMER_ERROR, 'E-mail Address validation error', true);
     }
     if ($pass && !Validate::isPasswd($pass)) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_REGISTER_CUSTOMER_ERROR, 'Password validation error', true);
     }
     /** @var CustomerCore | Customer $customerModel */
     $customerModel = new Customer();
     if ($customerModel->getByEmail($user)) {
         throw new ShopgateLibraryException(ShopgateLibraryException::REGISTER_USER_ALREADY_EXISTS);
     }
     $customerModel->active = 1;
     $customerModel->lastname = $customer->getLastName();
     $customerModel->firstname = $customer->getFirstName();
     $customerModel->email = $user;
     $customerModel->passwd = Tools::encrypt($pass);
     $customerModel->id_gender = $this->mapGender($customer->getGender());
     $customerModel->birthday = $customer->getBirthday();
     $customerModel->newsletter = $customer->getNewsletterSubscription();
     $shopgateCustomFieldsHelper = new ShopgateCustomFieldsHelper();
     $shopgateCustomFieldsHelper->saveCustomFields($customerModel, $customer->getCustomFields());
     $validateMessage = $customerModel->validateFields(false, true);
     if ($validateMessage !== true) {
         throw new ShopgateLibraryException(ShopgateLibraryException::REGISTER_FAILED_TO_ADD_USER, $validateMessage, true);
     }
     $customerModel->save();
     /**
      * addresses
      */
     foreach ($customer->getAddresses() as $address) {
         $this->createAddress($address, $customerModel);
     }
     return $customerModel->id;
 }
Пример #2
0
 /**
  * add addresses to the customer
  *
  * @param Mage_Customer_Model_Customer $magentoCustomer
  * @param ShopgateCustomer             $shopgateCustomer
  */
 protected function _registerAddCustomerAddresses($magentoCustomer, $shopgateCustomer)
 {
     foreach ($shopgateCustomer->getAddresses() as $shopgateCustomerAddress) {
         $magentoCustomerAddress = $this->getMagentoCustomerAddress($shopgateCustomerAddress);
         $magentoCustomerAddress->setCustomer($magentoCustomer);
         $magentoCustomerAddress->setCustomerId($magentoCustomer->getId());
         $magentoCustomerAddress->save();
         if ($magentoCustomerAddress->getIsInvoiceAddress() && !$magentoCustomer->getDefaultBillingAddress()) {
             $magentoCustomer->setDefaultBilling($magentoCustomerAddress->getId());
         }
         if ($magentoCustomerAddress->getIsDeliveryAddress() && !$magentoCustomer->getDefaultShippingAddress()) {
             $magentoCustomer->setDefaultShipping($magentoCustomerAddress->getId());
         }
     }
     $magentoCustomer->save();
 }