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
21use DateTimeImmutable;
22use stdClass;
23
27final class PriceDraftModel extends JsonObjectModel implements PriceDraft
28{
33 protected $key;
34
39 protected $value;
40
45 protected $country;
46
51 protected $customerGroup;
52
57 protected $channel;
58
63 protected $validFrom;
64
69 protected $validUntil;
70
75 protected $discounted;
76
81 protected $tiers;
82
87 protected $custom;
88
89
93 public function __construct(
94 ?string $key = null,
95 ?Money $value = null,
96 ?string $country = null,
99 ?DateTimeImmutable $validFrom = null,
100 ?DateTimeImmutable $validUntil = null,
104 ) {
105 $this->key = $key;
106 $this->value = $value;
107 $this->country = $country;
108 $this->customerGroup = $customerGroup;
109 $this->channel = $channel;
110 $this->validFrom = $validFrom;
111 $this->validUntil = $validUntil;
112 $this->discounted = $discounted;
113 $this->tiers = $tiers;
114 $this->custom = $custom;
115 }
116
123 public function getKey()
124 {
125 if (is_null($this->key)) {
127 $data = $this->raw(self::FIELD_KEY);
128 if (is_null($data)) {
129 return null;
130 }
131 $this->key = (string) $data;
132 }
133
134 return $this->key;
135 }
136
144 public function getValue()
145 {
146 if (is_null($this->value)) {
148 $data = $this->raw(self::FIELD_VALUE);
149 if (is_null($data)) {
150 return null;
151 }
152
153 $this->value = MoneyModel::of($data);
154 }
155
156 return $this->value;
157 }
158
165 public function getCountry()
166 {
167 if (is_null($this->country)) {
169 $data = $this->raw(self::FIELD_COUNTRY);
170 if (is_null($data)) {
171 return null;
172 }
173 $this->country = (string) $data;
174 }
175
176 return $this->country;
177 }
178
185 public function getCustomerGroup()
186 {
187 if (is_null($this->customerGroup)) {
189 $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
190 if (is_null($data)) {
191 return null;
192 }
193
194 $this->customerGroup = CustomerGroupResourceIdentifierModel::of($data);
195 }
196
198 }
199
206 public function getChannel()
207 {
208 if (is_null($this->channel)) {
210 $data = $this->raw(self::FIELD_CHANNEL);
211 if (is_null($data)) {
212 return null;
213 }
214
215 $this->channel = ChannelResourceIdentifierModel::of($data);
216 }
217
218 return $this->channel;
219 }
220
227 public function getValidFrom()
228 {
229 if (is_null($this->validFrom)) {
231 $data = $this->raw(self::FIELD_VALID_FROM);
232 if (is_null($data)) {
233 return null;
234 }
235 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
236 if (false === $data) {
237 return null;
238 }
239 $this->validFrom = $data;
240 }
241
242 return $this->validFrom;
243 }
244
251 public function getValidUntil()
252 {
253 if (is_null($this->validUntil)) {
255 $data = $this->raw(self::FIELD_VALID_UNTIL);
256 if (is_null($data)) {
257 return null;
258 }
259 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
260 if (false === $data) {
261 return null;
262 }
263 $this->validUntil = $data;
264 }
265
266 return $this->validUntil;
267 }
268
282 public function getDiscounted()
283 {
284 if (is_null($this->discounted)) {
286 $data = $this->raw(self::FIELD_DISCOUNTED);
287 if (is_null($data)) {
288 return null;
289 }
290
291 $this->discounted = DiscountedPriceDraftModel::of($data);
292 }
293
294 return $this->discounted;
295 }
296
304 public function getTiers()
305 {
306 if (is_null($this->tiers)) {
308 $data = $this->raw(self::FIELD_TIERS);
309 if (is_null($data)) {
310 return null;
311 }
312 $this->tiers = PriceTierDraftCollection::fromArray($data);
313 }
314
315 return $this->tiers;
316 }
317
324 public function getCustom()
325 {
326 if (is_null($this->custom)) {
328 $data = $this->raw(self::FIELD_CUSTOM);
329 if (is_null($data)) {
330 return null;
331 }
332
333 $this->custom = CustomFieldsDraftModel::of($data);
334 }
335
336 return $this->custom;
337 }
338
339
343 public function setKey(?string $key): void
344 {
345 $this->key = $key;
346 }
347
351 public function setValue(?Money $value): void
352 {
353 $this->value = $value;
354 }
355
359 public function setCountry(?string $country): void
360 {
361 $this->country = $country;
362 }
363
368 {
369 $this->customerGroup = $customerGroup;
370 }
371
376 {
377 $this->channel = $channel;
378 }
379
383 public function setValidFrom(?DateTimeImmutable $validFrom): void
384 {
385 $this->validFrom = $validFrom;
386 }
387
391 public function setValidUntil(?DateTimeImmutable $validUntil): void
392 {
393 $this->validUntil = $validUntil;
394 }
395
400 {
401 $this->discounted = $discounted;
402 }
403
408 {
409 $this->tiers = $tiers;
410 }
411
415 public function setCustom(?CustomFieldsDraft $custom): void
416 {
417 $this->custom = $custom;
418 }
419
420
421 #[\ReturnTypeWillChange]
422 public function jsonSerialize()
423 {
424 $data = $this->toArray();
425 if (isset($data[PriceDraft::FIELD_VALID_FROM]) && $data[PriceDraft::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
426 $data[PriceDraft::FIELD_VALID_FROM] = $data[PriceDraft::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
427 }
428
429 if (isset($data[PriceDraft::FIELD_VALID_UNTIL]) && $data[PriceDraft::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
430 $data[PriceDraft::FIELD_VALID_UNTIL] = $data[PriceDraft::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
431 }
432 return (object) $data;
433 }
434}
setDiscounted(?DiscountedPriceDraft $discounted)
setTiers(?PriceTierDraftCollection $tiers)
setValidUntil(?DateTimeImmutable $validUntil)
setCustomerGroup(?CustomerGroupResourceIdentifier $customerGroup)
__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)
setChannel(?ChannelResourceIdentifier $channel)
static fromArray(array $data)