commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
CartDiscountTargetModel.php
1<?php
2
3declare(strict_types=1);
10
15use 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 'pattern' => CartDiscountPatternTargetModel::class,
39 'shipping' => CartDiscountShippingCostTargetModel::class,
40 'totalPrice' => CartDiscountTotalPriceTargetModel::class,
41 ];
42
46 public function __construct(
47 ?string $type = null
48 ) {
49 $this->type = $type;
50 }
51
56 public function getType()
57 {
58 if (is_null($this->type)) {
60 $data = $this->raw(self::FIELD_TYPE);
61 if (is_null($data)) {
62 return null;
63 }
64 $this->type = (string) $data;
65 }
66
67 return $this->type;
68 }
69
70
71
72
73
78 public static function resolveDiscriminatorClass($value): string
79 {
81 if (is_object($value) && isset($value->$fieldName)) {
83 $discriminatorValue = $value->$fieldName;
84 if (isset(self::$discriminatorClasses[$discriminatorValue])) {
85 return self::$discriminatorClasses[$discriminatorValue];
86 }
87 }
88 if (is_array($value) && isset($value[$fieldName])) {
90 $discriminatorValue = $value[$fieldName];
91 if (isset(self::$discriminatorClasses[$discriminatorValue])) {
92 return self::$discriminatorClasses[$discriminatorValue];
93 }
94 }
95
97 $type = CartDiscountTargetModel::class;
98 return $type;
99 }
100}