commercetools-sdk-php-v2  master
The platform, import-api and ml-api PHP sdks generated from our api reference.
PriceDraftImportModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
26 use DateTimeImmutable;
27 use 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,
107  ?PriceTierCollection $tiers = 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 
126  public function getValue()
127  {
128  if (is_null($this->value)) {
130  $data = $this->raw(self::FIELD_VALUE);
131  if (is_null($data)) {
132  return null;
133  }
134  $className = TypedMoneyModel::resolveDiscriminatorClass($data);
135  $this->value = $className::of($data);
136  }
137 
138  return $this->value;
139  }
140 
147  public function getCountry()
148  {
149  if (is_null($this->country)) {
151  $data = $this->raw(self::FIELD_COUNTRY);
152  if (is_null($data)) {
153  return null;
154  }
155  $this->country = (string) $data;
156  }
157 
158  return $this->country;
159  }
160 
167  public function getCustomerGroup()
168  {
169  if (is_null($this->customerGroup)) {
171  $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
172  if (is_null($data)) {
173  return null;
174  }
175 
176  $this->customerGroup = CustomerGroupKeyReferenceModel::of($data);
177  }
178 
179  return $this->customerGroup;
180  }
181 
188  public function getChannel()
189  {
190  if (is_null($this->channel)) {
192  $data = $this->raw(self::FIELD_CHANNEL);
193  if (is_null($data)) {
194  return null;
195  }
196 
197  $this->channel = ChannelKeyReferenceModel::of($data);
198  }
199 
200  return $this->channel;
201  }
202 
207  public function getValidFrom()
208  {
209  if (is_null($this->validFrom)) {
211  $data = $this->raw(self::FIELD_VALID_FROM);
212  if (is_null($data)) {
213  return null;
214  }
215  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
216  if (false === $data) {
217  return null;
218  }
219  $this->validFrom = $data;
220  }
221 
222  return $this->validFrom;
223  }
224 
229  public function getValidUntil()
230  {
231  if (is_null($this->validUntil)) {
233  $data = $this->raw(self::FIELD_VALID_UNTIL);
234  if (is_null($data)) {
235  return null;
236  }
237  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
238  if (false === $data) {
239  return null;
240  }
241  $this->validUntil = $data;
242  }
243 
244  return $this->validUntil;
245  }
246 
253  public function getCustom()
254  {
255  if (is_null($this->custom)) {
257  $data = $this->raw(self::FIELD_CUSTOM);
258  if (is_null($data)) {
259  return null;
260  }
261 
262  $this->custom = CustomModel::of($data);
263  }
264 
265  return $this->custom;
266  }
267 
274  public function getDiscounted()
275  {
276  if (is_null($this->discounted)) {
278  $data = $this->raw(self::FIELD_DISCOUNTED);
279  if (is_null($data)) {
280  return null;
281  }
282 
283  $this->discounted = DiscountedPriceModel::of($data);
284  }
285 
286  return $this->discounted;
287  }
288 
295  public function getTiers()
296  {
297  if (is_null($this->tiers)) {
299  $data = $this->raw(self::FIELD_TIERS);
300  if (is_null($data)) {
301  return null;
302  }
303  $this->tiers = PriceTierCollection::fromArray($data);
304  }
305 
306  return $this->tiers;
307  }
308 
315  public function getKey()
316  {
317  if (is_null($this->key)) {
319  $data = $this->raw(self::FIELD_KEY);
320  if (is_null($data)) {
321  return null;
322  }
323  $this->key = (string) $data;
324  }
325 
326  return $this->key;
327  }
328 
329 
333  public function setValue(?TypedMoney $value): void
334  {
335  $this->value = $value;
336  }
337 
341  public function setCountry(?string $country): void
342  {
343  $this->country = $country;
344  }
345 
350  {
351  $this->customerGroup = $customerGroup;
352  }
353 
357  public function setChannel(?ChannelKeyReference $channel): void
358  {
359  $this->channel = $channel;
360  }
361 
365  public function setValidFrom(?DateTimeImmutable $validFrom): void
366  {
367  $this->validFrom = $validFrom;
368  }
369 
373  public function setValidUntil(?DateTimeImmutable $validUntil): void
374  {
375  $this->validUntil = $validUntil;
376  }
377 
381  public function setCustom(?Custom $custom): void
382  {
383  $this->custom = $custom;
384  }
385 
389  public function setDiscounted(?DiscountedPrice $discounted): void
390  {
391  $this->discounted = $discounted;
392  }
393 
397  public function setTiers(?PriceTierCollection $tiers): void
398  {
399  $this->tiers = $tiers;
400  }
401 
405  public function setKey(?string $key): void
406  {
407  $this->key = $key;
408  }
409 
410 
411  #[\ReturnTypeWillChange]
412  public function jsonSerialize()
413  {
414  $data = $this->toArray();
415  if (isset($data[PriceDraftImport::FIELD_VALID_FROM]) && $data[PriceDraftImport::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
416  $data[PriceDraftImport::FIELD_VALID_FROM] = $data[PriceDraftImport::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
417  }
418 
419  if (isset($data[PriceDraftImport::FIELD_VALID_UNTIL]) && $data[PriceDraftImport::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
420  $data[PriceDraftImport::FIELD_VALID_UNTIL] = $data[PriceDraftImport::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
421  }
422  return (object) $data;
423  }
424 }
__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)