/** * @param Customer $object * @param Constraint $constraint */ public function validate($object, Constraint $constraint) { /** @var CustomerRepository $customerRepo */ $customerRepo = $this->entityManager->getRepository('SehBundle:Customer'); if ($customerRepo->emailExists($object->getEmail(), $object->getId())) { $this->context->addViolationAt('seh_bundle_sehbundle_account_customer_type.email', $constraint->message); } }
/** * @param Customer $customer * @param $password * @return bool */ public function subscribeCustomer(Customer $customer, $password) { $em = $this->entityManager; $galittProvider = $this->galittProvider; $hashPassword = $galittProvider->hashPassword($password); try { $alreadyRegistered = $galittProvider->getCustomer($customer->getEmail()); } catch (\Exception $e) { $this->logger->error(sprintf('An error occured while trying to get a Galitt customer with email (%s) via the getCustomer webservice. Request failed with message : "%s"', $customer->getEmail(), $e->getMessage())); return false; } $accentCards = array(); if ($alreadyRegistered) { try { $passwordGalitt = $galittProvider->getPasswordCustomer($customer->getEmail()); } catch (\Exception $e) { $this->logger->error(sprintf('An error occured while trying to get a password Galitt customer with email (%s) via the getPasswordCustomer webservice. Request failed with message : "%s"', $customer->getEmail(), $e->getMessage())); return false; } if ($passwordGalitt != $hashPassword) { try { if (!$galittProvider->updatePassword($customer->getEmail(), $hashPassword, $passwordGalitt)) { return false; } } catch (\Exception $e) { $this->logger->error(sprintf('An error occured while trying to update a password Galitt customer with parameters (Email : %s, Password : %s, PasswordGalitt : %s) via the updatePassword webservice. Request failed with message : "%s"', $customer->getEmail(), $hashPassword, $passwordGalitt, $e->getMessage())); return false; } } $customer->setPassword(null); $customer->setLoyalty(1); if ($customer->getTempCardNumber()) { $this->addAccentCard($customer, $customer->getTempCardNumber()); $customer->setTempCardNumber(null); } $em->persist($customer); $em->flush(); return true; } else { try { $galittProvider->setAccountFidelity($customer, $password, $customer->getTempCardNumber() ?: null); $customer->setPassword(null); $customer->setLoyalty(1); if ($customer->getTempCardNumber()) { $this->addAccentCard($customer, $customer->getTempCardNumber()); $customer->setTempCardNumber(null); } $em->persist($customer); $em->flush(); return true; } catch (\Exception $e) { $this->logger->error(sprintf('An error occured while trying to create a customer (id : %s, email : %s) account on Galitt via the setAccountFidelity webservice. Request failed with message : "%s"', $customer->getId(), $customer->getEmail(), $e->getMessage())); return false; } } }
/** * @param Customer $customer */ public function fromUser(Customer $customer) { $this->title = $customer->getTitle() ? $customer->getTitle()->getId() : ''; $this->lastName = $customer->getLastName(); $this->firstName = $customer->getFirstName(); $this->phone = $customer->getPhone(); $this->email = $customer->getEmail(); $this->address = $customer->getAddress(); $this->address2 = $customer->getAddress2(); $this->zipCode = $customer->getZipCode(); $this->city = $customer->getCity(); $this->country = $customer->getCountry(); $this->locale = $customer->getLocale(); $this->birthDate = $customer->getBirthDate(); }
protected function customerToArray(Customer $customer) { $toReturn = array(); $mainAccentCard = $customer->getMainAccentCard(); $toReturn['numC'] = $mainAccentCard ? $mainAccentCard->getNumber() : ''; $toReturn['nom'] = $customer->getLastName(); $toReturn['prenom'] = $customer->getFirstName(); $toReturn['telephone'] = $customer->getPhone(); $toReturn['mobile'] = $customer->getMobile() ?: ''; $toReturn['email'] = $customer->getEmail(); $toReturn['adresse'] = $customer->getAddress(); $toReturn['cplAdresse'] = $customer->getAddress2() ?: ''; $toReturn['codePostal'] = $customer->getZipCode(); $toReturn['ville'] = $customer->getCity(); $toReturn['pays'] = $customer->getCountry(); $toReturn['langue'] = $customer->getLocale(); $toReturn['civilite'] = $customer->getGalittTitle() ?: $customer->getTitle()->getGalittTitle()->getValue(); $toReturn['nlCarteFidelite'] = $customer->getAccountOption() ? $customer->getAccountOption() : 'O'; $toReturn['dateNaissance'] = $customer->getBirthDate() ? $customer->getBirthDate()->format('Ymd') : '19700101'; return $toReturn; }