1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jayS-de <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Model\CustomField; |
7
|
|
|
|
8
|
|
|
use Commercetools\Core\Model\Common\JsonObject; |
9
|
|
|
use Commercetools\Core\Model\Type\FieldDefinition; |
10
|
|
|
use Commercetools\Core\Model\Type\FieldDefinitionCollection; |
11
|
|
|
use Commercetools\Core\Model\Type\FieldType; |
12
|
|
|
use Commercetools\Core\Model\Type\Type; |
13
|
|
|
use Commercetools\Core\Model\Type\TypeReference; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @package Commercetools\Core\Model\CustomField |
17
|
|
|
* @link https://dev.commercetools.com/http-api-projects-custom-fields.html#custom-fields |
18
|
|
|
*/ |
19
|
|
|
class FieldContainer extends JsonObject |
20
|
|
|
{ |
21
|
14 |
|
public function fieldDefinition($field) |
22
|
|
|
{ |
23
|
14 |
|
if (!$this->parent instanceof CustomFieldObject) { |
24
|
|
|
return null; |
25
|
|
|
} |
26
|
14 |
|
$typeReference = $this->parent->getType(); |
27
|
|
|
|
28
|
14 |
|
if (!$typeReference instanceof TypeReference) { |
29
|
|
|
return null; |
30
|
|
|
} |
31
|
14 |
|
$type = $typeReference->getObj(); |
32
|
14 |
|
if (!$type instanceof Type) { |
33
|
7 |
|
return null; |
34
|
|
|
} |
35
|
7 |
|
$fieldDefinitions = $type->getFieldDefinitions(); |
36
|
7 |
|
if (!$fieldDefinitions instanceof FieldDefinitionCollection) { |
37
|
|
|
return null; |
38
|
|
|
} |
39
|
7 |
|
$fieldDefinition = $fieldDefinitions->getByName($field); |
40
|
7 |
|
if (!$fieldDefinition instanceof FieldDefinition) { |
41
|
|
|
return null; |
42
|
|
|
} |
43
|
7 |
|
$fieldType = $fieldDefinition->getType(); |
44
|
7 |
|
if (!$fieldType instanceof FieldType) { |
45
|
|
|
return null; |
46
|
|
|
} |
47
|
7 |
|
return $fieldType->fieldTypeDefinition(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $field |
52
|
|
|
* @param mixed $value |
53
|
|
|
* @return $this |
54
|
|
|
*/ |
55
|
|
|
public function set($field, $value) |
56
|
|
|
{ |
57
|
|
|
return parent::set($field, $value); |
58
|
|
|
} |
59
|
|
|
|
60
|
14 |
|
public function hasField($field) |
61
|
|
|
{ |
62
|
14 |
|
return true; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|