1 | <?php |
||
2 | |||
3 | namespace GGGGino\SkuskuCartBundle\Model; |
||
4 | |||
5 | use Doctrine\Common\Collections\ArrayCollection; |
||
6 | use Doctrine\Common\Collections\Criteria; |
||
7 | use Doctrine\ORM\Mapping as ORM; |
||
8 | |||
9 | /** |
||
10 | * Skusku |
||
11 | * |
||
12 | * @ORM\Table(name="skusku_cart") |
||
13 | * @ORM\Entity(repositoryClass="GGGGino\SkuskuCartBundle\Repository\CartRepository") |
||
14 | */ |
||
15 | class SkuskuCart |
||
16 | { |
||
17 | const STATUS_INITIAL = 0; |
||
18 | const STATUS_ORDERED = 1; |
||
19 | /** |
||
20 | * @var int |
||
21 | * |
||
22 | * @ORM\Column(name="id", type="integer") |
||
23 | * @ORM\Id |
||
24 | * @ORM\GeneratedValue(strategy="AUTO") |
||
25 | */ |
||
26 | private $id; |
||
27 | |||
28 | /** |
||
29 | * @ORM\OneToMany(targetEntity="SkuskuCartProduct", mappedBy="cart", fetch="EXTRA_LAZY", cascade={"remove"}, orphanRemoval=true) |
||
30 | */ |
||
31 | private $products; |
||
32 | |||
33 | /** |
||
34 | * @ORM\OneToOne(targetEntity="SkuskuPayment", inversedBy="cart") |
||
35 | * @ORM\JoinColumn(name="payment", referencedColumnName="id") |
||
36 | */ |
||
37 | private $payment; |
||
38 | |||
39 | /** |
||
40 | * @ORM\OneToOne(targetEntity="SkuskuOrder", mappedBy="cart") |
||
41 | */ |
||
42 | private $order; |
||
43 | |||
44 | /** |
||
45 | * @ORM\ManyToOne(targetEntity="SkuskuLangInterface") |
||
46 | * @ORM\JoinColumn(name="lang_id", referencedColumnName="id") |
||
47 | * @var SkuskuLangInterface |
||
48 | */ |
||
49 | protected $lang; |
||
50 | |||
51 | /** |
||
52 | * @ORM\ManyToOne(targetEntity="SkuskuCurrencyInterface") |
||
53 | * @ORM\JoinColumn(name="currency_id", referencedColumnName="id") |
||
54 | * @var SkuskuCurrencyInterface |
||
55 | */ |
||
56 | protected $currency; |
||
57 | |||
58 | /** |
||
59 | * @ORM\ManyToOne(targetEntity="SkuskuCustomerInterface") |
||
60 | * @ORM\JoinColumn(name="customer_id", referencedColumnName="id") |
||
61 | * @var SkuskuCustomerInterface |
||
62 | */ |
||
63 | protected $customer; |
||
64 | |||
65 | /** |
||
66 | * @var \DateTime |
||
67 | * |
||
68 | * @ORM\Column(name="date_add", type="datetime") |
||
69 | */ |
||
70 | private $dateAdd; |
||
71 | |||
72 | /** |
||
73 | * @var \DateTime |
||
74 | * |
||
75 | * @ORM\Column(name="date_upd", type="datetime") |
||
76 | */ |
||
77 | private $dateUpd; |
||
78 | |||
79 | /** |
||
80 | * @var int |
||
81 | * |
||
82 | * @ORM\Column(name="status", type="integer") |
||
83 | */ |
||
84 | private $status = self::STATUS_INITIAL; |
||
85 | |||
86 | /** |
||
87 | * @var string |
||
88 | * |
||
89 | * @ORM\Column(name="additional_fields", type="array", nullable=true) |
||
90 | */ |
||
91 | private $additionalFields; |
||
92 | |||
93 | |||
94 | /** |
||
95 | * Cart constructor. |
||
96 | */ |
||
97 | public function __construct() |
||
98 | { |
||
99 | $this->products = new ArrayCollection(); |
||
100 | $this->dateAdd = new \DateTime(); |
||
101 | $this->dateUpd = new \DateTime(); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Get id. |
||
106 | * |
||
107 | * @return int |
||
108 | */ |
||
109 | public function getId() |
||
110 | { |
||
111 | return $this->id; |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Set dateAdd. |
||
116 | * |
||
117 | * @param \DateTime $dateAdd |
||
118 | * |
||
119 | * @return SkuskuCart |
||
120 | */ |
||
121 | public function setDateAdd($dateAdd) |
||
122 | { |
||
123 | $this->dateAdd = $dateAdd; |
||
124 | |||
125 | return $this; |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * Get dateAdd. |
||
130 | * |
||
131 | * @return \DateTime |
||
132 | */ |
||
133 | public function getDateAdd() |
||
134 | { |
||
135 | return $this->dateAdd; |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * Set dateUpd. |
||
140 | * |
||
141 | * @param \DateTime $dateUpd |
||
142 | * |
||
143 | * @return SkuskuCart |
||
144 | */ |
||
145 | public function setDateUpd($dateUpd) |
||
146 | { |
||
147 | $this->dateUpd = $dateUpd; |
||
148 | |||
149 | return $this; |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * Get dateUpd. |
||
154 | * |
||
155 | * @return \DateTime |
||
156 | */ |
||
157 | public function getDateUpd() |
||
158 | { |
||
159 | return $this->dateUpd; |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * @return SkuskuCustomerInterface |
||
164 | */ |
||
165 | public function getCustomer() |
||
166 | { |
||
167 | return $this->customer; |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * @return ArrayCollection |
||
172 | */ |
||
173 | public function getProducts() |
||
174 | { |
||
175 | return $this->products; |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * @param SkuskuProductInterface $product |
||
180 | * @return mixed |
||
181 | */ |
||
182 | public function getProduct(SkuskuProductInterface $product) |
||
183 | { |
||
184 | $criteria = Criteria::create()->where(Criteria::expr()->eq("product", $product)); |
||
185 | |||
186 | return $this->products->matching($criteria); |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * @param mixed $products |
||
191 | * @return SkuskuCart |
||
192 | */ |
||
193 | public function setProducts($products) |
||
194 | { |
||
195 | $this->products = $products; |
||
196 | return $this; |
||
197 | } |
||
198 | /** |
||
199 | * @return SkuskuCart |
||
200 | */ |
||
201 | public function emptyProducts() |
||
202 | { |
||
203 | $this->products->clear(); |
||
204 | return $this; |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * @param SkuskuCartProductInterface $product |
||
209 | * @return SkuskuCart |
||
210 | */ |
||
211 | public function addProduct(SkuskuCartProductInterface $product) |
||
212 | { |
||
213 | $product->setCart($this); |
||
214 | |||
215 | $this->products[] = $product; |
||
216 | return $this; |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * Get the total amount of the cart |
||
221 | * |
||
222 | * @return mixed |
||
223 | */ |
||
224 | public function getTotalPrice() |
||
225 | { |
||
226 | return array_reduce($this->getProducts()->toArray(), function($carry, SkuskuCartProduct $product) { |
||
227 | return $carry + ($product->getSubtotal()); |
||
228 | }, 0); |
||
229 | } |
||
230 | |||
231 | /** |
||
232 | * Get the number of products added to the cart. |
||
233 | * Useful for cart preview |
||
234 | * |
||
235 | * @return integer |
||
236 | */ |
||
237 | public function getTotalQuantity() |
||
238 | { |
||
239 | return array_reduce($this->getProducts()->toArray(), function($carry, SkuskuCartProduct $product) { |
||
240 | return $carry + ($product->getQuantity()); |
||
241 | }, 0); |
||
242 | } |
||
243 | |||
244 | /** |
||
245 | * @return SkuskuCurrencyInterface |
||
246 | */ |
||
247 | public function getCurrency() |
||
248 | { |
||
249 | return $this->currency; |
||
250 | } |
||
251 | |||
252 | /** |
||
253 | * @param SkuskuCurrencyInterface $currency |
||
254 | * @return SkuskuCart |
||
255 | */ |
||
256 | public function setCurrency($currency) |
||
257 | { |
||
258 | $this->currency = $currency; |
||
259 | return $this; |
||
260 | } |
||
261 | |||
262 | /** |
||
263 | * @return SkuskuLangInterface |
||
264 | */ |
||
265 | public function getLang() |
||
266 | { |
||
267 | return $this->lang; |
||
268 | } |
||
269 | |||
270 | /** |
||
271 | * @param SkuskuLangInterface $lang |
||
272 | * @return SkuskuCart |
||
273 | */ |
||
274 | public function setLang($lang) |
||
275 | { |
||
276 | $this->lang = $lang; |
||
277 | return $this; |
||
278 | } |
||
279 | |||
280 | /** |
||
281 | * @param SkuskuCustomerInterface $customer |
||
282 | * @return SkuskuCart |
||
283 | */ |
||
284 | public function setCustomer($customer) |
||
285 | { |
||
286 | $this->customer = $customer; |
||
287 | return $this; |
||
288 | } |
||
289 | |||
290 | /** |
||
291 | * @return mixed |
||
292 | */ |
||
293 | public function getPayment() |
||
294 | { |
||
295 | return $this->payment; |
||
296 | } |
||
297 | |||
298 | /** |
||
299 | * @param mixed $payment |
||
300 | * @return SkuskuCart |
||
301 | */ |
||
302 | public function setPayment($payment) |
||
303 | { |
||
304 | $this->payment = $payment; |
||
305 | return $this; |
||
306 | } |
||
307 | |||
308 | /** |
||
309 | * @return int |
||
310 | */ |
||
311 | public function getStatus() |
||
312 | { |
||
313 | return $this->status; |
||
314 | } |
||
315 | |||
316 | /** |
||
317 | * @param int $status |
||
318 | * @return SkuskuCart |
||
319 | */ |
||
320 | public function setStatus($status) |
||
321 | { |
||
322 | $this->status = $status; |
||
323 | return $this; |
||
324 | } |
||
325 | |||
326 | /** |
||
327 | * Set additionalFields. |
||
328 | * |
||
329 | * @param array|null $additionalFields |
||
330 | * |
||
331 | * @return SkuskuCart |
||
332 | */ |
||
333 | public function setAdditionalFields($additionalFields = null) |
||
334 | { |
||
335 | $this->additionalFields = $additionalFields; |
||
0 ignored issues
–
show
|
|||
336 | |||
337 | return $this; |
||
338 | } |
||
339 | |||
340 | /** |
||
341 | * Get additionalFields. |
||
342 | * |
||
343 | * @return SkuskuCart |
||
344 | */ |
||
345 | public function getAdditionalFields() |
||
346 | { |
||
347 | return $this->additionalFields; |
||
0 ignored issues
–
show
|
|||
348 | } |
||
349 | } |
||
350 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.