|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SyliusCart\Domain\Event; |
|
4
|
|
|
|
|
5
|
|
|
use Broadway\Serializer\SerializableInterface; |
|
6
|
|
|
use Ramsey\Uuid\Uuid; |
|
7
|
|
|
use Ramsey\Uuid\UuidInterface; |
|
8
|
|
|
use SyliusCart\Domain\ValueObject\CartItemQuantity; |
|
9
|
|
|
use SyliusCart\Domain\ValueObject\ProductCode; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
final class CartItemQuantityChanged implements SerializableInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var UuidInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
private $cartId; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var ProductCode |
|
23
|
|
|
*/ |
|
24
|
|
|
private $productCode; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var CartItemQuantity |
|
28
|
|
|
*/ |
|
29
|
|
|
private $oldCartItemQuantity; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var CartItemQuantity |
|
33
|
|
|
*/ |
|
34
|
|
|
private $newCartItemQuantity; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param UuidInterface $cartId |
|
38
|
|
|
* @param ProductCode $productCode |
|
39
|
|
|
* @param CartItemQuantity $oldCartItemQuantity |
|
40
|
|
|
* @param CartItemQuantity $newCartItemQuantity |
|
41
|
|
|
*/ |
|
42
|
|
|
private function __construct( |
|
43
|
|
|
UuidInterface $cartId, |
|
44
|
|
|
ProductCode $productCode, |
|
45
|
|
|
CartItemQuantity $oldCartItemQuantity, |
|
46
|
|
|
CartItemQuantity $newCartItemQuantity |
|
47
|
|
|
) { |
|
48
|
|
|
$this->cartId = $cartId; |
|
49
|
|
|
$this->productCode = $productCode; |
|
50
|
|
|
$this->oldCartItemQuantity = $oldCartItemQuantity; |
|
51
|
|
|
$this->newCartItemQuantity = $newCartItemQuantity; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param UuidInterface $cartId |
|
56
|
|
|
* @param ProductCode $productCode |
|
57
|
|
|
* @param CartItemQuantity $oldCartItemQuantity |
|
58
|
|
|
* @param CartItemQuantity $newCartItemQuantity |
|
59
|
|
|
* |
|
60
|
|
|
* @return CartItemQuantityChanged |
|
61
|
|
|
*/ |
|
62
|
|
|
public static function occur( |
|
63
|
|
|
UuidInterface $cartId, |
|
64
|
|
|
ProductCode $productCode, |
|
65
|
|
|
CartItemQuantity $oldCartItemQuantity, |
|
66
|
|
|
CartItemQuantity $newCartItemQuantity |
|
67
|
|
|
): self { |
|
68
|
|
|
return new self($cartId, $productCode, $oldCartItemQuantity, $newCartItemQuantity); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return UuidInterface |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getCartId(): UuidInterface |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->cartId; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return ProductCode |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getProductCode(): ProductCode |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->productCode; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return CartItemQuantity |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getOldCartItemQuantity(): CartItemQuantity |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->oldCartItemQuantity; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return CartItemQuantity |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getNewCartItemQuantity(): CartItemQuantity |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->newCartItemQuantity; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* {@inheritdoc} |
|
105
|
|
|
*/ |
|
106
|
|
|
public static function deserialize(array $data): self |
|
107
|
|
|
{ |
|
108
|
|
|
return new self( |
|
109
|
|
|
Uuid::fromString($data['cartId']), |
|
110
|
|
|
ProductCode::fromString($data['productCode']), |
|
111
|
|
|
CartItemQuantity::create($data['oldCartItemQuantity']), |
|
112
|
|
|
CartItemQuantity::create($data['newCartItemQuantity']) |
|
113
|
|
|
); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* {@inheritdoc} |
|
118
|
|
|
*/ |
|
119
|
|
|
public function serialize(): array |
|
120
|
|
|
{ |
|
121
|
|
|
return [ |
|
122
|
|
|
'cartId' => (string) $this->cartId, |
|
123
|
|
|
'productCode' => (string) $this->productCode, |
|
124
|
|
|
'oldCartItemQuantity' => $this->oldCartItemQuantity->getNumber(), |
|
125
|
|
|
'newCartItemQuantity' => $this->newCartItemQuantity->getNumber(), |
|
126
|
|
|
]; |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|