commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
StandalonePriceImportModel.php
1<?php
2
3declare(strict_types=1);
10
28use DateTimeImmutable;
29use stdClass;
30
35{
40 protected $key;
41
46 protected $sku;
47
52 protected $value;
53
58 protected $country;
59
64 protected $customerGroup;
65
70 protected $channel;
71
76 protected $validFrom;
77
82 protected $validUntil;
83
88 protected $tiers;
89
94 protected $discounted;
95
100 protected $custom;
101
102
106 public function __construct(
107 ?string $key = null,
108 ?string $sku = null,
109 ?TypedMoney $value = null,
110 ?string $country = null,
113 ?DateTimeImmutable $validFrom = null,
114 ?DateTimeImmutable $validUntil = null,
117 ?Custom $custom = null
118 ) {
119 $this->key = $key;
120 $this->sku = $sku;
121 $this->value = $value;
122 $this->country = $country;
123 $this->customerGroup = $customerGroup;
124 $this->channel = $channel;
125 $this->validFrom = $validFrom;
126 $this->validUntil = $validUntil;
127 $this->tiers = $tiers;
128 $this->discounted = $discounted;
129 $this->custom = $custom;
130 }
131
138 public function getKey()
139 {
140 if (is_null($this->key)) {
142 $data = $this->raw(self::FIELD_KEY);
143 if (is_null($data)) {
144 return null;
145 }
146 $this->key = (string) $data;
147 }
148
149 return $this->key;
150 }
151
158 public function getSku()
159 {
160 if (is_null($this->sku)) {
162 $data = $this->raw(self::FIELD_SKU);
163 if (is_null($data)) {
164 return null;
165 }
166 $this->sku = (string) $data;
167 }
168
169 return $this->sku;
170 }
171
178 public function getValue()
179 {
180 if (is_null($this->value)) {
182 $data = $this->raw(self::FIELD_VALUE);
183 if (is_null($data)) {
184 return null;
185 }
186 $className = TypedMoneyModel::resolveDiscriminatorClass($data);
187 $this->value = $className::of($data);
188 }
189
190 return $this->value;
191 }
192
199 public function getCountry()
200 {
201 if (is_null($this->country)) {
203 $data = $this->raw(self::FIELD_COUNTRY);
204 if (is_null($data)) {
205 return null;
206 }
207 $this->country = (string) $data;
208 }
209
210 return $this->country;
211 }
212
220 public function getCustomerGroup()
221 {
222 if (is_null($this->customerGroup)) {
224 $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
225 if (is_null($data)) {
226 return null;
227 }
228
229 $this->customerGroup = CustomerGroupKeyReferenceModel::of($data);
230 }
231
233 }
234
242 public function getChannel()
243 {
244 if (is_null($this->channel)) {
246 $data = $this->raw(self::FIELD_CHANNEL);
247 if (is_null($data)) {
248 return null;
249 }
250
251 $this->channel = ChannelKeyReferenceModel::of($data);
252 }
253
254 return $this->channel;
255 }
256
263 public function getValidFrom()
264 {
265 if (is_null($this->validFrom)) {
267 $data = $this->raw(self::FIELD_VALID_FROM);
268 if (is_null($data)) {
269 return null;
270 }
271 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
272 if (false === $data) {
273 return null;
274 }
275 $this->validFrom = $data;
276 }
277
278 return $this->validFrom;
279 }
280
287 public function getValidUntil()
288 {
289 if (is_null($this->validUntil)) {
291 $data = $this->raw(self::FIELD_VALID_UNTIL);
292 if (is_null($data)) {
293 return null;
294 }
295 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
296 if (false === $data) {
297 return null;
298 }
299 $this->validUntil = $data;
300 }
301
302 return $this->validUntil;
303 }
304
311 public function getTiers()
312 {
313 if (is_null($this->tiers)) {
315 $data = $this->raw(self::FIELD_TIERS);
316 if (is_null($data)) {
317 return null;
318 }
319 $this->tiers = PriceTierCollection::fromArray($data);
320 }
321
322 return $this->tiers;
323 }
324
331 public function getDiscounted()
332 {
333 if (is_null($this->discounted)) {
335 $data = $this->raw(self::FIELD_DISCOUNTED);
336 if (is_null($data)) {
337 return null;
338 }
339
340 $this->discounted = DiscountedPriceModel::of($data);
341 }
342
343 return $this->discounted;
344 }
345
352 public function getCustom()
353 {
354 if (is_null($this->custom)) {
356 $data = $this->raw(self::FIELD_CUSTOM);
357 if (is_null($data)) {
358 return null;
359 }
360
361 $this->custom = CustomModel::of($data);
362 }
363
364 return $this->custom;
365 }
366
367
371 public function setKey(?string $key): void
372 {
373 $this->key = $key;
374 }
375
379 public function setSku(?string $sku): void
380 {
381 $this->sku = $sku;
382 }
383
387 public function setValue(?TypedMoney $value): void
388 {
389 $this->value = $value;
390 }
391
395 public function setCountry(?string $country): void
396 {
397 $this->country = $country;
398 }
399
404 {
405 $this->customerGroup = $customerGroup;
406 }
407
412 {
413 $this->channel = $channel;
414 }
415
419 public function setValidFrom(?DateTimeImmutable $validFrom): void
420 {
421 $this->validFrom = $validFrom;
422 }
423
427 public function setValidUntil(?DateTimeImmutable $validUntil): void
428 {
429 $this->validUntil = $validUntil;
430 }
431
435 public function setTiers(?PriceTierCollection $tiers): void
436 {
437 $this->tiers = $tiers;
438 }
439
444 {
445 $this->discounted = $discounted;
446 }
447
451 public function setCustom(?Custom $custom): void
452 {
453 $this->custom = $custom;
454 }
455
456
457 #[\ReturnTypeWillChange]
458 public function jsonSerialize()
459 {
460 $data = $this->toArray();
461 if (isset($data[StandalonePriceImport::FIELD_VALID_FROM]) && $data[StandalonePriceImport::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
462 $data[StandalonePriceImport::FIELD_VALID_FROM] = $data[StandalonePriceImport::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
463 }
464
465 if (isset($data[StandalonePriceImport::FIELD_VALID_UNTIL]) && $data[StandalonePriceImport::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
466 $data[StandalonePriceImport::FIELD_VALID_UNTIL] = $data[StandalonePriceImport::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
467 }
468 return (object) $data;
469 }
470}
__construct(?string $key=null, ?string $sku=null, ?TypedMoney $value=null, ?string $country=null, ?CustomerGroupKeyReference $customerGroup=null, ?ChannelKeyReference $channel=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null, ?PriceTierCollection $tiers=null, ?DiscountedPrice $discounted=null, ?Custom $custom=null)