|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file was created by developers working at BitBag |
|
5
|
|
|
* Do you need more information about us and what we do? Visit our https://bitbag.io website! |
|
6
|
|
|
* 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 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
declare(strict_types=1); |
|
10
|
|
|
|
|
11
|
|
|
namespace BitBag\SyliusWishlistPlugin\Resolver; |
|
12
|
|
|
|
|
13
|
|
|
use BitBag\SyliusWishlistPlugin\Repository\WishlistRepositoryInterface; |
|
14
|
|
|
use Sylius\Component\Core\Model\ShopUserInterface; |
|
15
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
16
|
|
|
|
|
17
|
|
|
final class WishlistsResolver implements WishlistsResolverInterface |
|
18
|
|
|
{ |
|
19
|
|
|
private WishlistRepositoryInterface $wishlistRepository; |
|
20
|
|
|
|
|
21
|
|
|
private TokenStorageInterface $tokenStorage; |
|
22
|
|
|
|
|
23
|
|
|
private WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver; |
|
24
|
|
|
|
|
25
|
|
|
public function __construct( |
|
26
|
|
|
WishlistRepositoryInterface $wishlistRepository, |
|
27
|
|
|
TokenStorageInterface $tokenStorage, |
|
28
|
|
|
WishlistCookieTokenResolverInterface $wishlistCookieTokenResolver |
|
29
|
|
|
) { |
|
30
|
|
|
$this->wishlistRepository = $wishlistRepository; |
|
31
|
|
|
$this->tokenStorage = $tokenStorage; |
|
32
|
|
|
$this->wishlistCookieTokenResolver = $wishlistCookieTokenResolver; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function resolve(): array |
|
36
|
|
|
{ |
|
37
|
|
|
$user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; |
|
38
|
|
|
|
|
39
|
|
|
if ($user instanceof ShopUserInterface) { |
|
40
|
|
|
return $this->wishlistRepository->findAllByShopUser($user->getId()); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$wishlistCookieToken = $this->wishlistCookieTokenResolver->resolve(); |
|
44
|
|
|
|
|
45
|
|
|
return $this->wishlistRepository->findAllByAnonymous($wishlistCookieToken); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|