commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
PriceDraftModel.php
1<?php
2
3declare(strict_types=1);
10
23use DateTimeImmutable;
24use stdClass;
25
29final class PriceDraftModel extends JsonObjectModel implements PriceDraft
30{
35 protected $key;
36
41 protected $value;
42
47 protected $country;
48
53 protected $customerGroup;
54
59 protected $channel;
60
65 protected $validFrom;
66
71 protected $validUntil;
72
77 protected $discounted;
78
83 protected $tiers;
84
89 protected $custom;
90
96
97
101 public function __construct(
102 ?string $key = null,
103 ?Money $value = null,
104 ?string $country = null,
107 ?DateTimeImmutable $validFrom = null,
108 ?DateTimeImmutable $validUntil = null,
113 ) {
114 $this->key = $key;
115 $this->value = $value;
116 $this->country = $country;
117 $this->customerGroup = $customerGroup;
118 $this->channel = $channel;
119 $this->validFrom = $validFrom;
120 $this->validUntil = $validUntil;
121 $this->discounted = $discounted;
122 $this->tiers = $tiers;
123 $this->custom = $custom;
124 $this->recurrencePolicy = $recurrencePolicy;
125 }
126
134 public function getKey()
135 {
136 if (is_null($this->key)) {
138 $data = $this->raw(self::FIELD_KEY);
139 if (is_null($data)) {
140 return null;
141 }
142 $this->key = (string) $data;
143 }
144
145 return $this->key;
146 }
147
155 public function getValue()
156 {
157 if (is_null($this->value)) {
159 $data = $this->raw(self::FIELD_VALUE);
160 if (is_null($data)) {
161 return null;
162 }
163
164 $this->value = MoneyModel::of($data);
165 }
166
167 return $this->value;
168 }
169
176 public function getCountry()
177 {
178 if (is_null($this->country)) {
180 $data = $this->raw(self::FIELD_COUNTRY);
181 if (is_null($data)) {
182 return null;
183 }
184 $this->country = (string) $data;
185 }
186
187 return $this->country;
188 }
189
196 public function getCustomerGroup()
197 {
198 if (is_null($this->customerGroup)) {
200 $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
201 if (is_null($data)) {
202 return null;
203 }
204
205 $this->customerGroup = CustomerGroupResourceIdentifierModel::of($data);
206 }
207
209 }
210
217 public function getChannel()
218 {
219 if (is_null($this->channel)) {
221 $data = $this->raw(self::FIELD_CHANNEL);
222 if (is_null($data)) {
223 return null;
224 }
225
226 $this->channel = ChannelResourceIdentifierModel::of($data);
227 }
228
229 return $this->channel;
230 }
231
238 public function getValidFrom()
239 {
240 if (is_null($this->validFrom)) {
242 $data = $this->raw(self::FIELD_VALID_FROM);
243 if (is_null($data)) {
244 return null;
245 }
246 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
247 if (false === $data) {
248 return null;
249 }
250 $this->validFrom = $data;
251 }
252
253 return $this->validFrom;
254 }
255
262 public function getValidUntil()
263 {
264 if (is_null($this->validUntil)) {
266 $data = $this->raw(self::FIELD_VALID_UNTIL);
267 if (is_null($data)) {
268 return null;
269 }
270 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
271 if (false === $data) {
272 return null;
273 }
274 $this->validUntil = $data;
275 }
276
277 return $this->validUntil;
278 }
279
293 public function getDiscounted()
294 {
295 if (is_null($this->discounted)) {
297 $data = $this->raw(self::FIELD_DISCOUNTED);
298 if (is_null($data)) {
299 return null;
300 }
301
302 $this->discounted = DiscountedPriceDraftModel::of($data);
303 }
304
305 return $this->discounted;
306 }
307
315 public function getTiers()
316 {
317 if (is_null($this->tiers)) {
319 $data = $this->raw(self::FIELD_TIERS);
320 if (is_null($data)) {
321 return null;
322 }
323 $this->tiers = PriceTierDraftCollection::fromArray($data);
324 }
325
326 return $this->tiers;
327 }
328
335 public function getCustom()
336 {
337 if (is_null($this->custom)) {
339 $data = $this->raw(self::FIELD_CUSTOM);
340 if (is_null($data)) {
341 return null;
342 }
343
344 $this->custom = CustomFieldsDraftModel::of($data);
345 }
346
347 return $this->custom;
348 }
349
356 public function getRecurrencePolicy()
357 {
358 if (is_null($this->recurrencePolicy)) {
360 $data = $this->raw(self::FIELD_RECURRENCE_POLICY);
361 if (is_null($data)) {
362 return null;
363 }
364
365 $this->recurrencePolicy = RecurrencePolicyResourceIdentifierModel::of($data);
366 }
367
369 }
370
371
375 public function setKey(?string $key): void
376 {
377 $this->key = $key;
378 }
379
383 public function setValue(?Money $value): void
384 {
385 $this->value = $value;
386 }
387
391 public function setCountry(?string $country): void
392 {
393 $this->country = $country;
394 }
395
400 {
401 $this->customerGroup = $customerGroup;
402 }
403
408 {
409 $this->channel = $channel;
410 }
411
415 public function setValidFrom(?DateTimeImmutable $validFrom): void
416 {
417 $this->validFrom = $validFrom;
418 }
419
423 public function setValidUntil(?DateTimeImmutable $validUntil): void
424 {
425 $this->validUntil = $validUntil;
426 }
427
432 {
433 $this->discounted = $discounted;
434 }
435
440 {
441 $this->tiers = $tiers;
442 }
443
447 public function setCustom(?CustomFieldsDraft $custom): void
448 {
449 $this->custom = $custom;
450 }
451
456 {
457 $this->recurrencePolicy = $recurrencePolicy;
458 }
459
460
461 #[\ReturnTypeWillChange]
462 public function jsonSerialize()
463 {
464 $data = $this->toArray();
465 if (isset($data[PriceDraft::FIELD_VALID_FROM]) && $data[PriceDraft::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
466 $data[PriceDraft::FIELD_VALID_FROM] = $data[PriceDraft::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
467 }
468
469 if (isset($data[PriceDraft::FIELD_VALID_UNTIL]) && $data[PriceDraft::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
470 $data[PriceDraft::FIELD_VALID_UNTIL] = $data[PriceDraft::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
471 }
472 return (object) $data;
473 }
474}
setDiscounted(?DiscountedPriceDraft $discounted)
setTiers(?PriceTierDraftCollection $tiers)
setValidUntil(?DateTimeImmutable $validUntil)
setRecurrencePolicy(?RecurrencePolicyResourceIdentifier $recurrencePolicy)
__construct(?string $key=null, ?Money $value=null, ?string $country=null, ?CustomerGroupResourceIdentifier $customerGroup=null, ?ChannelResourceIdentifier $channel=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null, ?DiscountedPriceDraft $discounted=null, ?PriceTierDraftCollection $tiers=null, ?CustomFieldsDraft $custom=null, ?RecurrencePolicyResourceIdentifier $recurrencePolicy=null)
setCustomerGroup(?CustomerGroupResourceIdentifier $customerGroup)
setChannel(?ChannelResourceIdentifier $channel)
static fromArray(array $data)