Esempio n. 1
0
 /**
  * Checks if the passed value is valid.
  *
  * @param string $value The value that should be validated
  * @param IsAvailable|Constraint $constraint The constraint for the validation
  */
 public function validate($value, Constraint $constraint)
 {
     $available = $this->repository->getAvailability($value);
     if (!$available) {
         $this->context->buildViolation($constraint->message)->addViolation();
     }
 }
 public function onProductSave(ProductSavedEvent $event)
 {
     $product = $event->getProduct();
     $this->repository->saveAvailability($product->getId()->getValue(), $product->isAvailable());
     if ($this->persister->handlesObject($product)) {
         $this->persister->insertOne($product);
     }
 }
Esempio n. 3
0
 /**
  * @inheritDoc
  */
 public function collect() : \Iterator
 {
     $generator = function () {
         foreach ($this->repository->findAllIds() as $id) {
             foreach ($this->locales as $locale) {
                 (yield $this->router->generate('product', ['id' => $id, '_locale' => $locale], RouterInterface::ABSOLUTE_URL));
             }
         }
     };
     return $generator();
 }
Esempio n. 4
0
 /**
  * Do the initialization logic
  *
  * @return void
  */
 protected function doInitialize()
 {
     $collection = $this->collection;
     $ids = $collection->getKeys();
     $products = $this->repository->findByIds($ids);
     $this->collection = new ArrayCollection();
     foreach ($products as $product) {
         $lineItem = LineItemView::create($product, $collection->get($product->getId()));
         $this->collection->set($product->getId(), $lineItem);
     }
 }
Esempio n. 5
0
 /**
  * @inheritDoc
  */
 public function findAllIds()
 {
     return $this->repository->findAllIds();
 }
Esempio n. 6
0
 public function getProductAvailabilityById(GetProductAvailabilityByIdQuery $query)
 {
     $result = $this->viewRepository->getAvailability($query->getId());
     $query->setResult($result);
 }