commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
RecurringOrderDraftModel.php
1<?php
2
3declare(strict_types=1);
10
21use DateTimeImmutable;
22use stdClass;
23
28{
33 protected $key;
34
39 protected $cart;
40
45 protected $cartVersion;
46
51 protected $startsAt;
52
57 protected $expiresAt;
58
63 protected $state;
64
69 protected $custom;
70
71
75 public function __construct(
76 ?string $key = null,
78 ?int $cartVersion = null,
79 ?DateTimeImmutable $startsAt = null,
80 ?DateTimeImmutable $expiresAt = null,
83 ) {
84 $this->key = $key;
85 $this->cart = $cart;
86 $this->cartVersion = $cartVersion;
87 $this->startsAt = $startsAt;
88 $this->expiresAt = $expiresAt;
89 $this->state = $state;
90 $this->custom = $custom;
91 }
92
99 public function getKey()
100 {
101 if (is_null($this->key)) {
103 $data = $this->raw(self::FIELD_KEY);
104 if (is_null($data)) {
105 return null;
106 }
107 $this->key = (string) $data;
108 }
109
110 return $this->key;
111 }
112
119 public function getCart()
120 {
121 if (is_null($this->cart)) {
123 $data = $this->raw(self::FIELD_CART);
124 if (is_null($data)) {
125 return null;
126 }
127
128 $this->cart = CartResourceIdentifierModel::of($data);
129 }
130
131 return $this->cart;
132 }
133
140 public function getCartVersion()
141 {
142 if (is_null($this->cartVersion)) {
144 $data = $this->raw(self::FIELD_CART_VERSION);
145 if (is_null($data)) {
146 return null;
147 }
148 $this->cartVersion = (int) $data;
149 }
150
151 return $this->cartVersion;
152 }
153
160 public function getStartsAt()
161 {
162 if (is_null($this->startsAt)) {
164 $data = $this->raw(self::FIELD_STARTS_AT);
165 if (is_null($data)) {
166 return null;
167 }
168 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
169 if (false === $data) {
170 return null;
171 }
172 $this->startsAt = $data;
173 }
174
175 return $this->startsAt;
176 }
177
184 public function getExpiresAt()
185 {
186 if (is_null($this->expiresAt)) {
188 $data = $this->raw(self::FIELD_EXPIRES_AT);
189 if (is_null($data)) {
190 return null;
191 }
192 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
193 if (false === $data) {
194 return null;
195 }
196 $this->expiresAt = $data;
197 }
198
199 return $this->expiresAt;
200 }
201
208 public function getState()
209 {
210 if (is_null($this->state)) {
212 $data = $this->raw(self::FIELD_STATE);
213 if (is_null($data)) {
214 return null;
215 }
216
217 $this->state = StateResourceIdentifierModel::of($data);
218 }
219
220 return $this->state;
221 }
222
229 public function getCustom()
230 {
231 if (is_null($this->custom)) {
233 $data = $this->raw(self::FIELD_CUSTOM);
234 if (is_null($data)) {
235 return null;
236 }
237
238 $this->custom = CustomFieldsDraftModel::of($data);
239 }
240
241 return $this->custom;
242 }
243
244
248 public function setKey(?string $key): void
249 {
250 $this->key = $key;
251 }
252
256 public function setCart(?CartResourceIdentifier $cart): void
257 {
258 $this->cart = $cart;
259 }
260
264 public function setCartVersion(?int $cartVersion): void
265 {
266 $this->cartVersion = $cartVersion;
267 }
268
272 public function setStartsAt(?DateTimeImmutable $startsAt): void
273 {
274 $this->startsAt = $startsAt;
275 }
276
280 public function setExpiresAt(?DateTimeImmutable $expiresAt): void
281 {
282 $this->expiresAt = $expiresAt;
283 }
284
289 {
290 $this->state = $state;
291 }
292
296 public function setCustom(?CustomFieldsDraft $custom): void
297 {
298 $this->custom = $custom;
299 }
300
301
302 #[\ReturnTypeWillChange]
303 public function jsonSerialize()
304 {
305 $data = $this->toArray();
306 if (isset($data[RecurringOrderDraft::FIELD_STARTS_AT]) && $data[RecurringOrderDraft::FIELD_STARTS_AT] instanceof \DateTimeImmutable) {
307 $data[RecurringOrderDraft::FIELD_STARTS_AT] = $data[RecurringOrderDraft::FIELD_STARTS_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
308 }
309
310 if (isset($data[RecurringOrderDraft::FIELD_EXPIRES_AT]) && $data[RecurringOrderDraft::FIELD_EXPIRES_AT] instanceof \DateTimeImmutable) {
311 $data[RecurringOrderDraft::FIELD_EXPIRES_AT] = $data[RecurringOrderDraft::FIELD_EXPIRES_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
312 }
313 return (object) $data;
314 }
315}
__construct(?string $key=null, ?CartResourceIdentifier $cart=null, ?int $cartVersion=null, ?DateTimeImmutable $startsAt=null, ?DateTimeImmutable $expiresAt=null, ?StateResourceIdentifier $state=null, ?CustomFieldsDraft $custom=null)