Skip to content

Commit

Permalink
Added support for multiselect and checkbox values
Browse files Browse the repository at this point in the history
  • Loading branch information
rogyar committed May 17, 2019
1 parent 91251ea commit ba64fbf
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion app/code/Magento/QuoteGraphQl/Model/Cart/UpdateCartItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public function execute(Quote $cart, int $cartItemId, float $qty, array $customi

$customizableOptions = [];
foreach ($customizableOptionsData as $customizableOption) {
$customizableOptions[$customizableOption['id']] = $customizableOption['value_string'];
$customizableOptions[$customizableOption['id']] = $this->convertCustomOptionValue(
$customizableOption['value_string']
);
}

try {
Expand Down Expand Up @@ -174,4 +176,23 @@ private function createBuyRequest(float $qty, array $customOptions): DataObject
],
]);
}

// TODO: Refactor the code duplication with addCartItem
// TODO: Make a reusable logic that is shared between add to cart / change cart approaches

/**
* Convert custom options vakue
*
* @param string $value
* @return string|array
*/
private function convertCustomOptionValue(string $value)
{
$value = trim($value);
if (substr($value, 0, 1) === "[" &&
substr($value, strlen($value) - 1, 1) === "]") {
return explode(',', substr($value, 1, -1));
}
return $value;
}
}

0 comments on commit ba64fbf

Please sign in to comment.