get_by_identifier() public static method

Get member by unique field.
public static get_by_identifier ( $idvalue ) : Member | null
return Member | null
 public function validateData(Order $order, array $data)
 {
     if (Member::currentUserID()) {
         return;
     }
     $result = ValidationResult::create();
     if (Checkout::membership_required() || !empty($data['Password'])) {
         $member = Member::create($data);
         $idfield = Member::config()->unique_identifier_field;
         $idval = $data[$idfield];
         if (ShopMember::get_by_identifier($idval)) {
             // get localized field labels
             $fieldLabels = $member->fieldLabels(false);
             // if a localized value exists, use this for our error-message
             $fieldLabel = isset($fieldLabels[$idfield]) ? $fieldLabels[$idfield] : $idfield;
             $result->error(sprintf(_t("Checkout.MEMBEREXISTS", "A member already exists with the %s %s"), $fieldLabel, $idval), $idval);
         }
         $passwordresult = $this->passwordvalidator->validate($data['Password'], $member);
         if (!$passwordresult->valid()) {
             $result->error($passwordresult->message(), "Password");
         }
     }
     if (!$result->valid()) {
         throw new ValidationException($result);
     }
 }
 /**
  * Create member account from data array.
  * Data must contain unique identifier.
  *
  * @throws ValidationException
  * @param $data - map of member data
  * @return Member|boolean - new member (not saved to db), or false if there is an error.
  */
 public function create($data)
 {
     $result = new ValidationResult();
     if (!Checkout::member_creation_enabled()) {
         $result->error(_t("Checkout.MEMBERSHIPSNOTALLOWED", "Creating new memberships is not allowed"));
         throw new ValidationException($result);
     }
     $idfield = Config::inst()->get('Member', 'unique_identifier_field');
     if (!isset($data[$idfield]) || empty($data[$idfield])) {
         $result->error(sprintf(_t("Checkout.IDFIELDNOTFOUND", "Required field not found: %s"), $idfield));
         throw new ValidationException($result);
     }
     if (!isset($data['Password']) || empty($data['Password'])) {
         $result->error(_t("Checkout.PASSWORDREQUIRED", "A password is required"));
         throw new ValidationException($result);
     }
     $idval = $data[$idfield];
     if (ShopMember::get_by_identifier($idval)) {
         $result->error(sprintf(_t("Checkout.MEMBEREXISTS", "A member already exists with the %s %s"), _t("Member." . $idfield, $idfield), $idval));
         throw new ValidationException($result);
     }
     $member = new Member(Convert::raw2sql($data));
     $validation = $member->validate();
     if (!$validation->valid()) {
         //TODO need to handle i18n here?
         $result->error($validation->message());
     }
     if (!$result->valid()) {
         throw new ValidationException($result);
     }
     return $member;
 }
 public function testGetByIdentifier()
 {
     Member::config()->unique_identifier_field = 'Email';
     $member = ShopMember::get_by_identifier('*****@*****.**');
     $this->assertNotNull($member);
     $this->assertEquals('*****@*****.**', $member->Email);
     $this->assertEquals('Jeremy', $member->FirstName);
 }
 public function testMembershipStep()
 {
     //this should still work if there is no cart
     ShoppingCart::singleton()->clear();
     $this->checkout->index();
     $this->checkout->membership();
     $this->post('/checkout/guestcontinue', array());
     //redirect to next step
     $this->checkout->createaccount(new SS_HTTPRequest('GET', "/checkout/createaccount"));
     $form = $this->checkout->MembershipForm();
     $data = array();
     $form->loadDataFrom($data);
     $data = array('FirstName' => 'Michael', 'Surname' => 'Black', 'Email' => '*****@*****.**', 'Password' => array('_Password' => 'pass1234', '_ConfirmPassword' => 'pass1234'), 'action_docreateaccount' => 'Create New Account');
     $response = $this->post('/checkout/CreateAccountForm', $data);
     //redirect to next step
     $member = ShopMember::get_by_identifier("*****@*****.**");
     $this->assertTrue((bool) $member, "Check new account was created");
     $this->assertEquals('Michael', $member->FirstName);
     $this->assertEquals('Black', $member->Surname);
 }
 public function validateData(Order $order, array $data)
 {
     if (Member::currentUserID()) {
         return;
     }
     $result = new ValidationResult();
     if (Checkout::membership_required() || !empty($data['Password'])) {
         $member = new Member($data);
         $idfield = Member::config()->unique_identifier_field;
         $idval = $data[$idfield];
         if (ShopMember::get_by_identifier($idval)) {
             $result->error(sprintf(_t("Checkout.MEMBEREXISTS", "A member already exists with the %s %s"), $idfield, $idval), $idval);
         }
         $passwordresult = $this->passwordvalidator->validate($data['Password'], $member);
         if (!$passwordresult->valid()) {
             $result->error($passwordresult->message(), "Password");
         }
     }
     if (!$result->valid()) {
         throw new ValidationException($result);
     }
 }
 /**
  * Create member account from data array.
  * Data must contain unique identifier.
  *
  * @throws ValidationException
  *
  * @param $data - map of member data
  *
  * @return Member|boolean - new member (not saved to db), or false if there is an error.
  */
 public function create($data)
 {
     $result = ValidationResult::create();
     if (!Checkout::member_creation_enabled()) {
         $result->error(_t("Checkout.MEMBERSHIPSNOTALLOWED", "Creating new memberships is not allowed"));
         throw new ValidationException($result);
     }
     $idfield = Config::inst()->get('Member', 'unique_identifier_field');
     if (!isset($data[$idfield]) || empty($data[$idfield])) {
         $result->error(sprintf(_t("Checkout.IDFIELDNOTFOUND", "Required field not found: %s"), $idfield));
         throw new ValidationException($result);
     }
     if (!isset($data['Password']) || empty($data['Password'])) {
         $result->error(_t("Checkout.PASSWORDREQUIRED", "A password is required"));
         throw new ValidationException($result);
     }
     $idval = $data[$idfield];
     if ($member = ShopMember::get_by_identifier($idval)) {
         // get localized field labels
         $fieldLabels = $member->fieldLabels(false);
         // if a localized value exists, use this for our error-message
         $fieldLabel = isset($fieldLabels[$idfield]) ? $fieldLabels[$idfield] : $idfield;
         $result->error(sprintf(_t("Checkout.MEMBEREXISTS", "A member already exists with the %s %s"), $fieldLabel, $idval));
         throw new ValidationException($result);
     }
     $member = Member::create(Convert::raw2sql($data));
     // 3.2 changed validate to protected which made this fall through the DataExtension and error out
     $validation = $member->hasMethod('doValidate') ? $member->doValidate() : $member->validate();
     if (!$validation->valid()) {
         //TODO need to handle i18n here?
         $result->error($validation->message());
     }
     if (!$result->valid()) {
         throw new ValidationException($result);
     }
     return $member;
 }
 /**
  * Create member account from data array.
  * Data must contain unique identifier.
  *
  * @throws ValidationException
  *
  * @param $data - map of member data
  *
  * @return Member|boolean - new member (not saved to db), or false if there is an error.
  */
 public function create($data)
 {
     $result = ValidationResult::create();
     if (!Checkout::member_creation_enabled()) {
         $result->error(_t("Checkout.MembershipIsNotAllowed", "Creating new memberships is not allowed"));
         throw new ValidationException($result);
     }
     $idfield = Config::inst()->get('Member', 'unique_identifier_field');
     if (!isset($data[$idfield]) || empty($data[$idfield])) {
         $result->error(_t('Checkout.IdFieldNotFound', 'Required field not found: {IdentifierField}', 'Identifier is the field that holds the unique user-identifier, commonly this is \'Email\'', array('IdentifierField' => $idfield)));
         throw new ValidationException($result);
     }
     if (!isset($data['Password']) || empty($data['Password'])) {
         $result->error(_t("Checkout.PasswordRequired", "A password is required"));
         throw new ValidationException($result);
     }
     $idval = $data[$idfield];
     if ($member = ShopMember::get_by_identifier($idval)) {
         // get localized field labels
         $fieldLabels = $member->fieldLabels(false);
         // if a localized value exists, use this for our error-message
         $fieldLabel = isset($fieldLabels[$idfield]) ? $fieldLabels[$idfield] : $idfield;
         $result->error(_t('Checkout.MemberExists', 'A member already exists with the {Field} {Identifier}', '', array('Field' => $fieldLabel, 'Identifier' => $idval)));
         throw new ValidationException($result);
     }
     $member = Member::create(Convert::raw2sql($data));
     // 3.2 changed validate to protected which made this fall through the DataExtension and error out
     $validation = $member->hasMethod('doValidate') ? $member->doValidate() : $member->validate();
     if (!$validation->valid()) {
         //TODO need to handle i18n here?
         $result->error($validation->message());
     }
     if (!$result->valid()) {
         throw new ValidationException($result);
     }
     return $member;
 }