commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
LineItemDraftModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
21 use DateTimeImmutable;
22 use stdClass;
23 
27 final class LineItemDraftModel extends JsonObjectModel implements LineItemDraft
28 {
33  protected $key;
34 
39  protected $productId;
40 
45  protected $variantId;
46 
51  protected $sku;
52 
57  protected $quantity;
58 
63  protected $addedAt;
64 
70 
75  protected $supplyChannel;
76 
81  protected $externalPrice;
82 
88 
93  protected $externalTaxRate;
94 
100 
105  protected $inventoryMode;
106 
111  protected $shippingDetails;
112 
117  protected $custom;
118 
119 
123  public function __construct(
124  ?string $key = null,
125  ?string $productId = null,
126  ?int $variantId = null,
127  ?string $sku = null,
128  ?int $quantity = null,
129  ?DateTimeImmutable $addedAt = null,
132  ?Money $externalPrice = null,
136  ?string $inventoryMode = null,
138  ?CustomFieldsDraft $custom = null
139  ) {
140  $this->key = $key;
141  $this->productId = $productId;
142  $this->variantId = $variantId;
143  $this->sku = $sku;
144  $this->quantity = $quantity;
145  $this->addedAt = $addedAt;
146  $this->distributionChannel = $distributionChannel;
147  $this->supplyChannel = $supplyChannel;
148  $this->externalPrice = $externalPrice;
149  $this->externalTotalPrice = $externalTotalPrice;
150  $this->externalTaxRate = $externalTaxRate;
151  $this->perMethodExternalTaxRate = $perMethodExternalTaxRate;
152  $this->inventoryMode = $inventoryMode;
153  $this->shippingDetails = $shippingDetails;
154  $this->custom = $custom;
155  }
156 
163  public function getKey()
164  {
165  if (is_null($this->key)) {
167  $data = $this->raw(self::FIELD_KEY);
168  if (is_null($data)) {
169  return null;
170  }
171  $this->key = (string) $data;
172  }
173 
174  return $this->key;
175  }
176 
183  public function getProductId()
184  {
185  if (is_null($this->productId)) {
187  $data = $this->raw(self::FIELD_PRODUCT_ID);
188  if (is_null($data)) {
189  return null;
190  }
191  $this->productId = (string) $data;
192  }
193 
194  return $this->productId;
195  }
196 
204  public function getVariantId()
205  {
206  if (is_null($this->variantId)) {
208  $data = $this->raw(self::FIELD_VARIANT_ID);
209  if (is_null($data)) {
210  return null;
211  }
212  $this->variantId = (int) $data;
213  }
214 
215  return $this->variantId;
216  }
217 
224  public function getSku()
225  {
226  if (is_null($this->sku)) {
228  $data = $this->raw(self::FIELD_SKU);
229  if (is_null($data)) {
230  return null;
231  }
232  $this->sku = (string) $data;
233  }
234 
235  return $this->sku;
236  }
237 
244  public function getQuantity()
245  {
246  if (is_null($this->quantity)) {
248  $data = $this->raw(self::FIELD_QUANTITY);
249  if (is_null($data)) {
250  return null;
251  }
252  $this->quantity = (int) $data;
253  }
254 
255  return $this->quantity;
256  }
257 
266  public function getAddedAt()
267  {
268  if (is_null($this->addedAt)) {
270  $data = $this->raw(self::FIELD_ADDED_AT);
271  if (is_null($data)) {
272  return null;
273  }
274  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
275  if (false === $data) {
276  return null;
277  }
278  $this->addedAt = $data;
279  }
280 
281  return $this->addedAt;
282  }
283 
293  public function getDistributionChannel()
294  {
295  if (is_null($this->distributionChannel)) {
297  $data = $this->raw(self::FIELD_DISTRIBUTION_CHANNEL);
298  if (is_null($data)) {
299  return null;
300  }
301 
302  $this->distributionChannel = ChannelResourceIdentifierModel::of($data);
303  }
304 
306  }
307 
315  public function getSupplyChannel()
316  {
317  if (is_null($this->supplyChannel)) {
319  $data = $this->raw(self::FIELD_SUPPLY_CHANNEL);
320  if (is_null($data)) {
321  return null;
322  }
323 
324  $this->supplyChannel = ChannelResourceIdentifierModel::of($data);
325  }
326 
327  return $this->supplyChannel;
328  }
329 
336  public function getExternalPrice()
337  {
338  if (is_null($this->externalPrice)) {
340  $data = $this->raw(self::FIELD_EXTERNAL_PRICE);
341  if (is_null($data)) {
342  return null;
343  }
344 
345  $this->externalPrice = MoneyModel::of($data);
346  }
347 
348  return $this->externalPrice;
349  }
350 
357  public function getExternalTotalPrice()
358  {
359  if (is_null($this->externalTotalPrice)) {
361  $data = $this->raw(self::FIELD_EXTERNAL_TOTAL_PRICE);
362  if (is_null($data)) {
363  return null;
364  }
365 
366  $this->externalTotalPrice = ExternalLineItemTotalPriceModel::of($data);
367  }
368 
370  }
371 
378  public function getExternalTaxRate()
379  {
380  if (is_null($this->externalTaxRate)) {
382  $data = $this->raw(self::FIELD_EXTERNAL_TAX_RATE);
383  if (is_null($data)) {
384  return null;
385  }
386 
387  $this->externalTaxRate = ExternalTaxRateDraftModel::of($data);
388  }
389 
390  return $this->externalTaxRate;
391  }
392 
399  public function getPerMethodExternalTaxRate()
400  {
401  if (is_null($this->perMethodExternalTaxRate)) {
403  $data = $this->raw(self::FIELD_PER_METHOD_EXTERNAL_TAX_RATE);
404  if (is_null($data)) {
405  return null;
406  }
407  $this->perMethodExternalTaxRate = MethodExternalTaxRateDraftCollection::fromArray($data);
408  }
409 
411  }
412 
420  public function getInventoryMode()
421  {
422  if (is_null($this->inventoryMode)) {
424  $data = $this->raw(self::FIELD_INVENTORY_MODE);
425  if (is_null($data)) {
426  return null;
427  }
428  $this->inventoryMode = (string) $data;
429  }
430 
431  return $this->inventoryMode;
432  }
433 
440  public function getShippingDetails()
441  {
442  if (is_null($this->shippingDetails)) {
444  $data = $this->raw(self::FIELD_SHIPPING_DETAILS);
445  if (is_null($data)) {
446  return null;
447  }
448 
449  $this->shippingDetails = ItemShippingDetailsDraftModel::of($data);
450  }
451 
452  return $this->shippingDetails;
453  }
454 
461  public function getCustom()
462  {
463  if (is_null($this->custom)) {
465  $data = $this->raw(self::FIELD_CUSTOM);
466  if (is_null($data)) {
467  return null;
468  }
469 
470  $this->custom = CustomFieldsDraftModel::of($data);
471  }
472 
473  return $this->custom;
474  }
475 
476 
480  public function setKey(?string $key): void
481  {
482  $this->key = $key;
483  }
484 
488  public function setProductId(?string $productId): void
489  {
490  $this->productId = $productId;
491  }
492 
496  public function setVariantId(?int $variantId): void
497  {
498  $this->variantId = $variantId;
499  }
500 
504  public function setSku(?string $sku): void
505  {
506  $this->sku = $sku;
507  }
508 
512  public function setQuantity(?int $quantity): void
513  {
514  $this->quantity = $quantity;
515  }
516 
520  public function setAddedAt(?DateTimeImmutable $addedAt): void
521  {
522  $this->addedAt = $addedAt;
523  }
524 
529  {
530  $this->distributionChannel = $distributionChannel;
531  }
532 
537  {
538  $this->supplyChannel = $supplyChannel;
539  }
540 
544  public function setExternalPrice(?Money $externalPrice): void
545  {
546  $this->externalPrice = $externalPrice;
547  }
548 
553  {
554  $this->externalTotalPrice = $externalTotalPrice;
555  }
556 
561  {
562  $this->externalTaxRate = $externalTaxRate;
563  }
564 
569  {
570  $this->perMethodExternalTaxRate = $perMethodExternalTaxRate;
571  }
572 
576  public function setInventoryMode(?string $inventoryMode): void
577  {
578  $this->inventoryMode = $inventoryMode;
579  }
580 
585  {
586  $this->shippingDetails = $shippingDetails;
587  }
588 
592  public function setCustom(?CustomFieldsDraft $custom): void
593  {
594  $this->custom = $custom;
595  }
596 
597 
598  #[\ReturnTypeWillChange]
599  public function jsonSerialize()
600  {
601  $data = $this->toArray();
602  if (isset($data[LineItemDraft::FIELD_ADDED_AT]) && $data[LineItemDraft::FIELD_ADDED_AT] instanceof \DateTimeImmutable) {
603  $data[LineItemDraft::FIELD_ADDED_AT] = $data[LineItemDraft::FIELD_ADDED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
604  }
605  return (object) $data;
606  }
607 }
__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)
setDistributionChannel(?ChannelResourceIdentifier $distributionChannel)
setExternalTaxRate(?ExternalTaxRateDraft $externalTaxRate)
setExternalTotalPrice(?ExternalLineItemTotalPrice $externalTotalPrice)
setPerMethodExternalTaxRate(?MethodExternalTaxRateDraftCollection $perMethodExternalTaxRate)
setShippingDetails(?ItemShippingDetailsDraft $shippingDetails)
setSupplyChannel(?ChannelResourceIdentifier $supplyChannel)