commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
PriceDraftImportModel.php
1<?php
2
3declare(strict_types=1);
10
26use DateTimeImmutable;
27use stdClass;
28
33{
38 protected $value;
39
44 protected $country;
45
50 protected $customerGroup;
51
56 protected $channel;
57
62 protected $validFrom;
63
68 protected $validUntil;
69
74 protected $custom;
75
80 protected $discounted;
81
86 protected $tiers;
87
92 protected $key;
93
94
98 public function __construct(
99 ?TypedMoney $value = null,
100 ?string $country = null,
103 ?DateTimeImmutable $validFrom = null,
104 ?DateTimeImmutable $validUntil = null,
105 ?Custom $custom = null,
108 ?string $key = null
109 ) {
110 $this->value = $value;
111 $this->country = $country;
112 $this->customerGroup = $customerGroup;
113 $this->channel = $channel;
114 $this->validFrom = $validFrom;
115 $this->validUntil = $validUntil;
116 $this->custom = $custom;
117 $this->discounted = $discounted;
118 $this->tiers = $tiers;
119 $this->key = $key;
120 }
121
128 public function getValue()
129 {
130 if (is_null($this->value)) {
132 $data = $this->raw(self::FIELD_VALUE);
133 if (is_null($data)) {
134 return null;
135 }
136 $className = TypedMoneyModel::resolveDiscriminatorClass($data);
137 $this->value = $className::of($data);
138 }
139
140 return $this->value;
141 }
142
149 public function getCountry()
150 {
151 if (is_null($this->country)) {
153 $data = $this->raw(self::FIELD_COUNTRY);
154 if (is_null($data)) {
155 return null;
156 }
157 $this->country = (string) $data;
158 }
159
160 return $this->country;
161 }
162
169 public function getCustomerGroup()
170 {
171 if (is_null($this->customerGroup)) {
173 $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
174 if (is_null($data)) {
175 return null;
176 }
177
178 $this->customerGroup = CustomerGroupKeyReferenceModel::of($data);
179 }
180
182 }
183
190 public function getChannel()
191 {
192 if (is_null($this->channel)) {
194 $data = $this->raw(self::FIELD_CHANNEL);
195 if (is_null($data)) {
196 return null;
197 }
198
199 $this->channel = ChannelKeyReferenceModel::of($data);
200 }
201
202 return $this->channel;
203 }
204
211 public function getValidFrom()
212 {
213 if (is_null($this->validFrom)) {
215 $data = $this->raw(self::FIELD_VALID_FROM);
216 if (is_null($data)) {
217 return null;
218 }
219 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
220 if (false === $data) {
221 return null;
222 }
223 $this->validFrom = $data;
224 }
225
226 return $this->validFrom;
227 }
228
235 public function getValidUntil()
236 {
237 if (is_null($this->validUntil)) {
239 $data = $this->raw(self::FIELD_VALID_UNTIL);
240 if (is_null($data)) {
241 return null;
242 }
243 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
244 if (false === $data) {
245 return null;
246 }
247 $this->validUntil = $data;
248 }
249
250 return $this->validUntil;
251 }
252
259 public function getCustom()
260 {
261 if (is_null($this->custom)) {
263 $data = $this->raw(self::FIELD_CUSTOM);
264 if (is_null($data)) {
265 return null;
266 }
267
268 $this->custom = CustomModel::of($data);
269 }
270
271 return $this->custom;
272 }
273
280 public function getDiscounted()
281 {
282 if (is_null($this->discounted)) {
284 $data = $this->raw(self::FIELD_DISCOUNTED);
285 if (is_null($data)) {
286 return null;
287 }
288
289 $this->discounted = DiscountedPriceModel::of($data);
290 }
291
292 return $this->discounted;
293 }
294
301 public function getTiers()
302 {
303 if (is_null($this->tiers)) {
305 $data = $this->raw(self::FIELD_TIERS);
306 if (is_null($data)) {
307 return null;
308 }
309 $this->tiers = PriceTierCollection::fromArray($data);
310 }
311
312 return $this->tiers;
313 }
314
321 public function getKey()
322 {
323 if (is_null($this->key)) {
325 $data = $this->raw(self::FIELD_KEY);
326 if (is_null($data)) {
327 return null;
328 }
329 $this->key = (string) $data;
330 }
331
332 return $this->key;
333 }
334
335
339 public function setValue(?TypedMoney $value): void
340 {
341 $this->value = $value;
342 }
343
347 public function setCountry(?string $country): void
348 {
349 $this->country = $country;
350 }
351
356 {
357 $this->customerGroup = $customerGroup;
358 }
359
364 {
365 $this->channel = $channel;
366 }
367
371 public function setValidFrom(?DateTimeImmutable $validFrom): void
372 {
373 $this->validFrom = $validFrom;
374 }
375
379 public function setValidUntil(?DateTimeImmutable $validUntil): void
380 {
381 $this->validUntil = $validUntil;
382 }
383
387 public function setCustom(?Custom $custom): void
388 {
389 $this->custom = $custom;
390 }
391
396 {
397 $this->discounted = $discounted;
398 }
399
403 public function setTiers(?PriceTierCollection $tiers): void
404 {
405 $this->tiers = $tiers;
406 }
407
411 public function setKey(?string $key): void
412 {
413 $this->key = $key;
414 }
415
416
417 #[\ReturnTypeWillChange]
418 public function jsonSerialize()
419 {
420 $data = $this->toArray();
421 if (isset($data[PriceDraftImport::FIELD_VALID_FROM]) && $data[PriceDraftImport::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
422 $data[PriceDraftImport::FIELD_VALID_FROM] = $data[PriceDraftImport::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
423 }
424
425 if (isset($data[PriceDraftImport::FIELD_VALID_UNTIL]) && $data[PriceDraftImport::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
426 $data[PriceDraftImport::FIELD_VALID_UNTIL] = $data[PriceDraftImport::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
427 }
428 return (object) $data;
429 }
430}
__construct(?TypedMoney $value=null, ?string $country=null, ?CustomerGroupKeyReference $customerGroup=null, ?ChannelKeyReference $channel=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null, ?Custom $custom=null, ?DiscountedPrice $discounted=null, ?PriceTierCollection $tiers=null, ?string $key=null)