|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file has been created by developers from BitBag. |
|
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
|
6
|
|
|
* another great project. |
|
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
|
8
|
|
|
* an email on [email protected]. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types=1); |
|
12
|
|
|
|
|
13
|
|
|
namespace BitBag\SyliusWishlistPlugin\Entity; |
|
14
|
|
|
|
|
15
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
16
|
|
|
use Doctrine\Common\Collections\Collection; |
|
17
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
|
18
|
|
|
use Sylius\Component\Core\Model\ProductVariantInterface; |
|
19
|
|
|
use Sylius\Component\Core\Model\ShopUserInterface; |
|
20
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
|
21
|
|
|
|
|
22
|
|
|
class Wishlist implements WishlistInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var int */ |
|
25
|
|
|
protected $id; |
|
26
|
|
|
|
|
27
|
|
|
/** @var Collection|WishlistProductInterface[] */ |
|
28
|
|
|
protected $wishlistProducts; |
|
29
|
|
|
|
|
30
|
|
|
/** @var ShopUserInterface|null */ |
|
31
|
|
|
protected $shopUser; |
|
32
|
|
|
|
|
33
|
|
|
/** @var TokenInterface|null */ |
|
34
|
|
|
protected $token; |
|
35
|
|
|
|
|
36
|
|
|
public function __construct() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->wishlistProducts = new ArrayCollection(); |
|
39
|
|
|
$this->token = new WishlistToken(); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function getId(): ?int |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->id; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function getProducts(): Collection |
|
48
|
|
|
{ |
|
49
|
|
|
$products = []; |
|
50
|
|
|
|
|
51
|
|
|
foreach ($this->wishlistProducts as $wishlistProduct) { |
|
52
|
|
|
$products[] = $wishlistProduct->getProduct(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return new ArrayCollection($products); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function getProductVariants(): Collection |
|
59
|
|
|
{ |
|
60
|
|
|
$variants = []; |
|
61
|
|
|
|
|
62
|
|
|
foreach ($this->wishlistProducts as $wishlistProduct) { |
|
63
|
|
|
$variants[] = $wishlistProduct->getVariant(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return new ArrayCollection($variants); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function hasProductVariant(ProductVariantInterface $productVariant): bool |
|
70
|
|
|
{ |
|
71
|
|
|
foreach ($this->wishlistProducts as $wishlistProduct) { |
|
72
|
|
|
if ($productVariant === $wishlistProduct->getVariant()) { |
|
73
|
|
|
return true; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return false; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function getWishlistProducts(): Collection |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->wishlistProducts; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function hasProduct(ProductInterface $product): bool |
|
86
|
|
|
{ |
|
87
|
|
|
foreach ($this->wishlistProducts as $wishlistProduct) { |
|
88
|
|
|
if ($product === $wishlistProduct->getProduct()) { |
|
89
|
|
|
return true; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return false; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function setWishlistProducts(Collection $wishlistProducts): void |
|
97
|
|
|
{ |
|
98
|
|
|
$this->wishlistProducts = $wishlistProducts; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function hasWishlistProduct(WishlistProductInterface $wishlistProduct): bool |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->wishlistProducts->contains($wishlistProduct); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function addWishlistProduct(WishlistProductInterface $wishlistProduct): void |
|
107
|
|
|
{ |
|
108
|
|
|
if (!$this->hasProductVariant($wishlistProduct->getVariant())) { |
|
109
|
|
|
$wishlistProduct->setWishlist($this); |
|
110
|
|
|
$this->wishlistProducts->add($wishlistProduct); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function getShopUser(): ?ShopUserInterface |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->shopUser; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function setShopUser(ShopUserInterface $shopUser): void |
|
120
|
|
|
{ |
|
121
|
|
|
$this->shopUser = $shopUser; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function getToken(): string |
|
125
|
|
|
{ |
|
126
|
|
|
return (string) $this->token; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function setToken(string $token): void |
|
130
|
|
|
{ |
|
131
|
|
|
$this->token = new WishlistToken($token); |
|
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..