commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
CartDiscountTargetModel.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  'customLineItems' => CartDiscountCustomLineItemsTargetModel::class,
35  'lineItems' => CartDiscountLineItemsTargetModel::class,
36  'multiBuyCustomLineItems' => MultiBuyCustomLineItemsTargetModel::class,
37  'multiBuyLineItems' => MultiBuyLineItemsTargetModel::class,
38  'shipping' => CartDiscountShippingCostTargetModel::class,
39  'totalPrice' => CartDiscountTotalPriceTargetModel::class,
40  ];
41 
45  public function __construct(
46  ?string $type = null
47  ) {
48  $this->type = $type;
49  }
50 
55  public function getType()
56  {
57  if (is_null($this->type)) {
59  $data = $this->raw(self::FIELD_TYPE);
60  if (is_null($data)) {
61  return null;
62  }
63  $this->type = (string) $data;
64  }
65 
66  return $this->type;
67  }
68 
69 
70 
71 
72 
77  public static function resolveDiscriminatorClass($value): string
78  {
80  if (is_object($value) && isset($value->$fieldName)) {
82  $discriminatorValue = $value->$fieldName;
83  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
84  return self::$discriminatorClasses[$discriminatorValue];
85  }
86  }
87  if (is_array($value) && isset($value[$fieldName])) {
89  $discriminatorValue = $value[$fieldName];
90  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
91  return self::$discriminatorClasses[$discriminatorValue];
92  }
93  }
94 
96  $type = CartDiscountTargetModel::class;
97  return $type;
98  }
99 }