1313use Magento \Framework \Api \Search \AggregationValueInterface ;
1414use Magento \Framework \Api \Search \BucketInterface ;
1515use Magento \CatalogGraphQl \DataProvider \Product \LayeredNavigation \Formatter \LayerFormatter ;
16+ use Magento \Config \Model \Config \Source \Yesno ;
1617
1718/**
1819 * @inheritdoc
@@ -49,18 +50,26 @@ class Attribute implements LayerBuilderInterface
4950 self ::CATEGORY_BUCKET
5051 ];
5152
53+ /**
54+ * @var Yesno
55+ */
56+ private Yesno $ YesNo ;
57+
5258 /**
5359 * @param AttributeOptionProvider $attributeOptionProvider
5460 * @param LayerFormatter $layerFormatter
61+ * @param Yesno $YesNo
5562 * @param array $bucketNameFilter
5663 */
5764 public function __construct (
5865 AttributeOptionProvider $ attributeOptionProvider ,
5966 LayerFormatter $ layerFormatter ,
67+ Yesno $ YesNo ,
6068 $ bucketNameFilter = []
6169 ) {
6270 $ this ->attributeOptionProvider = $ attributeOptionProvider ;
6371 $ this ->layerFormatter = $ layerFormatter ;
72+ $ this ->YesNo = $ YesNo ;
6473 $ this ->bucketNameFilter = \array_merge ($ this ->bucketNameFilter , $ bucketNameFilter );
6574 }
6675
@@ -87,7 +96,11 @@ public function build(AggregationInterface $aggregation, ?int $storeId): array
8796 isset ($ attribute ['position ' ]) ? $ attribute ['position ' ] : null
8897 );
8998
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+ );
91104 foreach ($ options as $ option ) {
92105 $ result [$ bucketName ]['options ' ][] = $ this ->layerFormatter ->buildItem (
93106 $ option ['label ' ],
@@ -168,9 +181,11 @@ function (AggregationValueInterface $value) {
168181 *
169182 * @param BucketInterface $bucket
170183 * @param array $optionLabels
184+ * @param string $attributeType
171185 * @return array
186+ * @SuppressWarnings(PHPMD.UnusedLocalVariable)
172187 */
173- private function getSortedOptions (BucketInterface $ bucket , array $ optionLabels ): array
188+ private function getSortedOptions (BucketInterface $ bucket , array $ optionLabels, string $ attributeType ): array
174189 {
175190 /**
176191 * Option labels array has been sorted
@@ -179,7 +194,16 @@ private function getSortedOptions(BucketInterface $bucket, array $optionLabels):
179194 foreach ($ bucket ->getValues () as $ value ) {
180195 $ metrics = $ value ->getMetrics ();
181196 $ 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+ }
183207 $ options [$ optionValue ] = $ metrics + ['label ' => $ optionLabel ];
184208 }
185209
@@ -188,7 +212,7 @@ private function getSortedOptions(BucketInterface $bucket, array $optionLabels):
188212 */
189213 foreach ($ options as $ optionId => $ option ) {
190214 if (!is_array ($ options [$ optionId ])) {
191- unset($ options [$ optionId ]);
215+ unset($ options [$ optionId ]);
192216 }
193217 }
194218
0 commit comments