commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
StandalonePriceDraftModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
26 use DateTimeImmutable;
27 use stdClass;
28 
33 {
38  protected $key;
39 
44  protected $sku;
45 
50  protected $value;
51 
56  protected $country;
57 
62  protected $customerGroup;
63 
68  protected $channel;
69 
74  protected $validFrom;
75 
80  protected $validUntil;
81 
86  protected $tiers;
87 
92  protected $discounted;
93 
98  protected $custom;
99 
104  protected $staged;
105 
110  protected $active;
111 
112 
116  public function __construct(
117  ?string $key = null,
118  ?string $sku = null,
119  ?Money $value = null,
120  ?string $country = null,
123  ?DateTimeImmutable $validFrom = null,
124  ?DateTimeImmutable $validUntil = null,
127  ?CustomFieldsDraft $custom = null,
128  ?StagedPriceDraft $staged = null,
129  ?bool $active = null
130  ) {
131  $this->key = $key;
132  $this->sku = $sku;
133  $this->value = $value;
134  $this->country = $country;
135  $this->customerGroup = $customerGroup;
136  $this->channel = $channel;
137  $this->validFrom = $validFrom;
138  $this->validUntil = $validUntil;
139  $this->tiers = $tiers;
140  $this->discounted = $discounted;
141  $this->custom = $custom;
142  $this->staged = $staged;
143  $this->active = $active;
144  }
145 
152  public function getKey()
153  {
154  if (is_null($this->key)) {
156  $data = $this->raw(self::FIELD_KEY);
157  if (is_null($data)) {
158  return null;
159  }
160  $this->key = (string) $data;
161  }
162 
163  return $this->key;
164  }
165 
173  public function getSku()
174  {
175  if (is_null($this->sku)) {
177  $data = $this->raw(self::FIELD_SKU);
178  if (is_null($data)) {
179  return null;
180  }
181  $this->sku = (string) $data;
182  }
183 
184  return $this->sku;
185  }
186 
193  public function getValue()
194  {
195  if (is_null($this->value)) {
197  $data = $this->raw(self::FIELD_VALUE);
198  if (is_null($data)) {
199  return null;
200  }
201 
202  $this->value = MoneyModel::of($data);
203  }
204 
205  return $this->value;
206  }
207 
214  public function getCountry()
215  {
216  if (is_null($this->country)) {
218  $data = $this->raw(self::FIELD_COUNTRY);
219  if (is_null($data)) {
220  return null;
221  }
222  $this->country = (string) $data;
223  }
224 
225  return $this->country;
226  }
227 
234  public function getCustomerGroup()
235  {
236  if (is_null($this->customerGroup)) {
238  $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
239  if (is_null($data)) {
240  return null;
241  }
242 
243  $this->customerGroup = CustomerGroupResourceIdentifierModel::of($data);
244  }
245 
246  return $this->customerGroup;
247  }
248 
255  public function getChannel()
256  {
257  if (is_null($this->channel)) {
259  $data = $this->raw(self::FIELD_CHANNEL);
260  if (is_null($data)) {
261  return null;
262  }
263 
264  $this->channel = ChannelResourceIdentifierModel::of($data);
265  }
266 
267  return $this->channel;
268  }
269 
276  public function getValidFrom()
277  {
278  if (is_null($this->validFrom)) {
280  $data = $this->raw(self::FIELD_VALID_FROM);
281  if (is_null($data)) {
282  return null;
283  }
284  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
285  if (false === $data) {
286  return null;
287  }
288  $this->validFrom = $data;
289  }
290 
291  return $this->validFrom;
292  }
293 
300  public function getValidUntil()
301  {
302  if (is_null($this->validUntil)) {
304  $data = $this->raw(self::FIELD_VALID_UNTIL);
305  if (is_null($data)) {
306  return null;
307  }
308  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
309  if (false === $data) {
310  return null;
311  }
312  $this->validUntil = $data;
313  }
314 
315  return $this->validUntil;
316  }
317 
325  public function getTiers()
326  {
327  if (is_null($this->tiers)) {
329  $data = $this->raw(self::FIELD_TIERS);
330  if (is_null($data)) {
331  return null;
332  }
333  $this->tiers = PriceTierDraftCollection::fromArray($data);
334  }
335 
336  return $this->tiers;
337  }
338 
345  public function getDiscounted()
346  {
347  if (is_null($this->discounted)) {
349  $data = $this->raw(self::FIELD_DISCOUNTED);
350  if (is_null($data)) {
351  return null;
352  }
353 
354  $this->discounted = DiscountedPriceDraftModel::of($data);
355  }
356 
357  return $this->discounted;
358  }
359 
366  public function getCustom()
367  {
368  if (is_null($this->custom)) {
370  $data = $this->raw(self::FIELD_CUSTOM);
371  if (is_null($data)) {
372  return null;
373  }
374 
375  $this->custom = CustomFieldsDraftModel::of($data);
376  }
377 
378  return $this->custom;
379  }
380 
387  public function getStaged()
388  {
389  if (is_null($this->staged)) {
391  $data = $this->raw(self::FIELD_STAGED);
392  if (is_null($data)) {
393  return null;
394  }
395 
396  $this->staged = StagedPriceDraftModel::of($data);
397  }
398 
399  return $this->staged;
400  }
401 
408  public function getActive()
409  {
410  if (is_null($this->active)) {
412  $data = $this->raw(self::FIELD_ACTIVE);
413  if (is_null($data)) {
414  return null;
415  }
416  $this->active = (bool) $data;
417  }
418 
419  return $this->active;
420  }
421 
422 
426  public function setKey(?string $key): void
427  {
428  $this->key = $key;
429  }
430 
434  public function setSku(?string $sku): void
435  {
436  $this->sku = $sku;
437  }
438 
442  public function setValue(?Money $value): void
443  {
444  $this->value = $value;
445  }
446 
450  public function setCountry(?string $country): void
451  {
452  $this->country = $country;
453  }
454 
459  {
460  $this->customerGroup = $customerGroup;
461  }
462 
467  {
468  $this->channel = $channel;
469  }
470 
474  public function setValidFrom(?DateTimeImmutable $validFrom): void
475  {
476  $this->validFrom = $validFrom;
477  }
478 
482  public function setValidUntil(?DateTimeImmutable $validUntil): void
483  {
484  $this->validUntil = $validUntil;
485  }
486 
490  public function setTiers(?PriceTierDraftCollection $tiers): void
491  {
492  $this->tiers = $tiers;
493  }
494 
499  {
500  $this->discounted = $discounted;
501  }
502 
506  public function setCustom(?CustomFieldsDraft $custom): void
507  {
508  $this->custom = $custom;
509  }
510 
514  public function setStaged(?StagedPriceDraft $staged): void
515  {
516  $this->staged = $staged;
517  }
518 
522  public function setActive(?bool $active): void
523  {
524  $this->active = $active;
525  }
526 
527 
528  #[\ReturnTypeWillChange]
529  public function jsonSerialize()
530  {
531  $data = $this->toArray();
532  if (isset($data[StandalonePriceDraft::FIELD_VALID_FROM]) && $data[StandalonePriceDraft::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
533  $data[StandalonePriceDraft::FIELD_VALID_FROM] = $data[StandalonePriceDraft::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
534  }
535 
536  if (isset($data[StandalonePriceDraft::FIELD_VALID_UNTIL]) && $data[StandalonePriceDraft::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
537  $data[StandalonePriceDraft::FIELD_VALID_UNTIL] = $data[StandalonePriceDraft::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
538  }
539  return (object) $data;
540  }
541 }
__construct(?string $key=null, ?string $sku=null, ?Money $value=null, ?string $country=null, ?CustomerGroupResourceIdentifier $customerGroup=null, ?ChannelResourceIdentifier $channel=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null, ?PriceTierDraftCollection $tiers=null, ?DiscountedPriceDraft $discounted=null, ?CustomFieldsDraft $custom=null, ?StagedPriceDraft $staged=null, ?bool $active=null)