1 <?php
2 /**
3 * @author Krzysztof Gzocha <krzysztof.gzocha@xsolve.pl>
4 */
5 namespace Team3\PayU\Order\Model\Products;
6
7 use Team3\PayU\Order\Model\IsFilledTrait;
8 use Team3\PayU\Order\Model\Money\Money;
9 use Team3\PayU\Order\Model\Money\MoneyInterface;
10 use JMS\Serializer\Annotation as JMS;
11 use Symfony\Component\Validator\Constraints as Assert;
12
13 /**
14 * Class Product
15 * @package Team3\PayU\Order\Model\Products
16 * @JMS\AccessorOrder("alphabetical")
17 */
18 class Product implements ProductInterface
19 {
20 use IsFilledTrait;
21
22 /**
23 * @var string
24 * @JMS\Type("string")
25 * @Assert\NotBlank()
26 */
27 protected $name;
28
29 /**
30 * @var MoneyInterface
31 * @JMS\SerializedName("unitPrice")
32 * @JMS\Accessor(
33 * getter="getUnitPriceForSerialization",
34 * setter="setUnitPriceFromDeserialization"
35 * )
36 * @JMS\Type("integer")
37 * @Assert\NotBlank()
38 * @Assert\Valid()
39 * @Assert\Type(type="object")
40 */
41 protected $unitPrice;
42
43 /**
44 * @var int
45 * @JMS\Type("integer")
46 * @Assert\NotBlank()
47 * @Assert\Type(type="integer")
48 * @Assert\GreaterThan(0)
49 */
50 protected $quantity;
51
52 /**
53 * @return string
54 */
55 public function getName()
56 {
57 return $this->name;
58 }
59
60 /**
61 * @param string $name
62 *
63 * @return Product
64 */
65 public function setName($name)
66 {
67 $this->name = $name;
68
69 return $this;
70 }
71
72 /**
73 * @return int
74 */
75 public function getQuantity()
76 {
77 return $this->quantity;
78 }
79
80 /**
81 * @param int $quantity
82 *
83 * @return Product
84 */
85 public function setQuantity($quantity)
86 {
87 $this->quantity = $quantity;
88
89 return $this;
90 }
91
92 /**
93 * @return MoneyInterface
94 */
95 public function getUnitPrice()
96 {
97 return $this->unitPrice;
98 }
99
100 /**
101 * @return int
102 */
103 public function getUnitPriceForSerialization()
104 {
105 return $this->unitPrice->getValueWithoutSeparation(2);
106 }
107
108 /**
109 * @param MoneyInterface $unitPrice
110 *
111 * @return Product
112 */
113 public function setUnitPrice(MoneyInterface $unitPrice)
114 {
115 $this->unitPrice = $unitPrice;
116
117 return $this;
118 }
119
120 /**
121 * @param int $price
122 *
123 * @return $this
124 */
125 public function setUnitPriceFromDeserialization($price)
126 {
127 $this->unitPrice = new Money($price / 100);
128
129 return $this;
130 }
131 }
132