Skip to content

Commit b02c6d7

Browse files
Merge pull request #11 from riha112/1650
#1650 Remove empty attributes from response
2 parents 205685e + 261ffbf commit b02c6d7

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/Model/Resolver/Products/DataPostProcessor/Attributes.php

+16-8
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,13 @@ protected function appendWithValue(
126126
foreach ($attributes as $attributeCode => $attribute) {
127127
$attributeValue = $product->getData($attributeCode);
128128

129+
// Remove all empty attributes
129130
if (!$attributeValue) {
130-
// Remove all empty attributes
131+
// If attribute does not contain both value nor options then we remove it from output
132+
if (!isset($productAttributes[$productId][$attributeCode]) ||
133+
!$productAttributes[$productId][$attributeCode]['attribute_options']) {
134+
unset($productAttributes[$productId][$attributeCode]);
135+
}
131136
continue;
132137
}
133138

@@ -289,8 +294,11 @@ protected function isAttributeSkipped(
289294
/**
290295
* On PLP, KEEP attribute if it is used on PLP.
291296
* This means if not visible on PLP we should SKIP it.
297+
*
298+
* On PDP, If attribute has no label then it shouldn't be
299+
* visible.
292300
*/
293-
return !$attribute->getUsedInProductListing();
301+
return !$attribute->getUsedInProductListing() || !$attribute->getStoreLabel();
294302
}
295303

296304
/**
@@ -358,12 +366,6 @@ public function process(
358366
}
359367
}
360368

361-
$this->appendWithValue(
362-
$attributes,
363-
$productIds,
364-
$productAttributes
365-
);
366-
367369
if ($isCollectOptions) {
368370
$this->appendWithOptions(
369371
$attributes,
@@ -373,6 +375,12 @@ public function process(
373375
);
374376
}
375377

378+
$this->appendWithValue(
379+
$attributes,
380+
$productIds,
381+
$productAttributes
382+
);
383+
376384
return function (&$productData) use ($productAttributes) {
377385
if (!isset($productData['entity_id'])) {
378386
return;

0 commit comments

Comments
 (0)