Skip to content

Commit f097e92

Browse files
Implemented support of attribute property.
1 parent 802ab7a commit f097e92

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/Model/Resolver/Products/DataPostProcessor.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public function process(
4444
array $products,
4545
string $graphqlResolvePath,
4646
$graphqlResolveInfo,
47-
array $processorOptions = []
47+
array $processorOptions = [
48+
'isSingleProduct' => false
49+
]
4850
): array {
4951
$processorsCallbacks = array_map(function ($processor) use (
5052
$products,

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

+18-2
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,21 @@ protected function appendWithSwatchOptions(
282282
}
283283
}
284284

285+
protected function isAttributeSkipped(
286+
Attribute $attribute,
287+
bool $isSingleProduct
288+
): bool {
289+
if ($isSingleProduct) {
290+
return !$attribute->getIsVisibleOnFront(); // skip attribute if is is not visible on FE
291+
}
292+
293+
/**
294+
* On PLP, KEEP attribute if it is used on PLP and is visible on FE.
295+
* This means if not visible on PLP or is not visible we should SKIP it.
296+
*/
297+
return !$attribute->getUsedInProductListing() || !$attribute->getIsVisibleOnFront();
298+
}
299+
285300
/**
286301
* @inheritDoc
287302
* @throws LocalizedException
@@ -297,6 +312,8 @@ public function process(
297312
$attributes = [];
298313
$swatchAttributes = [];
299314

315+
$isSingleProduct = isset($processorOptions['isSingleProduct']) ? $processorOptions['isSingleProduct'] : false;
316+
300317
$fields = $this->getFieldsFromProductInfo(
301318
$graphqlResolveInfo,
302319
$graphqlResolvePath
@@ -321,7 +338,7 @@ public function process(
321338
* @var Attribute $attribute
322339
*/
323340
foreach ($product->getAttributes() as $attributeCode => $attribute) {
324-
if (!$attribute->getIsVisibleOnFront()) {
341+
if ($this->isAttributeSkipped($attribute, $isSingleProduct)) {
325342
continue;
326343
}
327344

@@ -338,7 +355,6 @@ public function process(
338355
$attributes[$attributeCode] = $attribute;
339356

340357
// Collect all swatches (we will need additional data for them)
341-
/** @var Attribute $attribute */
342358
if ($isCollectOptions && $this->swatchHelper->isSwatchAttribute($attribute)) {
343359
$swatchAttributes[] = $attributeCode;
344360
}

0 commit comments

Comments
 (0)