13
13
use Magento \Framework \Api \Search \AggregationValueInterface ;
14
14
use Magento \Framework \Api \Search \BucketInterface ;
15
15
use Magento \CatalogGraphQl \DataProvider \Product \LayeredNavigation \Formatter \LayerFormatter ;
16
+ use Magento \Config \Model \Config \Source \Yesno ;
16
17
17
18
/**
18
19
* @inheritdoc
@@ -49,18 +50,26 @@ class Attribute implements LayerBuilderInterface
49
50
self ::CATEGORY_BUCKET
50
51
];
51
52
53
+ /**
54
+ * @var Yesno
55
+ */
56
+ private Yesno $ YesNo ;
57
+
52
58
/**
53
59
* @param AttributeOptionProvider $attributeOptionProvider
54
60
* @param LayerFormatter $layerFormatter
61
+ * @param Yesno $YesNo
55
62
* @param array $bucketNameFilter
56
63
*/
57
64
public function __construct (
58
65
AttributeOptionProvider $ attributeOptionProvider ,
59
66
LayerFormatter $ layerFormatter ,
67
+ Yesno $ YesNo ,
60
68
$ bucketNameFilter = []
61
69
) {
62
70
$ this ->attributeOptionProvider = $ attributeOptionProvider ;
63
71
$ this ->layerFormatter = $ layerFormatter ;
72
+ $ this ->YesNo = $ YesNo ;
64
73
$ this ->bucketNameFilter = \array_merge ($ this ->bucketNameFilter , $ bucketNameFilter );
65
74
}
66
75
@@ -87,7 +96,11 @@ public function build(AggregationInterface $aggregation, ?int $storeId): array
87
96
isset ($ attribute ['position ' ]) ? $ attribute ['position ' ] : null
88
97
);
89
98
90
- $ options = $ this ->getSortedOptions ($ bucket , isset ($ attribute ['options ' ]) ? $ attribute ['options ' ] : []);
99
+ $ options = $ this ->getSortedOptions (
100
+ $ bucket ,
101
+ isset ($ attribute ['options ' ]) ? $ attribute ['options ' ] : [],
102
+ ($ attribute ['attribute_type ' ]) ? $ attribute ['attribute_type ' ]: ''
103
+ );
91
104
foreach ($ options as $ option ) {
92
105
$ result [$ bucketName ]['options ' ][] = $ this ->layerFormatter ->buildItem (
93
106
$ option ['label ' ],
@@ -168,9 +181,11 @@ function (AggregationValueInterface $value) {
168
181
*
169
182
* @param BucketInterface $bucket
170
183
* @param array $optionLabels
184
+ * @param string $attributeType
171
185
* @return array
186
+ * @SuppressWarnings(PHPMD.UnusedLocalVariable)
172
187
*/
173
- private function getSortedOptions (BucketInterface $ bucket , array $ optionLabels ): array
188
+ private function getSortedOptions (BucketInterface $ bucket , array $ optionLabels, string $ attributeType ): array
174
189
{
175
190
/**
176
191
* Option labels array has been sorted
@@ -179,7 +194,16 @@ private function getSortedOptions(BucketInterface $bucket, array $optionLabels):
179
194
foreach ($ bucket ->getValues () as $ value ) {
180
195
$ metrics = $ value ->getMetrics ();
181
196
$ optionValue = $ metrics ['value ' ];
182
- $ optionLabel = $ optionLabels [$ optionValue ] ?? $ optionValue ;
197
+ if (isset ($ optionLabels [$ optionValue ])) {
198
+ $ optionLabel = $ optionLabels [$ optionValue ];
199
+ } else {
200
+ if ($ attributeType === 'boolean ' ) {
201
+ $ yesNoOptions = $ this ->YesNo ->toArray ();
202
+ $ optionLabel = $ yesNoOptions [$ optionValue ];
203
+ } else {
204
+ $ optionLabel = $ optionValue ;
205
+ }
206
+ }
183
207
$ options [$ optionValue ] = $ metrics + ['label ' => $ optionLabel ];
184
208
}
185
209
@@ -188,7 +212,7 @@ private function getSortedOptions(BucketInterface $bucket, array $optionLabels):
188
212
*/
189
213
foreach ($ options as $ optionId => $ option ) {
190
214
if (!is_array ($ options [$ optionId ])) {
191
- unset($ options [$ optionId ]);
215
+ unset($ options [$ optionId ]);
192
216
}
193
217
}
194
218
0 commit comments