From d3734f85853a8ed77f4d6255058f4c8f042f2126 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Mon, 24 Jun 2019 15:46:50 -0500 Subject: [PATCH] magento/graphql-ce#622: No possibility to update customizable_options in updateCartItems mutation - code style + minor fixes --- .../Model/Cart/AddSimpleProductToCart.php | 23 ------------------- .../Model/Cart/CreateBuyRequest.php | 14 ++++++----- .../Model/Cart/UpdateCartItem.php | 18 +++++---------- .../EditQuoteItemWithCustomOptionsTest.php | 1 - .../add_simple_product_with_options.php | 14 ++++++----- 5 files changed, 22 insertions(+), 48 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php index 0bf7968a50fae..3f6cc42614030 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php @@ -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; - } } diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/CreateBuyRequest.php b/app/code/Magento/QuoteGraphQl/Model/Cart/CreateBuyRequest.php index bcbfc43d567a9..b95be8db2dccd 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/CreateBuyRequest.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/CreateBuyRequest.php @@ -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, + ], + ] + ); } /** diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/UpdateCartItem.php b/app/code/Magento/QuoteGraphQl/Model/Cart/UpdateCartItem.php index 7d653788ab0af..b18c6ad662335 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/UpdateCartItem.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/UpdateCartItem.php @@ -18,7 +18,6 @@ /** * Update cart item - * */ class UpdateCartItem { @@ -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); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/EditQuoteItemWithCustomOptionsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/EditQuoteItemWithCustomOptionsTest.php index 8c46f66e70cf0..62c1ae0dab3c7 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/EditQuoteItemWithCustomOptionsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/EditQuoteItemWithCustomOptionsTest.php @@ -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 diff --git a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/add_simple_product_with_options.php b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/add_simple_product_with_options.php index 68e2261ab02b0..ecd1428a5d617 100644 --- a/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/add_simple_product_with_options.php +++ b/dev/tests/integration/testsuite/Magento/GraphQl/Quote/_files/add_simple_product_with_options.php @@ -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');