Skip to content

Commit ba64fbf

Browse files
committed
Added support for multiselect and checkbox values
1 parent 91251ea commit ba64fbf

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

app/code/Magento/QuoteGraphQl/Model/Cart/UpdateCartItem.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ public function execute(Quote $cart, int $cartItemId, float $qty, array $customi
7676

7777
$customizableOptions = [];
7878
foreach ($customizableOptionsData as $customizableOption) {
79-
$customizableOptions[$customizableOption['id']] = $customizableOption['value_string'];
79+
$customizableOptions[$customizableOption['id']] = $this->convertCustomOptionValue(
80+
$customizableOption['value_string']
81+
);
8082
}
8183

8284
try {
@@ -174,4 +176,23 @@ private function createBuyRequest(float $qty, array $customOptions): DataObject
174176
],
175177
]);
176178
}
179+
180+
// TODO: Refactor the code duplication with addCartItem
181+
// TODO: Make a reusable logic that is shared between add to cart / change cart approaches
182+
183+
/**
184+
* Convert custom options vakue
185+
*
186+
* @param string $value
187+
* @return string|array
188+
*/
189+
private function convertCustomOptionValue(string $value)
190+
{
191+
$value = trim($value);
192+
if (substr($value, 0, 1) === "[" &&
193+
substr($value, strlen($value) - 1, 1) === "]") {
194+
return explode(',', substr($value, 1, -1));
195+
}
196+
return $value;
197+
}
177198
}

0 commit comments

Comments
 (0)