commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
CartDiscountValueDraftModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
15 use stdClass;
16 
21 {
22  public const DISCRIMINATOR_VALUE = '';
27  protected $type;
28 
33  private static $discriminatorClasses = [
34  'absolute' => CartDiscountValueAbsoluteDraftModel::class,
35  'fixed' => CartDiscountValueFixedDraftModel::class,
36  'giftLineItem' => CartDiscountValueGiftLineItemDraftModel::class,
37  'relative' => CartDiscountValueRelativeDraftModel::class,
38  ];
39 
43  public function __construct(
44  ?string $type = null
45  ) {
46  $this->type = $type;
47  }
48 
53  public function getType()
54  {
55  if (is_null($this->type)) {
57  $data = $this->raw(self::FIELD_TYPE);
58  if (is_null($data)) {
59  return null;
60  }
61  $this->type = (string) $data;
62  }
63 
64  return $this->type;
65  }
66 
67 
68 
69 
70 
75  public static function resolveDiscriminatorClass($value): string
76  {
78  if (is_object($value) && isset($value->$fieldName)) {
80  $discriminatorValue = $value->$fieldName;
81  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
82  return self::$discriminatorClasses[$discriminatorValue];
83  }
84  }
85  if (is_array($value) && isset($value[$fieldName])) {
87  $discriminatorValue = $value[$fieldName];
88  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
89  return self::$discriminatorClasses[$discriminatorValue];
90  }
91  }
92 
94  $type = CartDiscountValueDraftModel::class;
95  return $type;
96  }
97 }