commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
CustomerGroupModel.php
1<?php
2
3declare(strict_types=1);
10
23use DateTimeImmutable;
24use stdClass;
25
29final class CustomerGroupModel extends JsonObjectModel implements CustomerGroup
30{
35 protected $id;
36
41 protected $version;
42
47 protected $createdAt;
48
53 protected $lastModifiedAt;
54
59 protected $lastModifiedBy;
60
65 protected $createdBy;
66
71 protected $key;
72
77 protected $name;
78
83 protected $custom;
84
85
89 public function __construct(
90 ?string $id = null,
91 ?int $version = null,
92 ?DateTimeImmutable $createdAt = null,
93 ?DateTimeImmutable $lastModifiedAt = null,
95 ?CreatedBy $createdBy = null,
96 ?string $key = null,
97 ?string $name = null,
98 ?CustomFields $custom = null
99 ) {
100 $this->id = $id;
101 $this->version = $version;
102 $this->createdAt = $createdAt;
103 $this->lastModifiedAt = $lastModifiedAt;
104 $this->lastModifiedBy = $lastModifiedBy;
105 $this->createdBy = $createdBy;
106 $this->key = $key;
107 $this->name = $name;
108 $this->custom = $custom;
109 }
110
117 public function getId()
118 {
119 if (is_null($this->id)) {
121 $data = $this->raw(self::FIELD_ID);
122 if (is_null($data)) {
123 return null;
124 }
125 $this->id = (string) $data;
126 }
127
128 return $this->id;
129 }
130
137 public function getVersion()
138 {
139 if (is_null($this->version)) {
141 $data = $this->raw(self::FIELD_VERSION);
142 if (is_null($data)) {
143 return null;
144 }
145 $this->version = (int) $data;
146 }
147
148 return $this->version;
149 }
150
157 public function getCreatedAt()
158 {
159 if (is_null($this->createdAt)) {
161 $data = $this->raw(self::FIELD_CREATED_AT);
162 if (is_null($data)) {
163 return null;
164 }
165 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
166 if (false === $data) {
167 return null;
168 }
169 $this->createdAt = $data;
170 }
171
172 return $this->createdAt;
173 }
174
181 public function getLastModifiedAt()
182 {
183 if (is_null($this->lastModifiedAt)) {
185 $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
186 if (is_null($data)) {
187 return null;
188 }
189 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
190 if (false === $data) {
191 return null;
192 }
193 $this->lastModifiedAt = $data;
194 }
195
197 }
198
205 public function getLastModifiedBy()
206 {
207 if (is_null($this->lastModifiedBy)) {
209 $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
210 if (is_null($data)) {
211 return null;
212 }
213
214 $this->lastModifiedBy = LastModifiedByModel::of($data);
215 }
216
218 }
219
226 public function getCreatedBy()
227 {
228 if (is_null($this->createdBy)) {
230 $data = $this->raw(self::FIELD_CREATED_BY);
231 if (is_null($data)) {
232 return null;
233 }
234
235 $this->createdBy = CreatedByModel::of($data);
236 }
237
238 return $this->createdBy;
239 }
240
247 public function getKey()
248 {
249 if (is_null($this->key)) {
251 $data = $this->raw(self::FIELD_KEY);
252 if (is_null($data)) {
253 return null;
254 }
255 $this->key = (string) $data;
256 }
257
258 return $this->key;
259 }
260
267 public function getName()
268 {
269 if (is_null($this->name)) {
271 $data = $this->raw(self::FIELD_NAME);
272 if (is_null($data)) {
273 return null;
274 }
275 $this->name = (string) $data;
276 }
277
278 return $this->name;
279 }
280
287 public function getCustom()
288 {
289 if (is_null($this->custom)) {
291 $data = $this->raw(self::FIELD_CUSTOM);
292 if (is_null($data)) {
293 return null;
294 }
295
296 $this->custom = CustomFieldsModel::of($data);
297 }
298
299 return $this->custom;
300 }
301
302
306 public function setId(?string $id): void
307 {
308 $this->id = $id;
309 }
310
314 public function setVersion(?int $version): void
315 {
316 $this->version = $version;
317 }
318
322 public function setCreatedAt(?DateTimeImmutable $createdAt): void
323 {
324 $this->createdAt = $createdAt;
325 }
326
330 public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
331 {
332 $this->lastModifiedAt = $lastModifiedAt;
333 }
334
339 {
340 $this->lastModifiedBy = $lastModifiedBy;
341 }
342
346 public function setCreatedBy(?CreatedBy $createdBy): void
347 {
348 $this->createdBy = $createdBy;
349 }
350
354 public function setKey(?string $key): void
355 {
356 $this->key = $key;
357 }
358
362 public function setName(?string $name): void
363 {
364 $this->name = $name;
365 }
366
370 public function setCustom(?CustomFields $custom): void
371 {
372 $this->custom = $custom;
373 }
374
375
376 #[\ReturnTypeWillChange]
377 public function jsonSerialize()
378 {
379 $data = $this->toArray();
380 if (isset($data[CustomerGroup::FIELD_CREATED_AT]) && $data[CustomerGroup::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
381 $data[CustomerGroup::FIELD_CREATED_AT] = $data[CustomerGroup::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
382 }
383
384 if (isset($data[CustomerGroup::FIELD_LAST_MODIFIED_AT]) && $data[CustomerGroup::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
385 $data[CustomerGroup::FIELD_LAST_MODIFIED_AT] = $data[CustomerGroup::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
386 }
387 return (object) $data;
388 }
389}
__construct(?string $id=null, ?int $version=null, ?DateTimeImmutable $createdAt=null, ?DateTimeImmutable $lastModifiedAt=null, ?LastModifiedBy $lastModifiedBy=null, ?CreatedBy $createdBy=null, ?string $key=null, ?string $name=null, ?CustomFields $custom=null)