commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
ProductVariantModel.php
1<?php
2
3declare(strict_types=1);
10
22use stdClass;
23
28{
33 protected $id;
34
39 protected $sku;
40
45 protected $key;
46
51 protected $prices;
52
57 protected $attributes;
58
63 protected $price;
64
69 protected $images;
70
75 protected $assets;
76
81 protected $availability;
82
88
93 protected $scopedPrice;
94
100
101
105 public function __construct(
106 ?int $id = null,
107 ?string $sku = null,
108 ?string $key = null,
109 ?PriceCollection $prices = null,
111 ?Price $price = null,
112 ?ImageCollection $images = null,
113 ?AssetCollection $assets = null,
115 ?bool $isMatchingVariant = null,
117 ?bool $scopedPriceDiscounted = null
118 ) {
119 $this->id = $id;
120 $this->sku = $sku;
121 $this->key = $key;
122 $this->prices = $prices;
123 $this->attributes = $attributes;
124 $this->price = $price;
125 $this->images = $images;
126 $this->assets = $assets;
127 $this->availability = $availability;
128 $this->isMatchingVariant = $isMatchingVariant;
129 $this->scopedPrice = $scopedPrice;
130 $this->scopedPriceDiscounted = $scopedPriceDiscounted;
131 }
132
139 public function getId()
140 {
141 if (is_null($this->id)) {
143 $data = $this->raw(self::FIELD_ID);
144 if (is_null($data)) {
145 return null;
146 }
147 $this->id = (int) $data;
148 }
149
150 return $this->id;
151 }
152
159 public function getSku()
160 {
161 if (is_null($this->sku)) {
163 $data = $this->raw(self::FIELD_SKU);
164 if (is_null($data)) {
165 return null;
166 }
167 $this->sku = (string) $data;
168 }
169
170 return $this->sku;
171 }
172
180 public function getKey()
181 {
182 if (is_null($this->key)) {
184 $data = $this->raw(self::FIELD_KEY);
185 if (is_null($data)) {
186 return null;
187 }
188 $this->key = (string) $data;
189 }
190
191 return $this->key;
192 }
193
201 public function getPrices()
202 {
203 if (is_null($this->prices)) {
205 $data = $this->raw(self::FIELD_PRICES);
206 if (is_null($data)) {
207 return null;
208 }
209 $this->prices = PriceCollection::fromArray($data);
210 }
211
212 return $this->prices;
213 }
214
221 public function getAttributes()
222 {
223 if (is_null($this->attributes)) {
225 $data = $this->raw(self::FIELD_ATTRIBUTES);
226 if (is_null($data)) {
227 return null;
228 }
229 $this->attributes = AttributeCollection::fromArray($data);
230 }
231
232 return $this->attributes;
233 }
234
242 public function getPrice()
243 {
244 if (is_null($this->price)) {
246 $data = $this->raw(self::FIELD_PRICE);
247 if (is_null($data)) {
248 return null;
249 }
250
251 $this->price = PriceModel::of($data);
252 }
253
254 return $this->price;
255 }
256
263 public function getImages()
264 {
265 if (is_null($this->images)) {
267 $data = $this->raw(self::FIELD_IMAGES);
268 if (is_null($data)) {
269 return null;
270 }
271 $this->images = ImageCollection::fromArray($data);
272 }
273
274 return $this->images;
275 }
276
283 public function getAssets()
284 {
285 if (is_null($this->assets)) {
287 $data = $this->raw(self::FIELD_ASSETS);
288 if (is_null($data)) {
289 return null;
290 }
291 $this->assets = AssetCollection::fromArray($data);
292 }
293
294 return $this->assets;
295 }
296
305 public function getAvailability()
306 {
307 if (is_null($this->availability)) {
309 $data = $this->raw(self::FIELD_AVAILABILITY);
310 if (is_null($data)) {
311 return null;
312 }
313
314 $this->availability = ProductVariantAvailabilityModel::of($data);
315 }
316
317 return $this->availability;
318 }
319
327 public function getIsMatchingVariant()
328 {
329 if (is_null($this->isMatchingVariant)) {
331 $data = $this->raw(self::FIELD_IS_MATCHING_VARIANT);
332 if (is_null($data)) {
333 return null;
334 }
335 $this->isMatchingVariant = (bool) $data;
336 }
337
339 }
340
349 public function getScopedPrice()
350 {
351 if (is_null($this->scopedPrice)) {
353 $data = $this->raw(self::FIELD_SCOPED_PRICE);
354 if (is_null($data)) {
355 return null;
356 }
357
358 $this->scopedPrice = ScopedPriceModel::of($data);
359 }
360
361 return $this->scopedPrice;
362 }
363
371 public function getScopedPriceDiscounted()
372 {
373 if (is_null($this->scopedPriceDiscounted)) {
375 $data = $this->raw(self::FIELD_SCOPED_PRICE_DISCOUNTED);
376 if (is_null($data)) {
377 return null;
378 }
379 $this->scopedPriceDiscounted = (bool) $data;
380 }
381
383 }
384
385
389 public function setId(?int $id): void
390 {
391 $this->id = $id;
392 }
393
397 public function setSku(?string $sku): void
398 {
399 $this->sku = $sku;
400 }
401
405 public function setKey(?string $key): void
406 {
407 $this->key = $key;
408 }
409
413 public function setPrices(?PriceCollection $prices): void
414 {
415 $this->prices = $prices;
416 }
417
422 {
423 $this->attributes = $attributes;
424 }
425
429 public function setPrice(?Price $price): void
430 {
431 $this->price = $price;
432 }
433
437 public function setImages(?ImageCollection $images): void
438 {
439 $this->images = $images;
440 }
441
445 public function setAssets(?AssetCollection $assets): void
446 {
447 $this->assets = $assets;
448 }
449
454 {
455 $this->availability = $availability;
456 }
457
461 public function setIsMatchingVariant(?bool $isMatchingVariant): void
462 {
463 $this->isMatchingVariant = $isMatchingVariant;
464 }
465
470 {
471 $this->scopedPrice = $scopedPrice;
472 }
473
478 {
479 $this->scopedPriceDiscounted = $scopedPriceDiscounted;
480 }
481}
setAvailability(?ProductVariantAvailability $availability)
__construct(?int $id=null, ?string $sku=null, ?string $key=null, ?PriceCollection $prices=null, ?AttributeCollection $attributes=null, ?Price $price=null, ?ImageCollection $images=null, ?AssetCollection $assets=null, ?ProductVariantAvailability $availability=null, ?bool $isMatchingVariant=null, ?ScopedPrice $scopedPrice=null, ?bool $scopedPriceDiscounted=null)
static fromArray(array $data)