commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
TextLineItemDraftModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
19 use DateTimeImmutable;
20 use stdClass;
21 
26 {
31  protected $key;
32 
37  protected $addedAt;
38 
43  protected $custom;
44 
49  protected $description;
50 
55  protected $name;
56 
61  protected $quantity;
62 
63 
67  public function __construct(
68  ?string $key = null,
69  ?DateTimeImmutable $addedAt = null,
70  ?CustomFieldsDraft $custom = null,
72  ?LocalizedString $name = null,
73  ?int $quantity = null
74  ) {
75  $this->key = $key;
76  $this->addedAt = $addedAt;
77  $this->custom = $custom;
78  $this->description = $description;
79  $this->name = $name;
80  $this->quantity = $quantity;
81  }
82 
89  public function getKey()
90  {
91  if (is_null($this->key)) {
93  $data = $this->raw(self::FIELD_KEY);
94  if (is_null($data)) {
95  return null;
96  }
97  $this->key = (string) $data;
98  }
99 
100  return $this->key;
101  }
102 
109  public function getAddedAt()
110  {
111  if (is_null($this->addedAt)) {
113  $data = $this->raw(self::FIELD_ADDED_AT);
114  if (is_null($data)) {
115  return null;
116  }
117  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
118  if (false === $data) {
119  return null;
120  }
121  $this->addedAt = $data;
122  }
123 
124  return $this->addedAt;
125  }
126 
133  public function getCustom()
134  {
135  if (is_null($this->custom)) {
137  $data = $this->raw(self::FIELD_CUSTOM);
138  if (is_null($data)) {
139  return null;
140  }
141 
142  $this->custom = CustomFieldsDraftModel::of($data);
143  }
144 
145  return $this->custom;
146  }
147 
154  public function getDescription()
155  {
156  if (is_null($this->description)) {
158  $data = $this->raw(self::FIELD_DESCRIPTION);
159  if (is_null($data)) {
160  return null;
161  }
162 
163  $this->description = LocalizedStringModel::of($data);
164  }
165 
166  return $this->description;
167  }
168 
175  public function getName()
176  {
177  if (is_null($this->name)) {
179  $data = $this->raw(self::FIELD_NAME);
180  if (is_null($data)) {
181  return null;
182  }
183 
184  $this->name = LocalizedStringModel::of($data);
185  }
186 
187  return $this->name;
188  }
189 
196  public function getQuantity()
197  {
198  if (is_null($this->quantity)) {
200  $data = $this->raw(self::FIELD_QUANTITY);
201  if (is_null($data)) {
202  return null;
203  }
204  $this->quantity = (int) $data;
205  }
206 
207  return $this->quantity;
208  }
209 
210 
214  public function setKey(?string $key): void
215  {
216  $this->key = $key;
217  }
218 
222  public function setAddedAt(?DateTimeImmutable $addedAt): void
223  {
224  $this->addedAt = $addedAt;
225  }
226 
230  public function setCustom(?CustomFieldsDraft $custom): void
231  {
232  $this->custom = $custom;
233  }
234 
239  {
240  $this->description = $description;
241  }
242 
246  public function setName(?LocalizedString $name): void
247  {
248  $this->name = $name;
249  }
250 
254  public function setQuantity(?int $quantity): void
255  {
256  $this->quantity = $quantity;
257  }
258 
259 
260  #[\ReturnTypeWillChange]
261  public function jsonSerialize()
262  {
263  $data = $this->toArray();
264  if (isset($data[TextLineItemDraft::FIELD_ADDED_AT]) && $data[TextLineItemDraft::FIELD_ADDED_AT] instanceof \DateTimeImmutable) {
265  $data[TextLineItemDraft::FIELD_ADDED_AT] = $data[TextLineItemDraft::FIELD_ADDED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
266  }
267  return (object) $data;
268  }
269 }
__construct(?string $key=null, ?DateTimeImmutable $addedAt=null, ?CustomFieldsDraft $custom=null, ?LocalizedString $description=null, ?LocalizedString $name=null, ?int $quantity=null)
static of($data=null)
Definition: MapperMap.php:45