1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Component\Product\Model; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
15
|
|
|
use Doctrine\Common\Collections\Collection; |
16
|
|
|
use Sylius\Component\Resource\Model\TimestampableTrait; |
17
|
|
|
use Sylius\Component\Resource\Model\TranslatableTrait; |
18
|
|
|
use Sylius\Component\Resource\Model\TranslationInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
22
|
|
|
* @author Gonzalo Vilaseca <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class ProductOption implements ProductOptionInterface |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
use TimestampableTrait; |
27
|
|
|
use TranslatableTrait { |
28
|
|
|
__construct as private initializeTranslationsCollection; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var mixed |
33
|
|
|
*/ |
34
|
|
|
protected $id; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $code; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var Collection|ProductOptionValueInterface[] |
43
|
|
|
*/ |
44
|
|
|
protected $values; |
45
|
|
|
|
46
|
|
|
public function __construct() |
47
|
|
|
{ |
48
|
|
|
$this->initializeTranslationsCollection(); |
49
|
|
|
|
50
|
|
|
$this->values = new ArrayCollection(); |
51
|
|
|
$this->createdAt = new \DateTime(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function __toString() |
58
|
|
|
{ |
59
|
|
|
return $this->getName(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
public function getId() |
66
|
|
|
{ |
67
|
|
|
return $this->id; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function getCode() |
74
|
|
|
{ |
75
|
|
|
return $this->code; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
|
|
public function setCode($code) |
82
|
|
|
{ |
83
|
|
|
$this->code = $code; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
|
|
public function getName() |
90
|
|
|
{ |
91
|
|
|
return $this->getTranslation()->getName(); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
|
|
public function setName($name) |
98
|
|
|
{ |
99
|
|
|
$this->getTranslation()->setName($name); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritdoc} |
104
|
|
|
*/ |
105
|
|
|
public function getValues() |
106
|
|
|
{ |
107
|
|
|
return $this->values; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* {@inheritdoc} |
112
|
|
|
*/ |
113
|
|
|
public function addValue(ProductOptionValueInterface $value) |
114
|
|
|
{ |
115
|
|
|
if (!$this->hasValue($value)) { |
116
|
|
|
$value->setOption($this); |
117
|
|
|
$this->values->add($value); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* {@inheritdoc} |
123
|
|
|
*/ |
124
|
|
|
public function removeValue(ProductOptionValueInterface $value) |
125
|
|
|
{ |
126
|
|
|
if ($this->hasValue($value)) { |
127
|
|
|
$this->values->removeElement($value); |
128
|
|
|
$value->setOption(null); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* {@inheritdoc} |
134
|
|
|
*/ |
135
|
|
|
public function hasValue(ProductOptionValueInterface $value) |
136
|
|
|
{ |
137
|
|
|
return $this->values->contains($value); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* {@inheritdoc} |
142
|
|
|
*/ |
143
|
|
|
protected function createTranslation() |
144
|
|
|
{ |
145
|
|
|
return new ProductOptionTranslation(); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|