Author: Adam Piotrowski (adam@wellcommerce.org)
 public function resetPasswordForUser(UserInterface $user)
 {
     $password = Helper::generateRandomPassword();
     $user->setPassword($password);
     $this->manager->updateResource($user);
     $this->mailerHelper->sendEmail(['recipient' => $user->getEmail(), 'subject' => 'user.email.title.reset_password', 'template' => 'WellCommerceAdminBundle:Admin/Email:reset_password.html.twig', 'parameters' => ['user' => $user, 'password' => $password], 'configuration' => $this->shopStorage->getCurrentShop()->getMailerConfiguration()]);
 }
 private function findLayoutBox($identifier) : LayoutBoxInterface
 {
     $layoutBox = $this->manager->getRepository()->findOneBy(['identifier' => $identifier]);
     if (!$layoutBox instanceof LayoutBoxInterface) {
         throw new LayoutBoxNotFoundException($identifier);
     }
     return $layoutBox;
 }
 private function getProductDistinction(ProductInterface $product, ProductStatusInterface $status) : ProductDistinctionInterface
 {
     $distinction = $this->manager->getRepository()->findOneBy(['product' => $product, 'status' => $status]);
     if (!$distinction instanceof ProductDistinctionInterface) {
         /** @var ProductDistinctionInterface $distinction */
         $distinction = $this->manager->initResource();
         $distinction->setProduct($product);
         $distinction->setStatus($status);
     }
     return $distinction;
 }
 /**
  * Returns the resource by its identifier or throws an exception if it was not found
  *
  * @param integer $identifier
  *
  * @return object
  * @throws ResourceNotFoundException
  */
 protected function getResourceById($identifier)
 {
     $resource = $this->manager->getRepository()->find($identifier);
     if (null === $resource) {
         throw new ResourceNotFoundException($this->getResourceType(), $identifier);
     }
     return $resource;
 }
Esempio n. 5
0
 private function getResourceById(int $identifier) : EntityInterface
 {
     $resource = $this->manager->getRepository()->find($identifier);
     if (null === $resource) {
         throw new ResourceNotFoundException($this->getResourceType(), $identifier);
     }
     return $resource;
 }
 public function upload(UploadedFile $file, $dir) : MediaInterface
 {
     if (!$file->isValid()) {
         throw new InvalidMediaException('Passed file object is not valid');
     }
     /** @var MediaInterface $media */
     $media = $this->manager->initResource();
     $media->setName($file->getClientOriginalName());
     $media->setExtension($file->guessClientExtension());
     $media->setMime($file->getClientMimeType());
     $media->setSize($file->getClientSize());
     $errors = $this->validatorHelper->validate($media);
     if (0 !== count($errors)) {
         throw new InvalidMediaException($errors);
     }
     $this->manager->createResource($media);
     $file->move($this->getUploadDir($dir), $media->getPath());
     return $media;
 }
 public function generate(string $name, $id, string $locale, $values, int $iteration = 0) : string
 {
     $slug = Sluggable::makeSlug($name);
     $existsInValues = in_array($slug, (array) $values);
     // if slug is the same as other values, try to add locale part
     if ($existsInValues) {
         $slug = sprintf('%s-%s', $slug, $locale);
     }
     $route = $this->manager->getRepository()->findOneBy(['path' => $slug]);
     if (null !== $route) {
         // if passed identifier and locale are same as in route, assume we can change the slug directly
         if ($this->hasRouteSameLocaleAndId($route, $locale, $id)) {
             return $slug;
         } else {
             $iteration++;
             $slug = $this->makeSlugIterated($slug, $iteration);
             return $this->generate($slug, $id, $locale, $values, $iteration);
         }
     }
     return $slug;
 }
 /**
  * Automatic register process
  *
  * @param FacebookUser $facebookUser
  *
  * @return ClientInterface
  */
 protected function autoRegisterClient(FacebookUser $facebookUser)
 {
     $firstName = $facebookUser->getFirstName();
     $lastName = $facebookUser->getLastName();
     $email = $facebookUser->getEmail();
     /** @var $client ClientInterface */
     $client = $this->clientManager->initResource();
     $client->getClientDetails()->setUsername($email);
     $client->getClientDetails()->setPassword(Helper::generateRandomPassword());
     $client->getContactDetails()->setEmail($email);
     $client->getContactDetails()->setFirstName($firstName);
     $client->getContactDetails()->setLastName($lastName);
     $client->getContactDetails()->setPhone(' ');
     $client->getContactDetails()->setSecondaryPhone(' ');
     $this->clientManager->createResource($client);
     return $client;
 }
 private function findLocale(string $code) : LocaleInterface
 {
     return $this->localeManager->getRepository()->findOneBy(['code' => $code]);
 }