commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
LineItemPriceModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
26 use DateTimeImmutable;
27 use stdClass;
28 
32 final class LineItemPriceModel extends JsonObjectModel implements LineItemPrice
33 {
38  protected $value;
39 
44  protected $country;
45 
50  protected $validFrom;
51 
56  protected $validUntil;
57 
62  protected $customerGroup;
63 
68  protected $channel;
69 
74  protected $discounted;
75 
80  protected $tiers;
81 
86  protected $custom;
87 
88 
92  public function __construct(
93  ?TypedMoney $value = null,
94  ?string $country = null,
95  ?DateTimeImmutable $validFrom = null,
96  ?DateTimeImmutable $validUntil = null,
100  ?PriceTierCollection $tiers = null,
101  ?Custom $custom = null
102  ) {
103  $this->value = $value;
104  $this->country = $country;
105  $this->validFrom = $validFrom;
106  $this->validUntil = $validUntil;
107  $this->customerGroup = $customerGroup;
108  $this->channel = $channel;
109  $this->discounted = $discounted;
110  $this->tiers = $tiers;
111  $this->custom = $custom;
112  }
113 
120  public function getValue()
121  {
122  if (is_null($this->value)) {
124  $data = $this->raw(self::FIELD_VALUE);
125  if (is_null($data)) {
126  return null;
127  }
128  $className = TypedMoneyModel::resolveDiscriminatorClass($data);
129  $this->value = $className::of($data);
130  }
131 
132  return $this->value;
133  }
134 
141  public function getCountry()
142  {
143  if (is_null($this->country)) {
145  $data = $this->raw(self::FIELD_COUNTRY);
146  if (is_null($data)) {
147  return null;
148  }
149  $this->country = (string) $data;
150  }
151 
152  return $this->country;
153  }
154 
161  public function getValidFrom()
162  {
163  if (is_null($this->validFrom)) {
165  $data = $this->raw(self::FIELD_VALID_FROM);
166  if (is_null($data)) {
167  return null;
168  }
169  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
170  if (false === $data) {
171  return null;
172  }
173  $this->validFrom = $data;
174  }
175 
176  return $this->validFrom;
177  }
178 
185  public function getValidUntil()
186  {
187  if (is_null($this->validUntil)) {
189  $data = $this->raw(self::FIELD_VALID_UNTIL);
190  if (is_null($data)) {
191  return null;
192  }
193  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
194  if (false === $data) {
195  return null;
196  }
197  $this->validUntil = $data;
198  }
199 
200  return $this->validUntil;
201  }
202 
209  public function getCustomerGroup()
210  {
211  if (is_null($this->customerGroup)) {
213  $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
214  if (is_null($data)) {
215  return null;
216  }
217 
218  $this->customerGroup = CustomerGroupKeyReferenceModel::of($data);
219  }
220 
221  return $this->customerGroup;
222  }
223 
230  public function getChannel()
231  {
232  if (is_null($this->channel)) {
234  $data = $this->raw(self::FIELD_CHANNEL);
235  if (is_null($data)) {
236  return null;
237  }
238 
239  $this->channel = ChannelKeyReferenceModel::of($data);
240  }
241 
242  return $this->channel;
243  }
244 
251  public function getDiscounted()
252  {
253  if (is_null($this->discounted)) {
255  $data = $this->raw(self::FIELD_DISCOUNTED);
256  if (is_null($data)) {
257  return null;
258  }
259 
260  $this->discounted = DiscountedPriceModel::of($data);
261  }
262 
263  return $this->discounted;
264  }
265 
272  public function getTiers()
273  {
274  if (is_null($this->tiers)) {
276  $data = $this->raw(self::FIELD_TIERS);
277  if (is_null($data)) {
278  return null;
279  }
280  $this->tiers = PriceTierCollection::fromArray($data);
281  }
282 
283  return $this->tiers;
284  }
285 
292  public function getCustom()
293  {
294  if (is_null($this->custom)) {
296  $data = $this->raw(self::FIELD_CUSTOM);
297  if (is_null($data)) {
298  return null;
299  }
300 
301  $this->custom = CustomModel::of($data);
302  }
303 
304  return $this->custom;
305  }
306 
307 
311  public function setValue(?TypedMoney $value): void
312  {
313  $this->value = $value;
314  }
315 
319  public function setCountry(?string $country): void
320  {
321  $this->country = $country;
322  }
323 
327  public function setValidFrom(?DateTimeImmutable $validFrom): void
328  {
329  $this->validFrom = $validFrom;
330  }
331 
335  public function setValidUntil(?DateTimeImmutable $validUntil): void
336  {
337  $this->validUntil = $validUntil;
338  }
339 
344  {
345  $this->customerGroup = $customerGroup;
346  }
347 
351  public function setChannel(?ChannelKeyReference $channel): void
352  {
353  $this->channel = $channel;
354  }
355 
359  public function setDiscounted(?DiscountedPrice $discounted): void
360  {
361  $this->discounted = $discounted;
362  }
363 
367  public function setTiers(?PriceTierCollection $tiers): void
368  {
369  $this->tiers = $tiers;
370  }
371 
375  public function setCustom(?Custom $custom): void
376  {
377  $this->custom = $custom;
378  }
379 
380 
381  #[\ReturnTypeWillChange]
382  public function jsonSerialize()
383  {
384  $data = $this->toArray();
385  if (isset($data[LineItemPrice::FIELD_VALID_FROM]) && $data[LineItemPrice::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
386  $data[LineItemPrice::FIELD_VALID_FROM] = $data[LineItemPrice::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
387  }
388 
389  if (isset($data[LineItemPrice::FIELD_VALID_UNTIL]) && $data[LineItemPrice::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
390  $data[LineItemPrice::FIELD_VALID_UNTIL] = $data[LineItemPrice::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
391  }
392  return (object) $data;
393  }
394 }
__construct(?TypedMoney $value=null, ?string $country=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null, ?CustomerGroupKeyReference $customerGroup=null, ?ChannelKeyReference $channel=null, ?DiscountedPrice $discounted=null, ?PriceTierCollection $tiers=null, ?Custom $custom=null)
setCustomerGroup(?CustomerGroupKeyReference $customerGroup)