vendor/bitbag/wishlist-plugin/src/Resolver/WishlistsResolver.php line 42

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file was created by developers working at BitBag
  4.  * Do you need more information about us and what we do? Visit our https://bitbag.io website!
  5.  * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
  6. */
  7. declare(strict_types=1);
  8. namespace BitBag\SyliusWishlistPlugin\Resolver;
  9. use BitBag\SyliusWishlistPlugin\Repository\WishlistRepositoryInterface;
  10. use Sylius\Component\Channel\Context\ChannelContextInterface;
  11. use Sylius\Component\Channel\Context\ChannelNotFoundException;
  12. use Sylius\Component\Core\Model\ChannelInterface;
  13. use Sylius\Component\Core\Model\ShopUserInterface;
  14. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  15. final class WishlistsResolver implements WishlistsResolverInterface
  16. {
  17.     private WishlistRepositoryInterface $wishlistRepository;
  18.     private TokenStorageInterface $tokenStorage;
  19.     private WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver;
  20.     private ChannelContextInterface $channelContext;
  21.     public function __construct(
  22.         WishlistRepositoryInterface $wishlistRepository,
  23.         TokenStorageInterface $tokenStorage,
  24.         WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver,
  25.         ChannelContextInterface $channelContext
  26.     ) {
  27.         $this->wishlistRepository $wishlistRepository;
  28.         $this->tokenStorage $tokenStorage;
  29.         $this->wishlistCookieTokenResolver $wishlistCookieTokenResolver;
  30.         $this->channelContext $channelContext;
  31.     }
  32.     public function resolve(): array
  33.     {
  34.         $user $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
  35.         $wishlistCookieToken $this->wishlistCookieTokenResolver->resolve();
  36.         try {
  37.             $channel $this->channelContext->getChannel();
  38.         } catch (ChannelNotFoundException $foundException) {
  39.             $channel null;
  40.         }
  41.         if ($user instanceof ShopUserInterface) {
  42.             return $this->wishlistRepository->findAllByShopUserAndToken($user->getId(), $wishlistCookieToken);
  43.         }
  44.         if ($channel instanceof ChannelInterface) {
  45.             return $this->wishlistRepository->findAllByAnonymousAndChannel($wishlistCookieToken$channel);
  46.         }
  47.         return $this->wishlistRepository->findAllByAnonymous($wishlistCookieToken);
  48.     }
  49. }