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
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Sylius\Component\Product\Model; |
15
|
|
|
|
16
|
|
|
use Sylius\Component\Resource\Model\TranslatableTrait; |
17
|
|
|
use Sylius\Component\Resource\Model\TranslationInterface; |
18
|
|
|
|
19
|
|
|
class ProductOptionValue implements ProductOptionValueInterface |
20
|
|
|
{ |
21
|
|
|
use TranslatableTrait { |
22
|
|
|
__construct as private initializeTranslationCollection; |
23
|
|
|
getTranslation as private doGetTranslation; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var mixed |
28
|
|
|
*/ |
29
|
|
|
protected $id; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $code; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var ProductOptionInterface |
38
|
|
|
*/ |
39
|
|
|
protected $option; |
40
|
|
|
|
41
|
|
|
public function __construct() |
42
|
|
|
{ |
43
|
|
|
$this->initializeTranslationCollection(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function __toString(): string |
50
|
|
|
{ |
51
|
|
|
return (string) $this->getValue(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function getId() |
58
|
|
|
{ |
59
|
|
|
return $this->id; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
public function getCode(): ?string |
66
|
|
|
{ |
67
|
|
|
return $this->code; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function setCode(?string $code): void |
74
|
|
|
{ |
75
|
|
|
$this->code = $code; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
|
|
public function getOption(): ?ProductOptionInterface |
82
|
|
|
{ |
83
|
|
|
return $this->option; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
|
|
public function setOption(?ProductOptionInterface $option): void |
90
|
|
|
{ |
91
|
|
|
$this->option = $option; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
|
|
public function getValue(): ?string |
98
|
|
|
{ |
99
|
|
|
return $this->getTranslation()->getValue(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritdoc} |
104
|
|
|
*/ |
105
|
|
|
public function setValue(?string $value): void |
106
|
|
|
{ |
107
|
|
|
$this->getTranslation()->setValue($value); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* {@inheritdoc} |
112
|
|
|
* |
113
|
|
|
* @throws \BadMethodCallException |
114
|
|
|
*/ |
115
|
|
|
public function getOptionCode(): ?string |
116
|
|
|
{ |
117
|
|
|
if (null === $this->option) { |
118
|
|
|
throw new \BadMethodCallException( |
119
|
|
|
'The option have not been created yet so you cannot access proxy methods.' |
120
|
|
|
); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return $this->option->getCode(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* {@inheritdoc} |
128
|
|
|
* |
129
|
|
|
* @throws \BadMethodCallException |
130
|
|
|
*/ |
131
|
|
|
public function getName(): ?string |
132
|
|
|
{ |
133
|
|
|
if (null === $this->option) { |
134
|
|
|
throw new \BadMethodCallException( |
135
|
|
|
'The option have not been created yet so you cannot access proxy methods.' |
136
|
|
|
); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
return $this->option->getName(); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param string|null $locale |
144
|
|
|
* |
145
|
|
|
* @return ProductOptionValueTranslationInterface |
146
|
|
|
*/ |
147
|
|
|
public function getTranslation(?string $locale = null): TranslationInterface |
148
|
|
|
{ |
149
|
|
|
/** @var ProductOptionValueTranslationInterface $translation */ |
150
|
|
|
$translation = $this->doGetTranslation($locale); |
151
|
|
|
|
152
|
|
|
return $translation; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* {@inheritdoc} |
157
|
|
|
*/ |
158
|
|
|
protected function createTranslation(): ProductOptionValueTranslationInterface |
159
|
|
|
{ |
160
|
|
|
return new ProductOptionValueTranslation(); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|