vendor/boldr/allergen-bundle/src/Presenter/ViewProcessor.php line 24

Open in your IDE?
  1. <?php
  2. namespace Boldr\Shop\AllergenBundle\Presenter;
  3. use Boldr\Shop\ShopBundle\Entity\ProductVariant;
  4. use Boldr\Shop\AllergenBundle\Entity\ProductAllergens;
  5. use Boldr\Shop\ShopBundle\Presenter\Product\{ ProductVariantViewProductVariantViewProcessorInterface };
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Contracts\Cache\TagAwareCacheInterface;
  8. class ViewProcessor implements ProductVariantViewProcessorInterface
  9. {
  10.     private EntityManagerInterface $em;
  11.     private TagAwareCacheInterface $cache;
  12.     public function __construct(EntityManagerInterface $emTagAwareCacheInterface $cache)
  13.     {
  14.         $this->em $em;
  15.         $this->cache $cache;
  16.     }
  17.     public function processProductVariantView(ProductVariantView $productVariantViewProductVariant $productVariantstring $locale): ProductVariantView
  18.     {
  19.         $product $productVariant->getProduct();
  20.         $productVariantView->allergens $this->cache->get('boldr_allergens.product_allergens.'$product->getId(), function($item) use ($product) {
  21.             $item->tag('boldr_shop.product.'$product->getId());
  22.             $productAllergensRepository $this->em->getRepository(ProductAllergens::class);
  23.             $productAllergens $productAllergensRepository->find($product);
  24.             if ($productAllergens === null)
  25.             {
  26.                 $productAllergens = new ProductAllergens($product);
  27.             }
  28.             return new ProductAllergensView(
  29.                 $productAllergens->getGluten(),
  30.                 $productAllergens->getEgg(),
  31.                 $productAllergens->getFish(),
  32.                 $productAllergens->getPeanut(),
  33.                 $productAllergens->getNuts(),
  34.                 $productAllergens->getSoy(),
  35.                 $productAllergens->getMilk(),
  36.                 $productAllergens->getShellfish(),
  37.                 $productAllergens->getMollusks(),
  38.                 $productAllergens->getCelery(),
  39.                 $productAllergens->getMustard(),
  40.                 $productAllergens->getSesame(),
  41.                 $productAllergens->getSulfites(),
  42.                 $productAllergens->getLupine()
  43.             );
  44.         });
  45.         return $productVariantView;
  46.     }
  47. }