1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jayS-de <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Model\ShippingMethod; |
7
|
|
|
|
8
|
|
|
use Commercetools\Core\Model\Common\Context; |
9
|
|
|
use Commercetools\Core\Model\Common\JsonObject; |
10
|
|
|
use Commercetools\Core\Model\Zone\ZoneReference; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @package Commercetools\Core\Model\ShippingMethod |
14
|
|
|
* @link https://dev.commercetools.com/http-api-projects-shippingMethods.html#shippingratepricetier |
15
|
|
|
* @method string getType() |
16
|
|
|
* @method ShippingRatePriceTier setType(string $type = null) |
17
|
|
|
*/ |
18
|
|
|
class ShippingRatePriceTier extends JsonObject |
19
|
|
|
{ |
20
|
|
|
const INPUT_TYPE = ''; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @inheritDoc |
24
|
|
|
*/ |
25
|
8 |
|
public function __construct(array $data = [], $context = null) |
26
|
|
|
{ |
27
|
8 |
|
if (static::INPUT_TYPE != '' && !isset($data[static::TYPE])) { |
|
|
|
|
28
|
7 |
|
$data[static::TYPE] = static::INPUT_TYPE; |
29
|
|
|
} |
30
|
8 |
|
parent::__construct($data, $context); |
31
|
8 |
|
} |
32
|
|
|
|
33
|
1 |
|
public function fieldDefinitions() |
34
|
|
|
{ |
35
|
|
|
return [ |
36
|
1 |
|
'type' => [static::TYPE => 'string'], |
37
|
|
|
]; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param array $data |
42
|
|
|
* @param Context|callable $context |
43
|
|
|
* @return static |
44
|
|
|
*/ |
45
|
4 |
|
public static function fromArray(array $data, $context = null) |
46
|
|
|
{ |
47
|
4 |
|
if (get_called_class() == ShippingRatePriceTier::class && isset($data[static::TYPE])) { |
48
|
4 |
|
$className = static::inputType($data[static::TYPE]); |
49
|
4 |
|
if (class_exists($className)) { |
50
|
4 |
|
return new $className($data, $context); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
return new static($data, $context); |
54
|
|
|
} |
55
|
|
|
|
56
|
4 |
|
protected static function inputType($type) |
57
|
|
|
{ |
58
|
|
|
$types = [ |
59
|
4 |
|
CartValue::INPUT_TYPE => CartValue::class, |
60
|
4 |
|
CartClassification::INPUT_TYPE => CartClassification::class, |
61
|
4 |
|
CartScore::INPUT_TYPE => CartScore::class, |
62
|
|
|
]; |
63
|
4 |
|
return isset($types[$type]) ? $types[$type] : ShippingRatePriceTier::class; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|