Esempio n. 1
0
 /**
  * Creates an instance of an entity.
  *
  * This method must return always an empty instance
  *
  * @return Customer Empty entity
  */
 public function create()
 {
     /**
      * @var Customer $customer
      */
     $classNamespace = $this->getEntityNamespace();
     $customer = new $classNamespace();
     $customer->setGender(ElcodiUserProperties::GENDER_UNKNOWN)->setGuest(false)->setNewsletter(false)->setAddresses(new ArrayCollection())->setCarts(new ArrayCollection())->setOrders(new ArrayCollection())->setToken($this->generator->generate(2))->setEnabled(true)->setCreatedAt($this->now());
     return $customer;
 }
Esempio n. 2
0
 /**
  * Creates an instance of an entity.
  *
  * This method must return always an empty instance
  *
  * @return AdminUserInterface Empty entity
  */
 public function create()
 {
     /**
      * @var AdminUserInterface $adminUser
      */
     $classNamespace = $this->getEntityNamespace();
     $adminUser = new $classNamespace();
     $adminUser->setGender(ElcodiUserProperties::GENDER_UNKNOWN)->setToken($this->generator->generate(2))->setEnabled(true)->setCreatedAt($this->now());
     return $adminUser;
 }
Esempio n. 3
0
 /**
  * Set a user in a remember password mode. Also rises an event
  * to hook when this happens.
  *
  * Recover url must contain these fields with these names
  *
  * @param AbstractUser $user                   User
  * @param string       $recoverPasswordUrlName Recover password name
  * @param string       $hashField              Hash
  *
  * @return $this Self object
  */
 public function rememberPassword(AbstractUser $user, $recoverPasswordUrlName, $hashField = 'hash')
 {
     $recoveryHash = $this->recoveryHashGenerator->generate();
     $user->setRecoveryHash($recoveryHash);
     $this->manager->flush($user);
     $recoverUrl = $this->router->generate($recoverPasswordUrlName, [$hashField => $recoveryHash], true);
     $this->passwordEventDispatcher->dispatchOnPasswordRememberEvent($user, $recoverUrl);
     return $this;
 }
Esempio n. 4
0
 /**
  * Set a user in a remember password mode. Also rises an event
  * to hook when this happens.
  *
  * Recover url must contain these fields with these names
  *
  * @param AbstractUser $user                   User
  * @param string       $recoverPasswordUrlName Recover password name
  * @param string       $hashField              Hash
  *
  * @return $this self Object
  */
 public function rememberPassword(AbstractUser $user, $recoverPasswordUrlName, $hashField = 'hash')
 {
     $recoveryHash = $this->recoveryHashGenerator->generate();
     $user->setRecoveryHash($recoveryHash);
     $this->manager->flush($user);
     $recoverUrl = $this->router->generate($recoverPasswordUrlName, array($hashField => $recoveryHash), true);
     $event = new PasswordRememberEvent($user, $recoverUrl);
     $this->eventDispatcher->dispatch(ElcodiUserEvents::PASSWORD_REMEMBER, $event);
     return $this;
 }
Esempio n. 5
0
 /**
  * Subscribe email to newsletter
  *
  * @param string            $email    Email
  * @param LanguageInterface $language The language
  *
  * @return $this Self object
  *
  * @throws NewsletterCannotBeAddedException
  */
 public function subscribe($email, LanguageInterface $language = null)
 {
     if (!$this->validateEmail($email)) {
         throw new NewsletterCannotBeAddedException();
     }
     $newsletterSubscription = $this->getSubscription($email);
     if (!$newsletterSubscription instanceof NewsletterSubscriptionInterface) {
         $newsletterSubscription = $this->newsletterSubscriptionFactory->create();
         $newsletterSubscription->setEmail($email)->setHash($this->hashGenerator->generate())->setLanguage($language);
     }
     $newsletterSubscription->setEnabled(true);
     $this->newsletterEventDispatcher->dispatchSubscribeEvent($newsletterSubscription);
     return $this;
 }
Esempio n. 6
0
 /**
  * Given an existing Customer, this service manages its referral hash
  *
  * When requiring Customer Hash, if not set, new one is generated.
  * Otherwise, returns related.
  *
  * @param CustomerInterface $customer Customer
  *
  * @return ReferralHash ReferralHash
  */
 public function getReferralHashByCustomer(CustomerInterface $customer)
 {
     /**
      * @var $referralHash ReferralHash
      */
     $referralHash = $this->referralHashRepository->findOneBy(array('referrer' => $customer));
     if (!$referralHash instanceof ReferralHashInterface) {
         $referralHash = $this->referralHashFactory->create();
         $referralHash->setReferrer($customer)->setHash($this->referralHashGenerator->generate());
         $this->manager->persist($referralHash);
         $this->manager->flush($referralHash);
     }
     return $referralHash;
 }
Esempio n. 7
0
 /**
  * Creates a new coupon instance, given an existing Coupon as reference
  *
  * You can specify a DateTime new coupon will be valid from.
  * If not specified, current DateTime will be used
  *
  * If given coupon is valid forever, new coupon will also be
  * Otherwise, this method will add to validFrom, the same interval than given Coupon
  *
  * Also can be specified how new Coupon name must be defined.
  * If none, automatic generator will add to existing name, 10 random digits.
  *
  * Given Coupon name: FOO
  * New Coupon name: FOO_a67b6786a6
  *
  * Coupons are only generated, and are not persisted in Manager not Flushed
  *
  * @param CouponInterface $coupon   Reference coupon
  * @param DateTime        $dateFrom Date From. If null, takes actual dateTime
  *
  * @return CouponInterface Coupon generated
  */
 public function duplicateCoupon(CouponInterface $coupon, DateTime $dateFrom = null)
 {
     /**
      * Creates a valid date interval given the referent Coupon
      */
     if (!$dateFrom instanceof DateTime) {
         $dateFrom = new DateTime();
     }
     $dateTo = null;
     if ($coupon->getValidTo() instanceof DateTime) {
         $interval = $coupon->getValidFrom()->diff($coupon->getValidTo());
         $dateTo = clone $dateFrom;
         $dateTo->add($interval);
     }
     /**
      * @var CouponInterface $couponGenerated
      */
     $couponGenerated = $this->couponFactory->create();
     $couponGenerated->setCode($this->couponCodeGenerator->generate())->setName($coupon->getName())->setType($coupon->getType())->setPrice($coupon->getPrice())->setDiscount($coupon->getDiscount())->setCount($coupon->getCount())->setPriority($coupon->getPriority())->setMinimumPurchase($coupon->getMinimumPurchase())->setValidFrom($dateFrom)->setValidTo($dateTo)->setEnabled(true);
     return $couponGenerated;
 }
Esempio n. 8
0
 /**
  * Generates a random string.
  *
  * @param int $length Length of string generated
  *
  * @return string Result of generation
  */
 public function generate($length = 1)
 {
     return hash('sha1', $this->generator->generate($length));
 }