Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
#622: No possibility to update customizable_options in updateCartItem…
Browse files Browse the repository at this point in the history
…s mutation

- code style + minor fixes
  • Loading branch information
lenaorobei committed Jun 24, 2019
1 parent 1cf357b commit d3734f8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,4 @@ private function extractQuantity(array $cartItemData): float
}
return $quantity;
}

/**
* Extract Customizable Options from cart item data
*
* @param array $cartItemData
* @return array
*/
private function extractCustomizableOptions(array $cartItemData): array
{
if (!isset($cartItemData['customizable_options']) || empty($cartItemData['customizable_options'])) {
return [];
}

$customizableOptionsData = [];
foreach ($cartItemData['customizable_options'] as $customizableOption) {
if (isset($customizableOption['value_string'])) {
$customizableOptionsData[$customizableOption['id']] = $this->convertCustomOptionValue(
$customizableOption['value_string']
);
}
}
return $customizableOptionsData;
}
}
14 changes: 8 additions & 6 deletions app/code/Magento/QuoteGraphQl/Model/Cart/CreateBuyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ public function execute(float $qty, array $customizableOptionsData): DataObject
}
}

return $this->dataObjectFactory->create([
'data' => [
'qty' => $qty,
'options' => $customizableOptions,
],
]);
return $this->dataObjectFactory->create(
[
'data' => [
'qty' => $qty,
'options' => $customizableOptions,
],
]
);
}

/**
Expand Down
18 changes: 6 additions & 12 deletions app/code/Magento/QuoteGraphQl/Model/Cart/UpdateCartItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

/**
* Update cart item
*
*/
class UpdateCartItem
{
Expand Down Expand Up @@ -86,18 +85,13 @@ public function execute(Quote $cart, int $cartItemId, float $quantity, array $cu
);
}

if (is_string($result)) {
throw new GraphQlInputException(__(
'Could not update cart item: %message',
['message' => $result]
));
}

if ($result->getHasError()) {
throw new GraphQlInputException(__(
'Could not update cart item: %message',
['message' => $result->getMessage(true)]
));
throw new GraphQlInputException(
__(
'Could not update cart item: %message',
['message' => $result->getMessage()]
)
);
}

$this->quoteRepository->save($cart);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ private function getQuoteItemIdBySku(string $sku): int
return (int)$quoteItem->getId();
}


/**
* Generate an array with test values for customizable options
* based on the option type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@
$cartItemCustomOptions[$productOption->getId()] = 'initial value';
}

$request = $dataObjectFactory->create([
'data' => [
'qty' => 1.0,
'options' => $cartItemCustomOptions,
],
]);
$request = $dataObjectFactory->create(
[
'data' => [
'qty' => 1.0,
'options' => $cartItemCustomOptions,
],
]
);

$quote = $quoteFactory->create();
$quoteResource->load($quote, 'test_quote', 'reserved_order_id');
Expand Down

0 comments on commit d3734f8

Please sign in to comment.