commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
MyLineItemDraftModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
21 use DateTimeImmutable;
22 use stdClass;
23 
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 
69  protected $supplyChannel;
70 
76 
81  protected $shippingDetails;
82 
87  protected $custom;
88 
89 
93  public function __construct(
94  ?string $key = null,
95  ?string $productId = null,
96  ?int $variantId = null,
97  ?string $sku = null,
98  ?int $quantity = null,
99  ?DateTimeImmutable $addedAt = null,
103  ?CustomFieldsDraft $custom = null
104  ) {
105  $this->key = $key;
106  $this->productId = $productId;
107  $this->variantId = $variantId;
108  $this->sku = $sku;
109  $this->quantity = $quantity;
110  $this->addedAt = $addedAt;
111  $this->supplyChannel = $supplyChannel;
112  $this->distributionChannel = $distributionChannel;
113  $this->shippingDetails = $shippingDetails;
114  $this->custom = $custom;
115  }
116 
123  public function getKey()
124  {
125  if (is_null($this->key)) {
127  $data = $this->raw(self::FIELD_KEY);
128  if (is_null($data)) {
129  return null;
130  }
131  $this->key = (string) $data;
132  }
133 
134  return $this->key;
135  }
136 
143  public function getProductId()
144  {
145  if (is_null($this->productId)) {
147  $data = $this->raw(self::FIELD_PRODUCT_ID);
148  if (is_null($data)) {
149  return null;
150  }
151  $this->productId = (string) $data;
152  }
153 
154  return $this->productId;
155  }
156 
164  public function getVariantId()
165  {
166  if (is_null($this->variantId)) {
168  $data = $this->raw(self::FIELD_VARIANT_ID);
169  if (is_null($data)) {
170  return null;
171  }
172  $this->variantId = (int) $data;
173  }
174 
175  return $this->variantId;
176  }
177 
184  public function getSku()
185  {
186  if (is_null($this->sku)) {
188  $data = $this->raw(self::FIELD_SKU);
189  if (is_null($data)) {
190  return null;
191  }
192  $this->sku = (string) $data;
193  }
194 
195  return $this->sku;
196  }
197 
204  public function getQuantity()
205  {
206  if (is_null($this->quantity)) {
208  $data = $this->raw(self::FIELD_QUANTITY);
209  if (is_null($data)) {
210  return null;
211  }
212  $this->quantity = (int) $data;
213  }
214 
215  return $this->quantity;
216  }
217 
226  public function getAddedAt()
227  {
228  if (is_null($this->addedAt)) {
230  $data = $this->raw(self::FIELD_ADDED_AT);
231  if (is_null($data)) {
232  return null;
233  }
234  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
235  if (false === $data) {
236  return null;
237  }
238  $this->addedAt = $data;
239  }
240 
241  return $this->addedAt;
242  }
243 
251  public function getSupplyChannel()
252  {
253  if (is_null($this->supplyChannel)) {
255  $data = $this->raw(self::FIELD_SUPPLY_CHANNEL);
256  if (is_null($data)) {
257  return null;
258  }
259 
260  $this->supplyChannel = ChannelResourceIdentifierModel::of($data);
261  }
262 
263  return $this->supplyChannel;
264  }
265 
275  public function getDistributionChannel()
276  {
277  if (is_null($this->distributionChannel)) {
279  $data = $this->raw(self::FIELD_DISTRIBUTION_CHANNEL);
280  if (is_null($data)) {
281  return null;
282  }
283 
284  $this->distributionChannel = ChannelResourceIdentifierModel::of($data);
285  }
286 
288  }
289 
296  public function getShippingDetails()
297  {
298  if (is_null($this->shippingDetails)) {
300  $data = $this->raw(self::FIELD_SHIPPING_DETAILS);
301  if (is_null($data)) {
302  return null;
303  }
304 
305  $this->shippingDetails = ItemShippingDetailsDraftModel::of($data);
306  }
307 
308  return $this->shippingDetails;
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 = CustomFieldsDraftModel::of($data);
327  }
328 
329  return $this->custom;
330  }
331 
332 
336  public function setKey(?string $key): void
337  {
338  $this->key = $key;
339  }
340 
344  public function setProductId(?string $productId): void
345  {
346  $this->productId = $productId;
347  }
348 
352  public function setVariantId(?int $variantId): void
353  {
354  $this->variantId = $variantId;
355  }
356 
360  public function setSku(?string $sku): void
361  {
362  $this->sku = $sku;
363  }
364 
368  public function setQuantity(?int $quantity): void
369  {
370  $this->quantity = $quantity;
371  }
372 
376  public function setAddedAt(?DateTimeImmutable $addedAt): void
377  {
378  $this->addedAt = $addedAt;
379  }
380 
385  {
386  $this->supplyChannel = $supplyChannel;
387  }
388 
393  {
394  $this->distributionChannel = $distributionChannel;
395  }
396 
401  {
402  $this->shippingDetails = $shippingDetails;
403  }
404 
408  public function setCustom(?CustomFieldsDraft $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[MyLineItemDraft::FIELD_ADDED_AT]) && $data[MyLineItemDraft::FIELD_ADDED_AT] instanceof \DateTimeImmutable) {
419  $data[MyLineItemDraft::FIELD_ADDED_AT] = $data[MyLineItemDraft::FIELD_ADDED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
420  }
421  return (object) $data;
422  }
423 }
setDistributionChannel(?ChannelResourceIdentifier $distributionChannel)
__construct(?string $key=null, ?string $productId=null, ?int $variantId=null, ?string $sku=null, ?int $quantity=null, ?DateTimeImmutable $addedAt=null, ?ChannelResourceIdentifier $supplyChannel=null, ?ChannelResourceIdentifier $distributionChannel=null, ?ItemShippingDetailsDraft $shippingDetails=null, ?CustomFieldsDraft $custom=null)
setShippingDetails(?ItemShippingDetailsDraft $shippingDetails)
setSupplyChannel(?ChannelResourceIdentifier $supplyChannel)