Skip to content

Commit 2e62d03

Browse files
committed
AC-15856: Internal Server Error When Adding Gift Card product to Cart via AddProductsToCart Mutation including custom_attributesV2
Fix internal server error with implode method
1 parent ef10afa commit 2e62d03

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductCustomAttributes.php

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,9 @@ function (AttributeInterface $customAttribute) {
108108
}
109109
$attributeValue = $productData[$attributeCode] ?? "";
110110
if (is_array($attributeValue)) {
111-
$attributeValue = implode(
112-
',',
113-
$this->getFlatArrayIfArrayIsMultiDimentional($attributeValue)
114-
);
111+
$attributeValue = (count($attributeValue) != count($attributeValue, COUNT_RECURSIVE))
112+
? json_encode($attributeValue)
113+
: implode(',', $attributeValue);
115114
}
116115
$customAttributes[] = [
117116
'attribute_code' => $attributeCode,
@@ -133,24 +132,4 @@ function (array $customAttribute) {
133132
'errors' => $productCustomAttributes['errors']
134133
];
135134
}
136-
137-
/**
138-
* Returns flat array if the array passed is multidimentional
139-
*
140-
* @param array $array
141-
* @return array
142-
*/
143-
private function getFlatArrayIfArrayIsMultiDimentional(array $array): array
144-
{
145-
// Check if it's a multi-dimensional array
146-
$isMultiDimensional = (count($array) != count($array, COUNT_RECURSIVE));
147-
if ($isMultiDimensional) {
148-
$flatArray = [];
149-
array_walk_recursive($array, function ($item) use (&$flatArray) {
150-
$flatArray[] = $item;
151-
});
152-
$array = $flatArray;
153-
}
154-
return $array;
155-
}
156135
}

0 commit comments

Comments
 (0)