Пример #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
 /**
  * Set customers basic data like name, gender etc.
  *
  * @param Mage_Customer_Model_Customer $magentoCustomer
  * @param ShopgateCustomer             $shopgateCustomer
  *
  * @return Mage_Customer_Model_Customer $magentoCustomer
  */
 protected function _registerSetBasicData($magentoCustomer, $shopgateCustomer)
 {
     $magentoCustomer->setConfirmation(null);
     $magentoCustomer->setFirstname($shopgateCustomer->getFirstName());
     $magentoCustomer->setLastname($shopgateCustomer->getLastName());
     $magentoCustomer->setGender($this->getMagentoCustomerGender($shopgateCustomer->getGender()));
     $magentoCustomer->setDob($shopgateCustomer->getBirthday());
     $magentoCustomer->setForceConfirmed(true);
     $magentoCustomer->save();
     $magentoCustomer->sendNewAccountEmail('registered', '', $magentoCustomer->getStore()->getId());
     return $magentoCustomer;
 }