/** * @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; }