1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Model\OrderEdit; |
7
|
|
|
|
8
|
|
|
use Commercetools\Core\Model\Common\Context; |
9
|
|
|
use Commercetools\Core\Model\Common\JsonObject; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @package Commercetools\Core\Model\OrderEdit |
13
|
|
|
* |
14
|
|
|
* @method string getType() |
15
|
|
|
* @method OrderEditResult setType(string $type = null) |
16
|
|
|
*/ |
17
|
|
|
class OrderEditResult extends JsonObject |
18
|
|
|
{ |
19
|
|
|
const ORDER_EDIT_RESULT_TYPE = ''; |
20
|
|
|
|
21
|
4 |
|
public function fieldDefinitions() |
22
|
|
|
{ |
23
|
|
|
return [ |
24
|
4 |
|
'type' => [static::TYPE => 'string'], |
25
|
|
|
]; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param array $data |
30
|
|
|
* @param Context|callable $context |
31
|
|
|
* @return static |
32
|
|
|
*/ |
33
|
49 |
|
public static function fromArray(array $data, $context = null) |
34
|
|
|
{ |
35
|
49 |
|
if (get_called_class() == OrderEditResult::class && isset($data['type'])) { |
36
|
49 |
|
$className = static::resultType($data['type']); |
37
|
49 |
|
if (class_exists($className)) { |
38
|
49 |
|
return new $className($data, $context); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
return new static($data, $context); |
42
|
|
|
} |
43
|
|
|
|
44
|
49 |
|
protected static function resultType($typeId) |
45
|
|
|
{ |
46
|
|
|
$types = [ |
47
|
49 |
|
OrderEditNotProcessed::ORDER_EDIT_RESULT_TYPE => OrderEditNotProcessed::class, |
48
|
49 |
|
OrderEditPreviewFailure::ORDER_EDIT_RESULT_TYPE => OrderEditPreviewFailure::class, |
49
|
49 |
|
OrderEditPreviewSuccess::ORDER_EDIT_RESULT_TYPE => OrderEditPreviewSuccess::class, |
50
|
49 |
|
OrderEditApplied::ORDER_EDIT_RESULT_TYPE => OrderEditApplied::class, |
51
|
|
|
|
52
|
|
|
]; |
53
|
49 |
|
return isset($types[$typeId]) ? $types[$typeId] : OrderEditResult::class; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|