commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
ProductDiscountValueModel.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' => ProductDiscountValueAbsoluteModel::class,
35  'external' => ProductDiscountValueExternalModel::class,
36  'relative' => ProductDiscountValueRelativeModel::class,
37  ];
38 
42  public function __construct(
43  ?string $type = null
44  ) {
45  $this->type = $type;
46  }
47 
52  public function getType()
53  {
54  if (is_null($this->type)) {
56  $data = $this->raw(self::FIELD_TYPE);
57  if (is_null($data)) {
58  return null;
59  }
60  $this->type = (string) $data;
61  }
62 
63  return $this->type;
64  }
65 
66 
67 
68 
69 
74  public static function resolveDiscriminatorClass($value): string
75  {
77  if (is_object($value) && isset($value->$fieldName)) {
79  $discriminatorValue = $value->$fieldName;
80  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
81  return self::$discriminatorClasses[$discriminatorValue];
82  }
83  }
84  if (is_array($value) && isset($value[$fieldName])) {
86  $discriminatorValue = $value[$fieldName];
87  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
88  return self::$discriminatorClasses[$discriminatorValue];
89  }
90  }
91 
93  $type = ProductDiscountValueModel::class;
94  return $type;
95  }
96 }