commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
AssignedProductSelectionModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
15 use DateTimeImmutable;
16 use stdClass;
17 
22 {
27  protected $productSelection;
28 
33  protected $variantSelection;
34 
39  protected $variantExclusion;
40 
45  protected $createdAt;
46 
47 
51  public function __construct(
55  ?DateTimeImmutable $createdAt = null
56  ) {
57  $this->productSelection = $productSelection;
58  $this->variantSelection = $variantSelection;
59  $this->variantExclusion = $variantExclusion;
60  $this->createdAt = $createdAt;
61  }
62 
69  public function getProductSelection()
70  {
71  if (is_null($this->productSelection)) {
73  $data = $this->raw(self::FIELD_PRODUCT_SELECTION);
74  if (is_null($data)) {
75  return null;
76  }
77 
78  $this->productSelection = ProductSelectionReferenceModel::of($data);
79  }
80 
82  }
83 
91  public function getVariantSelection()
92  {
93  if (is_null($this->variantSelection)) {
95  $data = $this->raw(self::FIELD_VARIANT_SELECTION);
96  if (is_null($data)) {
97  return null;
98  }
100  $this->variantSelection = $className::of($data);
101  }
102 
104  }
105 
113  public function getVariantExclusion()
114  {
115  if (is_null($this->variantExclusion)) {
117  $data = $this->raw(self::FIELD_VARIANT_EXCLUSION);
118  if (is_null($data)) {
119  return null;
120  }
121 
122  $this->variantExclusion = ProductVariantExclusionModel::of($data);
123  }
124 
126  }
127 
134  public function getCreatedAt()
135  {
136  if (is_null($this->createdAt)) {
138  $data = $this->raw(self::FIELD_CREATED_AT);
139  if (is_null($data)) {
140  return null;
141  }
142  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
143  if (false === $data) {
144  return null;
145  }
146  $this->createdAt = $data;
147  }
148 
149  return $this->createdAt;
150  }
151 
152 
157  {
158  $this->productSelection = $productSelection;
159  }
160 
165  {
166  $this->variantSelection = $variantSelection;
167  }
168 
173  {
174  $this->variantExclusion = $variantExclusion;
175  }
176 
180  public function setCreatedAt(?DateTimeImmutable $createdAt): void
181  {
182  $this->createdAt = $createdAt;
183  }
184 
185 
186  #[\ReturnTypeWillChange]
187  public function jsonSerialize()
188  {
189  $data = $this->toArray();
190  if (isset($data[AssignedProductSelection::FIELD_CREATED_AT]) && $data[AssignedProductSelection::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
191  $data[AssignedProductSelection::FIELD_CREATED_AT] = $data[AssignedProductSelection::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
192  }
193  return (object) $data;
194  }
195 }
__construct(?ProductSelectionReference $productSelection=null, ?ProductVariantSelection $variantSelection=null, ?ProductVariantExclusion $variantExclusion=null, ?DateTimeImmutable $createdAt=null)