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
133 public function getKey()
134 {
135 if (is_null($this->key)) {
137 $data = $this->raw(self::FIELD_KEY);
138 if (is_null($data)) {
139 return null;
140 }
141 $this->key = (string) $data;
142 }
143
144 return $this->key;
145 }
146
154 public function getValue()
155 {
156 if (is_null($this->value)) {
158 $data = $this->raw(self::FIELD_VALUE);
159 if (is_null($data)) {
160 return null;
161 }
162
163 $this->value = MoneyModel::of($data);
164 }
165
166 return $this->value;
167 }
168
175 public function getCountry()
176 {
177 if (is_null($this->country)) {
179 $data = $this->raw(self::FIELD_COUNTRY);
180 if (is_null($data)) {
181 return null;
182 }
183 $this->country = (string) $data;
184 }
185
186 return $this->country;
187 }
188
195 public function getCustomerGroup()
196 {
197 if (is_null($this->customerGroup)) {
199 $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
200 if (is_null($data)) {
201 return null;
202 }
203
204 $this->customerGroup = CustomerGroupResourceIdentifierModel::of($data);
205 }
206
208 }
209
216 public function getChannel()
217 {
218 if (is_null($this->channel)) {
220 $data = $this->raw(self::FIELD_CHANNEL);
221 if (is_null($data)) {
222 return null;
223 }
224
225 $this->channel = ChannelResourceIdentifierModel::of($data);
226 }
227
228 return $this->channel;
229 }
230
237 public function getValidFrom()
238 {
239 if (is_null($this->validFrom)) {
241 $data = $this->raw(self::FIELD_VALID_FROM);
242 if (is_null($data)) {
243 return null;
244 }
245 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
246 if (false === $data) {
247 return null;
248 }
249 $this->validFrom = $data;
250 }
251
252 return $this->validFrom;
253 }
254
261 public function getValidUntil()
262 {
263 if (is_null($this->validUntil)) {
265 $data = $this->raw(self::FIELD_VALID_UNTIL);
266 if (is_null($data)) {
267 return null;
268 }
269 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
270 if (false === $data) {
271 return null;
272 }
273 $this->validUntil = $data;
274 }
275
276 return $this->validUntil;
277 }
278
292 public function getDiscounted()
293 {
294 if (is_null($this->discounted)) {
296 $data = $this->raw(self::FIELD_DISCOUNTED);
297 if (is_null($data)) {
298 return null;
299 }
300
301 $this->discounted = DiscountedPriceDraftModel::of($data);
302 }
303
304 return $this->discounted;
305 }
306
314 public function getTiers()
315 {
316 if (is_null($this->tiers)) {
318 $data = $this->raw(self::FIELD_TIERS);
319 if (is_null($data)) {
320 return null;
321 }
322 $this->tiers = PriceTierDraftCollection::fromArray($data);
323 }
324
325 return $this->tiers;
326 }
327
334 public function getCustom()
335 {
336 if (is_null($this->custom)) {
338 $data = $this->raw(self::FIELD_CUSTOM);
339 if (is_null($data)) {
340 return null;
341 }
342
343 $this->custom = CustomFieldsDraftModel::of($data);
344 }
345
346 return $this->custom;
347 }
348
355 public function getRecurrencePolicy()
356 {
357 if (is_null($this->recurrencePolicy)) {
359 $data = $this->raw(self::FIELD_RECURRENCE_POLICY);
360 if (is_null($data)) {
361 return null;
362 }
363
364 $this->recurrencePolicy = RecurrencePolicyResourceIdentifierModel::of($data);
365 }
366
368 }
369
370
374 public function setKey(?string $key): void
375 {
376 $this->key = $key;
377 }
378
382 public function setValue(?Money $value): void
383 {
384 $this->value = $value;
385 }
386
390 public function setCountry(?string $country): void
391 {
392 $this->country = $country;
393 }
394
399 {
400 $this->customerGroup = $customerGroup;
401 }
402
407 {
408 $this->channel = $channel;
409 }
410
414 public function setValidFrom(?DateTimeImmutable $validFrom): void
415 {
416 $this->validFrom = $validFrom;
417 }
418
422 public function setValidUntil(?DateTimeImmutable $validUntil): void
423 {
424 $this->validUntil = $validUntil;
425 }
426
431 {
432 $this->discounted = $discounted;
433 }
434
439 {
440 $this->tiers = $tiers;
441 }
442
446 public function setCustom(?CustomFieldsDraft $custom): void
447 {
448 $this->custom = $custom;
449 }
450
455 {
456 $this->recurrencePolicy = $recurrencePolicy;
457 }
458
459
460 #[\ReturnTypeWillChange]
461 public function jsonSerialize()
462 {
463 $data = $this->toArray();
464 if (isset($data[PriceDraft::FIELD_VALID_FROM]) && $data[PriceDraft::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
465 $data[PriceDraft::FIELD_VALID_FROM] = $data[PriceDraft::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
466 }
467
468 if (isset($data[PriceDraft::FIELD_VALID_UNTIL]) && $data[PriceDraft::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
469 $data[PriceDraft::FIELD_VALID_UNTIL] = $data[PriceDraft::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
470 }
471 return (object) $data;
472 }
473}
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)