commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
QueryPriceModel.php
1<?php
2
3declare(strict_types=1);
10
21use DateTimeImmutable;
22use stdClass;
23
27final class QueryPriceModel extends JsonObjectModel implements QueryPrice
28{
33 protected $id;
34
39 protected $value;
40
45 protected $country;
46
51 protected $customerGroup;
52
57 protected $channel;
58
63 protected $validFrom;
64
69 protected $validUntil;
70
75 protected $discounted;
76
81 protected $custom;
82
87 protected $tiers;
88
89
93 public function __construct(
94 ?string $id = null,
95 ?Money $value = null,
96 ?string $country = null,
99 ?DateTimeImmutable $validFrom = null,
100 ?DateTimeImmutable $validUntil = null,
102 ?CustomFields $custom = null,
104 ) {
105 $this->id = $id;
106 $this->value = $value;
107 $this->country = $country;
108 $this->customerGroup = $customerGroup;
109 $this->channel = $channel;
110 $this->validFrom = $validFrom;
111 $this->validUntil = $validUntil;
112 $this->discounted = $discounted;
113 $this->custom = $custom;
114 $this->tiers = $tiers;
115 }
116
123 public function getId()
124 {
125 if (is_null($this->id)) {
127 $data = $this->raw(self::FIELD_ID);
128 if (is_null($data)) {
129 return null;
130 }
131 $this->id = (string) $data;
132 }
133
134 return $this->id;
135 }
136
143 public function getValue()
144 {
145 if (is_null($this->value)) {
147 $data = $this->raw(self::FIELD_VALUE);
148 if (is_null($data)) {
149 return null;
150 }
151
152 $this->value = MoneyModel::of($data);
153 }
154
155 return $this->value;
156 }
157
164 public function getCountry()
165 {
166 if (is_null($this->country)) {
168 $data = $this->raw(self::FIELD_COUNTRY);
169 if (is_null($data)) {
170 return null;
171 }
172 $this->country = (string) $data;
173 }
174
175 return $this->country;
176 }
177
184 public function getCustomerGroup()
185 {
186 if (is_null($this->customerGroup)) {
188 $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
189 if (is_null($data)) {
190 return null;
191 }
192
193 $this->customerGroup = CustomerGroupReferenceModel::of($data);
194 }
195
197 }
198
205 public function getChannel()
206 {
207 if (is_null($this->channel)) {
209 $data = $this->raw(self::FIELD_CHANNEL);
210 if (is_null($data)) {
211 return null;
212 }
213
214 $this->channel = ChannelReferenceModel::of($data);
215 }
216
217 return $this->channel;
218 }
219
226 public function getValidFrom()
227 {
228 if (is_null($this->validFrom)) {
230 $data = $this->raw(self::FIELD_VALID_FROM);
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->validFrom = $data;
239 }
240
241 return $this->validFrom;
242 }
243
250 public function getValidUntil()
251 {
252 if (is_null($this->validUntil)) {
254 $data = $this->raw(self::FIELD_VALID_UNTIL);
255 if (is_null($data)) {
256 return null;
257 }
258 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
259 if (false === $data) {
260 return null;
261 }
262 $this->validUntil = $data;
263 }
264
265 return $this->validUntil;
266 }
267
274 public function getDiscounted()
275 {
276 if (is_null($this->discounted)) {
278 $data = $this->raw(self::FIELD_DISCOUNTED);
279 if (is_null($data)) {
280 return null;
281 }
282
283 $this->discounted = DiscountedPriceDraftModel::of($data);
284 }
285
286 return $this->discounted;
287 }
288
295 public function getCustom()
296 {
297 if (is_null($this->custom)) {
299 $data = $this->raw(self::FIELD_CUSTOM);
300 if (is_null($data)) {
301 return null;
302 }
303
304 $this->custom = CustomFieldsModel::of($data);
305 }
306
307 return $this->custom;
308 }
309
317 public function getTiers()
318 {
319 if (is_null($this->tiers)) {
321 $data = $this->raw(self::FIELD_TIERS);
322 if (is_null($data)) {
323 return null;
324 }
325 $this->tiers = PriceTierDraftCollection::fromArray($data);
326 }
327
328 return $this->tiers;
329 }
330
331
335 public function setId(?string $id): void
336 {
337 $this->id = $id;
338 }
339
343 public function setValue(?Money $value): void
344 {
345 $this->value = $value;
346 }
347
351 public function setCountry(?string $country): void
352 {
353 $this->country = $country;
354 }
355
360 {
361 $this->customerGroup = $customerGroup;
362 }
363
367 public function setChannel(?ChannelReference $channel): void
368 {
369 $this->channel = $channel;
370 }
371
375 public function setValidFrom(?DateTimeImmutable $validFrom): void
376 {
377 $this->validFrom = $validFrom;
378 }
379
383 public function setValidUntil(?DateTimeImmutable $validUntil): void
384 {
385 $this->validUntil = $validUntil;
386 }
387
392 {
393 $this->discounted = $discounted;
394 }
395
399 public function setCustom(?CustomFields $custom): void
400 {
401 $this->custom = $custom;
402 }
403
408 {
409 $this->tiers = $tiers;
410 }
411
412
413 #[\ReturnTypeWillChange]
414 public function jsonSerialize()
415 {
416 $data = $this->toArray();
417 if (isset($data[QueryPrice::FIELD_VALID_FROM]) && $data[QueryPrice::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
418 $data[QueryPrice::FIELD_VALID_FROM] = $data[QueryPrice::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
419 }
420
421 if (isset($data[QueryPrice::FIELD_VALID_UNTIL]) && $data[QueryPrice::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
422 $data[QueryPrice::FIELD_VALID_UNTIL] = $data[QueryPrice::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
423 }
424 return (object) $data;
425 }
426}
__construct(?string $id=null, ?Money $value=null, ?string $country=null, ?CustomerGroupReference $customerGroup=null, ?ChannelReference $channel=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null, ?DiscountedPriceDraft $discounted=null, ?CustomFields $custom=null, ?PriceTierDraftCollection $tiers=null)
setValidUntil(?DateTimeImmutable $validUntil)
setCustomerGroup(?CustomerGroupReference $customerGroup)
setDiscounted(?DiscountedPriceDraft $discounted)
setTiers(?PriceTierDraftCollection $tiers)
static fromArray(array $data)