17
17
*/
18
18
class ProductEntityAttributesForAst implements FieldEntityAttributesInterface
19
19
{
20
+ private const PRODUCT_BASE_TYPE = 'SimpleProduct ' ;
21
+
22
+ private const PRODUCT_FILTER_INPUT = 'ProductAttributeFilterInput ' ;
23
+
20
24
/**
21
25
* @var ConfigInterface
22
26
*/
@@ -51,9 +55,9 @@ public function __construct(
51
55
*/
52
56
public function getEntityAttributes () : array
53
57
{
54
- $ productTypeSchema = $ this ->config ->getConfigElement (' SimpleProduct ' );
58
+ $ productTypeSchema = $ this ->config ->getConfigElement (self :: PRODUCT_BASE_TYPE );
55
59
if (!$ productTypeSchema instanceof Type) {
56
- throw new \LogicException (__ (" SimpleProduct type not defined in schema. " ));
60
+ throw new \LogicException (__ (self :: PRODUCT_BASE_TYPE . " type not defined in schema. " ));
57
61
}
58
62
59
63
$ fields = [];
@@ -69,6 +73,9 @@ public function getEntityAttributes() : array
69
73
}
70
74
}
71
75
76
+ $ productAttributeFilterFields = $ this ->getProductAttributeFilterFields ();
77
+ $ fields = array_merge ($ fields , $ productAttributeFilterFields );
78
+
72
79
foreach ($ this ->additionalAttributes as $ attributeName ) {
73
80
$ fields [$ attributeName ] = [
74
81
'type ' => 'String ' ,
@@ -78,4 +85,24 @@ public function getEntityAttributes() : array
78
85
79
86
return $ fields ;
80
87
}
88
+
89
+ /**
90
+ * Get fields from ProductAttributeFilterInput
91
+ *
92
+ * @return array
93
+ */
94
+ private function getProductAttributeFilterFields ()
95
+ {
96
+ $ filterFields = [];
97
+
98
+ $ productAttributeFilterSchema = $ this ->config ->getConfigElement (self ::PRODUCT_FILTER_INPUT );
99
+ $ productAttributeFilterFields = $ productAttributeFilterSchema ->getFields ();
100
+ foreach ($ productAttributeFilterFields as $ filterField ) {
101
+ $ filterFields [$ filterField ->getName ()] = [
102
+ 'type ' => 'String ' ,
103
+ 'fieldName ' => $ filterField ->getName (),
104
+ ];
105
+ }
106
+ return $ filterFields ;
107
+ }
81
108
}
0 commit comments