commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
CartAddLineItemActionModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
21 use DateTimeImmutable;
22 use stdClass;
23 
28 {
29  public const DISCRIMINATOR_VALUE = 'addLineItem';
34  protected $action;
35 
40  protected $key;
41 
46  protected $productId;
47 
52  protected $variantId;
53 
58  protected $sku;
59 
64  protected $quantity;
65 
70  protected $addedAt;
71 
77 
82  protected $supplyChannel;
83 
88  protected $externalPrice;
89 
95 
100  protected $externalTaxRate;
101 
107 
112  protected $inventoryMode;
113 
118  protected $shippingDetails;
119 
124  protected $custom;
125 
126 
130  public function __construct(
131  ?string $key = null,
132  ?string $productId = null,
133  ?int $variantId = null,
134  ?string $sku = null,
135  ?int $quantity = null,
136  ?DateTimeImmutable $addedAt = null,
139  ?Money $externalPrice = null,
143  ?string $inventoryMode = null,
145  ?CustomFieldsDraft $custom = null,
146  ?string $action = null
147  ) {
148  $this->key = $key;
149  $this->productId = $productId;
150  $this->variantId = $variantId;
151  $this->sku = $sku;
152  $this->quantity = $quantity;
153  $this->addedAt = $addedAt;
154  $this->distributionChannel = $distributionChannel;
155  $this->supplyChannel = $supplyChannel;
156  $this->externalPrice = $externalPrice;
157  $this->externalTotalPrice = $externalTotalPrice;
158  $this->externalTaxRate = $externalTaxRate;
159  $this->perMethodExternalTaxRate = $perMethodExternalTaxRate;
160  $this->inventoryMode = $inventoryMode;
161  $this->shippingDetails = $shippingDetails;
162  $this->custom = $custom;
163  $this->action = $action ?? self::DISCRIMINATOR_VALUE;
164  }
165 
170  public function getAction()
171  {
172  if (is_null($this->action)) {
174  $data = $this->raw(self::FIELD_ACTION);
175  if (is_null($data)) {
176  return null;
177  }
178  $this->action = (string) $data;
179  }
180 
181  return $this->action;
182  }
183 
190  public function getKey()
191  {
192  if (is_null($this->key)) {
194  $data = $this->raw(self::FIELD_KEY);
195  if (is_null($data)) {
196  return null;
197  }
198  $this->key = (string) $data;
199  }
200 
201  return $this->key;
202  }
203 
211  public function getProductId()
212  {
213  if (is_null($this->productId)) {
215  $data = $this->raw(self::FIELD_PRODUCT_ID);
216  if (is_null($data)) {
217  return null;
218  }
219  $this->productId = (string) $data;
220  }
221 
222  return $this->productId;
223  }
224 
233  public function getVariantId()
234  {
235  if (is_null($this->variantId)) {
237  $data = $this->raw(self::FIELD_VARIANT_ID);
238  if (is_null($data)) {
239  return null;
240  }
241  $this->variantId = (int) $data;
242  }
243 
244  return $this->variantId;
245  }
246 
254  public function getSku()
255  {
256  if (is_null($this->sku)) {
258  $data = $this->raw(self::FIELD_SKU);
259  if (is_null($data)) {
260  return null;
261  }
262  $this->sku = (string) $data;
263  }
264 
265  return $this->sku;
266  }
267 
274  public function getQuantity()
275  {
276  if (is_null($this->quantity)) {
278  $data = $this->raw(self::FIELD_QUANTITY);
279  if (is_null($data)) {
280  return null;
281  }
282  $this->quantity = (int) $data;
283  }
284 
285  return $this->quantity;
286  }
287 
296  public function getAddedAt()
297  {
298  if (is_null($this->addedAt)) {
300  $data = $this->raw(self::FIELD_ADDED_AT);
301  if (is_null($data)) {
302  return null;
303  }
304  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
305  if (false === $data) {
306  return null;
307  }
308  $this->addedAt = $data;
309  }
310 
311  return $this->addedAt;
312  }
313 
322  public function getDistributionChannel()
323  {
324  if (is_null($this->distributionChannel)) {
326  $data = $this->raw(self::FIELD_DISTRIBUTION_CHANNEL);
327  if (is_null($data)) {
328  return null;
329  }
330 
331  $this->distributionChannel = ChannelResourceIdentifierModel::of($data);
332  }
333 
335  }
336 
344  public function getSupplyChannel()
345  {
346  if (is_null($this->supplyChannel)) {
348  $data = $this->raw(self::FIELD_SUPPLY_CHANNEL);
349  if (is_null($data)) {
350  return null;
351  }
352 
353  $this->supplyChannel = ChannelResourceIdentifierModel::of($data);
354  }
355 
356  return $this->supplyChannel;
357  }
358 
365  public function getExternalPrice()
366  {
367  if (is_null($this->externalPrice)) {
369  $data = $this->raw(self::FIELD_EXTERNAL_PRICE);
370  if (is_null($data)) {
371  return null;
372  }
373 
374  $this->externalPrice = MoneyModel::of($data);
375  }
376 
377  return $this->externalPrice;
378  }
379 
386  public function getExternalTotalPrice()
387  {
388  if (is_null($this->externalTotalPrice)) {
390  $data = $this->raw(self::FIELD_EXTERNAL_TOTAL_PRICE);
391  if (is_null($data)) {
392  return null;
393  }
394 
395  $this->externalTotalPrice = ExternalLineItemTotalPriceModel::of($data);
396  }
397 
399  }
400 
407  public function getExternalTaxRate()
408  {
409  if (is_null($this->externalTaxRate)) {
411  $data = $this->raw(self::FIELD_EXTERNAL_TAX_RATE);
412  if (is_null($data)) {
413  return null;
414  }
415 
416  $this->externalTaxRate = ExternalTaxRateDraftModel::of($data);
417  }
418 
419  return $this->externalTaxRate;
420  }
421 
428  public function getPerMethodExternalTaxRate()
429  {
430  if (is_null($this->perMethodExternalTaxRate)) {
432  $data = $this->raw(self::FIELD_PER_METHOD_EXTERNAL_TAX_RATE);
433  if (is_null($data)) {
434  return null;
435  }
436  $this->perMethodExternalTaxRate = MethodExternalTaxRateDraftCollection::fromArray($data);
437  }
438 
440  }
441 
449  public function getInventoryMode()
450  {
451  if (is_null($this->inventoryMode)) {
453  $data = $this->raw(self::FIELD_INVENTORY_MODE);
454  if (is_null($data)) {
455  return null;
456  }
457  $this->inventoryMode = (string) $data;
458  }
459 
460  return $this->inventoryMode;
461  }
462 
469  public function getShippingDetails()
470  {
471  if (is_null($this->shippingDetails)) {
473  $data = $this->raw(self::FIELD_SHIPPING_DETAILS);
474  if (is_null($data)) {
475  return null;
476  }
477 
478  $this->shippingDetails = ItemShippingDetailsDraftModel::of($data);
479  }
480 
481  return $this->shippingDetails;
482  }
483 
490  public function getCustom()
491  {
492  if (is_null($this->custom)) {
494  $data = $this->raw(self::FIELD_CUSTOM);
495  if (is_null($data)) {
496  return null;
497  }
498 
499  $this->custom = CustomFieldsDraftModel::of($data);
500  }
501 
502  return $this->custom;
503  }
504 
505 
509  public function setKey(?string $key): void
510  {
511  $this->key = $key;
512  }
513 
517  public function setProductId(?string $productId): void
518  {
519  $this->productId = $productId;
520  }
521 
525  public function setVariantId(?int $variantId): void
526  {
527  $this->variantId = $variantId;
528  }
529 
533  public function setSku(?string $sku): void
534  {
535  $this->sku = $sku;
536  }
537 
541  public function setQuantity(?int $quantity): void
542  {
543  $this->quantity = $quantity;
544  }
545 
549  public function setAddedAt(?DateTimeImmutable $addedAt): void
550  {
551  $this->addedAt = $addedAt;
552  }
553 
558  {
559  $this->distributionChannel = $distributionChannel;
560  }
561 
566  {
567  $this->supplyChannel = $supplyChannel;
568  }
569 
573  public function setExternalPrice(?Money $externalPrice): void
574  {
575  $this->externalPrice = $externalPrice;
576  }
577 
582  {
583  $this->externalTotalPrice = $externalTotalPrice;
584  }
585 
590  {
591  $this->externalTaxRate = $externalTaxRate;
592  }
593 
598  {
599  $this->perMethodExternalTaxRate = $perMethodExternalTaxRate;
600  }
601 
605  public function setInventoryMode(?string $inventoryMode): void
606  {
607  $this->inventoryMode = $inventoryMode;
608  }
609 
614  {
615  $this->shippingDetails = $shippingDetails;
616  }
617 
621  public function setCustom(?CustomFieldsDraft $custom): void
622  {
623  $this->custom = $custom;
624  }
625 
626 
627  #[\ReturnTypeWillChange]
628  public function jsonSerialize()
629  {
630  $data = $this->toArray();
631  if (isset($data[CartAddLineItemAction::FIELD_ADDED_AT]) && $data[CartAddLineItemAction::FIELD_ADDED_AT] instanceof \DateTimeImmutable) {
632  $data[CartAddLineItemAction::FIELD_ADDED_AT] = $data[CartAddLineItemAction::FIELD_ADDED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
633  }
634  return (object) $data;
635  }
636 }
setShippingDetails(?ItemShippingDetailsDraft $shippingDetails)
setPerMethodExternalTaxRate(?MethodExternalTaxRateDraftCollection $perMethodExternalTaxRate)
__construct(?string $key=null, ?string $productId=null, ?int $variantId=null, ?string $sku=null, ?int $quantity=null, ?DateTimeImmutable $addedAt=null, ?ChannelResourceIdentifier $distributionChannel=null, ?ChannelResourceIdentifier $supplyChannel=null, ?Money $externalPrice=null, ?ExternalLineItemTotalPrice $externalTotalPrice=null, ?ExternalTaxRateDraft $externalTaxRate=null, ?MethodExternalTaxRateDraftCollection $perMethodExternalTaxRate=null, ?string $inventoryMode=null, ?ItemShippingDetailsDraft $shippingDetails=null, ?CustomFieldsDraft $custom=null, ?string $action=null)
setDistributionChannel(?ChannelResourceIdentifier $distributionChannel)
setExternalTotalPrice(?ExternalLineItemTotalPrice $externalTotalPrice)