Skip to content

Commit 864a7c8

Browse files
committed
AC-15856: Internal Server Error When Adding Gift Card product to Cart via AddProductsToCart Mutation including custom_attributesV2
Fixed error while imploding custom attribute value array in the case the array is multidimentional
1 parent e044f74 commit 864a7c8

File tree

3 files changed

+735
-1
lines changed

3 files changed

+735
-1
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ function (AttributeInterface $customAttribute) {
108108
}
109109
$attributeValue = $productData[$attributeCode] ?? "";
110110
if (is_array($attributeValue)) {
111-
$attributeValue = implode(',', $attributeValue);
111+
$attributeValue = implode(
112+
',',
113+
$this->getFlatArrayIfArrayIsMultiDimentional($attributeValue)
114+
);
112115
}
113116
$customAttributes[] = [
114117
'attribute_code' => $attributeCode,
@@ -130,4 +133,24 @@ function (array $customAttribute) {
130133
'errors' => $productCustomAttributes['errors']
131134
];
132135
}
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+
}
133156
}

0 commit comments

Comments
 (0)