commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
ScopedPriceModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
21 use DateTimeImmutable;
22 use stdClass;
23 
27 final class ScopedPriceModel extends JsonObjectModel implements ScopedPrice
28 {
33  protected $id;
34 
39  protected $value;
40 
45  protected $currentValue;
46 
51  protected $country;
52 
57  protected $customerGroup;
58 
63  protected $channel;
64 
69  protected $validFrom;
70 
75  protected $validUntil;
76 
81  protected $discounted;
82 
87  protected $custom;
88 
89 
93  public function __construct(
94  ?string $id = null,
95  ?TypedMoney $value = null,
96  ?TypedMoney $currentValue = null,
97  ?string $country = null,
99  ?ChannelReference $channel = null,
100  ?DateTimeImmutable $validFrom = null,
101  ?DateTimeImmutable $validUntil = null,
103  ?CustomFields $custom = null
104  ) {
105  $this->id = $id;
106  $this->value = $value;
107  $this->currentValue = $currentValue;
108  $this->country = $country;
109  $this->customerGroup = $customerGroup;
110  $this->channel = $channel;
111  $this->validFrom = $validFrom;
112  $this->validUntil = $validUntil;
113  $this->discounted = $discounted;
114  $this->custom = $custom;
115  }
116 
123  public function getId()
124  {
125  if (is_null($this->id)) {
127  $data = $this->raw(self::FIELD_ID);
128  if (is_null($data)) {
129  return null;
130  }
131  $this->id = (string) $data;
132  }
133 
134  return $this->id;
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  $className = TypedMoneyModel::resolveDiscriminatorClass($data);
152  $this->value = $className::of($data);
153  }
154 
155  return $this->value;
156  }
157 
164  public function getCurrentValue()
165  {
166  if (is_null($this->currentValue)) {
168  $data = $this->raw(self::FIELD_CURRENT_VALUE);
169  if (is_null($data)) {
170  return null;
171  }
172  $className = TypedMoneyModel::resolveDiscriminatorClass($data);
173  $this->currentValue = $className::of($data);
174  }
175 
176  return $this->currentValue;
177  }
178 
185  public function getCountry()
186  {
187  if (is_null($this->country)) {
189  $data = $this->raw(self::FIELD_COUNTRY);
190  if (is_null($data)) {
191  return null;
192  }
193  $this->country = (string) $data;
194  }
195 
196  return $this->country;
197  }
198 
205  public function getCustomerGroup()
206  {
207  if (is_null($this->customerGroup)) {
209  $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
210  if (is_null($data)) {
211  return null;
212  }
213 
214  $this->customerGroup = CustomerGroupReferenceModel::of($data);
215  }
216 
217  return $this->customerGroup;
218  }
219 
226  public function getChannel()
227  {
228  if (is_null($this->channel)) {
230  $data = $this->raw(self::FIELD_CHANNEL);
231  if (is_null($data)) {
232  return null;
233  }
234 
235  $this->channel = ChannelReferenceModel::of($data);
236  }
237 
238  return $this->channel;
239  }
240 
247  public function getValidFrom()
248  {
249  if (is_null($this->validFrom)) {
251  $data = $this->raw(self::FIELD_VALID_FROM);
252  if (is_null($data)) {
253  return null;
254  }
255  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
256  if (false === $data) {
257  return null;
258  }
259  $this->validFrom = $data;
260  }
261 
262  return $this->validFrom;
263  }
264 
271  public function getValidUntil()
272  {
273  if (is_null($this->validUntil)) {
275  $data = $this->raw(self::FIELD_VALID_UNTIL);
276  if (is_null($data)) {
277  return null;
278  }
279  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
280  if (false === $data) {
281  return null;
282  }
283  $this->validUntil = $data;
284  }
285 
286  return $this->validUntil;
287  }
288 
296  public function getDiscounted()
297  {
298  if (is_null($this->discounted)) {
300  $data = $this->raw(self::FIELD_DISCOUNTED);
301  if (is_null($data)) {
302  return null;
303  }
304 
305  $this->discounted = DiscountedPriceModel::of($data);
306  }
307 
308  return $this->discounted;
309  }
310 
317  public function getCustom()
318  {
319  if (is_null($this->custom)) {
321  $data = $this->raw(self::FIELD_CUSTOM);
322  if (is_null($data)) {
323  return null;
324  }
325 
326  $this->custom = CustomFieldsModel::of($data);
327  }
328 
329  return $this->custom;
330  }
331 
332 
336  public function setId(?string $id): void
337  {
338  $this->id = $id;
339  }
340 
344  public function setValue(?TypedMoney $value): void
345  {
346  $this->value = $value;
347  }
348 
352  public function setCurrentValue(?TypedMoney $currentValue): void
353  {
354  $this->currentValue = $currentValue;
355  }
356 
360  public function setCountry(?string $country): void
361  {
362  $this->country = $country;
363  }
364 
369  {
370  $this->customerGroup = $customerGroup;
371  }
372 
376  public function setChannel(?ChannelReference $channel): void
377  {
378  $this->channel = $channel;
379  }
380 
384  public function setValidFrom(?DateTimeImmutable $validFrom): void
385  {
386  $this->validFrom = $validFrom;
387  }
388 
392  public function setValidUntil(?DateTimeImmutable $validUntil): void
393  {
394  $this->validUntil = $validUntil;
395  }
396 
400  public function setDiscounted(?DiscountedPrice $discounted): void
401  {
402  $this->discounted = $discounted;
403  }
404 
408  public function setCustom(?CustomFields $custom): void
409  {
410  $this->custom = $custom;
411  }
412 
413 
414  #[\ReturnTypeWillChange]
415  public function jsonSerialize()
416  {
417  $data = $this->toArray();
418  if (isset($data[ScopedPrice::FIELD_VALID_FROM]) && $data[ScopedPrice::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
419  $data[ScopedPrice::FIELD_VALID_FROM] = $data[ScopedPrice::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
420  }
421 
422  if (isset($data[ScopedPrice::FIELD_VALID_UNTIL]) && $data[ScopedPrice::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
423  $data[ScopedPrice::FIELD_VALID_UNTIL] = $data[ScopedPrice::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
424  }
425  return (object) $data;
426  }
427 }
__construct(?string $id=null, ?TypedMoney $value=null, ?TypedMoney $currentValue=null, ?string $country=null, ?CustomerGroupReference $customerGroup=null, ?ChannelReference $channel=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null, ?DiscountedPrice $discounted=null, ?CustomFields $custom=null)
setCustomerGroup(?CustomerGroupReference $customerGroup)