commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
PriceDraftModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
21 use DateTimeImmutable;
22 use stdClass;
23 
27 final 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,
103  ?CustomFieldsDraft $custom = 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 
143  public function getValue()
144  {
145  if (is_null($this->value)) {
147  $data = $this->raw(self::FIELD_VALUE);
148  if (is_null($data)) {
149  return null;
150  }
151 
152  $this->value = MoneyModel::of($data);
153  }
154 
155  return $this->value;
156  }
157 
164  public function getCountry()
165  {
166  if (is_null($this->country)) {
168  $data = $this->raw(self::FIELD_COUNTRY);
169  if (is_null($data)) {
170  return null;
171  }
172  $this->country = (string) $data;
173  }
174 
175  return $this->country;
176  }
177 
184  public function getCustomerGroup()
185  {
186  if (is_null($this->customerGroup)) {
188  $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
189  if (is_null($data)) {
190  return null;
191  }
192 
193  $this->customerGroup = CustomerGroupResourceIdentifierModel::of($data);
194  }
195 
196  return $this->customerGroup;
197  }
198 
205  public function getChannel()
206  {
207  if (is_null($this->channel)) {
209  $data = $this->raw(self::FIELD_CHANNEL);
210  if (is_null($data)) {
211  return null;
212  }
213 
214  $this->channel = ChannelResourceIdentifierModel::of($data);
215  }
216 
217  return $this->channel;
218  }
219 
226  public function getValidFrom()
227  {
228  if (is_null($this->validFrom)) {
230  $data = $this->raw(self::FIELD_VALID_FROM);
231  if (is_null($data)) {
232  return null;
233  }
234  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
235  if (false === $data) {
236  return null;
237  }
238  $this->validFrom = $data;
239  }
240 
241  return $this->validFrom;
242  }
243 
250  public function getValidUntil()
251  {
252  if (is_null($this->validUntil)) {
254  $data = $this->raw(self::FIELD_VALID_UNTIL);
255  if (is_null($data)) {
256  return null;
257  }
258  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
259  if (false === $data) {
260  return null;
261  }
262  $this->validUntil = $data;
263  }
264 
265  return $this->validUntil;
266  }
267 
281  public function getDiscounted()
282  {
283  if (is_null($this->discounted)) {
285  $data = $this->raw(self::FIELD_DISCOUNTED);
286  if (is_null($data)) {
287  return null;
288  }
289 
290  $this->discounted = DiscountedPriceDraftModel::of($data);
291  }
292 
293  return $this->discounted;
294  }
295 
303  public function getTiers()
304  {
305  if (is_null($this->tiers)) {
307  $data = $this->raw(self::FIELD_TIERS);
308  if (is_null($data)) {
309  return null;
310  }
311  $this->tiers = PriceTierDraftCollection::fromArray($data);
312  }
313 
314  return $this->tiers;
315  }
316 
323  public function getCustom()
324  {
325  if (is_null($this->custom)) {
327  $data = $this->raw(self::FIELD_CUSTOM);
328  if (is_null($data)) {
329  return null;
330  }
331 
332  $this->custom = CustomFieldsDraftModel::of($data);
333  }
334 
335  return $this->custom;
336  }
337 
338 
342  public function setKey(?string $key): void
343  {
344  $this->key = $key;
345  }
346 
350  public function setValue(?Money $value): void
351  {
352  $this->value = $value;
353  }
354 
358  public function setCountry(?string $country): void
359  {
360  $this->country = $country;
361  }
362 
367  {
368  $this->customerGroup = $customerGroup;
369  }
370 
375  {
376  $this->channel = $channel;
377  }
378 
382  public function setValidFrom(?DateTimeImmutable $validFrom): void
383  {
384  $this->validFrom = $validFrom;
385  }
386 
390  public function setValidUntil(?DateTimeImmutable $validUntil): void
391  {
392  $this->validUntil = $validUntil;
393  }
394 
399  {
400  $this->discounted = $discounted;
401  }
402 
406  public function setTiers(?PriceTierDraftCollection $tiers): void
407  {
408  $this->tiers = $tiers;
409  }
410 
414  public function setCustom(?CustomFieldsDraft $custom): void
415  {
416  $this->custom = $custom;
417  }
418 
419 
420  #[\ReturnTypeWillChange]
421  public function jsonSerialize()
422  {
423  $data = $this->toArray();
424  if (isset($data[PriceDraft::FIELD_VALID_FROM]) && $data[PriceDraft::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
425  $data[PriceDraft::FIELD_VALID_FROM] = $data[PriceDraft::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
426  }
427 
428  if (isset($data[PriceDraft::FIELD_VALID_UNTIL]) && $data[PriceDraft::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
429  $data[PriceDraft::FIELD_VALID_UNTIL] = $data[PriceDraft::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
430  }
431  return (object) $data;
432  }
433 }
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)