From 81daba855c0e741b3659fb109556115638e15f5d Mon Sep 17 00:00:00 2001 From: Ievgenii Gryshkun Date: Fri, 22 Mar 2019 14:53:44 +0200 Subject: [PATCH 1/7] Cannot return null for non-nullable field SelectedCustomizableOptionValue.sort_order and Call to a member function getPriceType() on null --- .../Model/Cart/AddSimpleProductToCart.php | 18 +++++++++++++++++- app/code/Magento/QuoteGraphQl/etc/di.xml | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php index ad730288e5cc2..36a31642e5139 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php @@ -15,6 +15,7 @@ use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; use Magento\Framework\Stdlib\ArrayManager; use Magento\Quote\Model\Quote; +use phpDocumentor\Reflection\Types\Mixed_; /** * Add simple product to cart @@ -140,7 +141,9 @@ private function extractCustomizableOptions(array $cartItemData): array $customizableOptionsData = []; foreach ($customizableOptions as $customizableOption) { - $customizableOptionsData[$customizableOption['id']] = $customizableOption['value']; + $customizableOptionsData[$customizableOption['id']] = $this->convertCustomOptions( + $customizableOption['value'] + ); } return $customizableOptionsData; } @@ -161,4 +164,17 @@ private function createBuyRequest(float $quantity, array $customOptions): DataOb ], ]); } + + /** + * @param string $value + * @return string|array + */ + private function convertCustomOptions(string $value) + { + if (substr($value, 0, 1) === "[" || + substr($value, strlen($value) - 1, 1) === "]") { + return explode(',', substr($value, 1, -1)); + } + return $value; + } } diff --git a/app/code/Magento/QuoteGraphQl/etc/di.xml b/app/code/Magento/QuoteGraphQl/etc/di.xml index 0697761a2a2a6..32b8b12987ffa 100644 --- a/app/code/Magento/QuoteGraphQl/etc/di.xml +++ b/app/code/Magento/QuoteGraphQl/etc/di.xml @@ -26,7 +26,7 @@ Magento\QuoteGraphQl\Model\CartItem\DataProvider\CustomizableOptionValue\Text Magento\QuoteGraphQl\Model\CartItem\DataProvider\CustomizableOptionValue\Dropdown Magento\QuoteGraphQl\Model\CartItem\DataProvider\CustomizableOptionValue\Dropdown - Magento\QuoteGraphQl\Model\CartItem\DataProvider\CustomizableOptionValue\Dropdown + Magento\QuoteGraphQl\Model\CartItem\DataProvider\CustomizableOptionValue\Multiple Magento\QuoteGraphQl\Model\CartItem\DataProvider\CustomizableOptionValue\Multiple From 742e6a79c733819744c6afa75dd1cde1dac2824c Mon Sep 17 00:00:00 2001 From: Ievgenii Gryshkun Date: Thu, 28 Mar 2019 08:31:35 +0200 Subject: [PATCH 2/7] Cannot return null for non-nullable field SelectedCustomizableOptionValue.sort_order and Call to a member function getPriceType() on null --- .../Model/Cart/AddSimpleProductToCart.php | 1 - .../CatalogInventory/AddProductToCartTest.php | 83 +++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php index 36a31642e5139..cf65393b08997 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php @@ -15,7 +15,6 @@ use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; use Magento\Framework\Stdlib\ArrayManager; use Magento\Quote\Model\Quote; -use phpDocumentor\Reflection\Types\Mixed_; /** * Add simple product to cart diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/AddProductToCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/AddProductToCartTest.php index 6f27693eeb4a7..c2fbfc1418dbf 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/AddProductToCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/AddProductToCartTest.php @@ -46,6 +46,89 @@ public function testAddProductIfQuantityIsNotAvailable() $this->graphQlMutation($query); } + /** + * @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php + * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php + * @expectedException \Exception + * @expectedExceptionMessage The product's required option(s) weren't entered. Make sure the options are entered and try again. + */ + public function testAddProductWithoutRequiredCustomOPtions() + { + $sku = 'simple_with_custom_options'; + $qty = 1; + + $maskedQuoteId = $this->getMaskedQuoteId(); + $query = $this->getAddSimpleProductQuery($maskedQuoteId, $sku, $qty); + $this->graphQlQuery($query); + } + + /** + * @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php + * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php + */ + public function testAddProductWithRequiredCustomOPtions() + { + $sku = 'simple_with_custom_options'; + $qty = 1; + $productCustomOptions = Bootstrap::getObjectManager() + ->get(\Magento\Catalog\Api\ProductCustomOptionRepositoryInterface::class) + ->getList($sku); + $customizableOptions = ''; + foreach ($productCustomOptions as $option) { + $value = $option->getValues() ? + '[' . key($option->getValues()) . ']' : + 'Test'; + $customizableOptions .= ' { + id: ' . $option->getId() . ' + value: "' . $value . '" + }'; + } + + $maskedQuoteId = $this->getMaskedQuoteId(); + $query = <<graphQlQuery($query); + self::assertArrayHasKey('cart', $response['addSimpleProductsToCart']); + + self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']); + self::assertEquals( + 1, + $response['addSimpleProductsToCart']['cart']['items'][0]['customizable_options'][0]['is_required'] + ); + } + /** * @magentoApiDataFixture Magento/Catalog/_files/products.php * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php From 30bc7b764590cb030eb57a4af3011fae77b5ddf4 Mon Sep 17 00:00:00 2001 From: Ievgenii Gryshkun Date: Wed, 3 Apr 2019 09:10:08 +0300 Subject: [PATCH 3/7] Cannot return null for non-nullable field SelectedCustomizableOptionValue.sort_order and Call to a member function getPriceType() on null --- .../Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php index cf65393b08997..bd81a15307e31 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php @@ -170,7 +170,7 @@ private function createBuyRequest(float $quantity, array $customOptions): DataOb */ private function convertCustomOptions(string $value) { - if (substr($value, 0, 1) === "[" || + if (substr($value, 0, 1) === "[" && substr($value, strlen($value) - 1, 1) === "]") { return explode(',', substr($value, 1, -1)); } From 733ddf969f840a0a787a459c96c97869c7f58ad1 Mon Sep 17 00:00:00 2001 From: Ievgenii Gryshkun Date: Sat, 27 Apr 2019 12:26:29 +0300 Subject: [PATCH 4/7] Cannot return null for non-nullable field SelectedCustomizableOptionValue.sort_order and Call to a member function getPriceType() on null --- app/code/Magento/QuoteGraphQl/etc/schema.graphqls | 1 - .../Magento/GraphQl/CatalogInventory/AddProductToCartTest.php | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls index e2d29e93db574..0b6b392c2ed9b 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -325,7 +325,6 @@ type SelectedCustomizableOptionValue { label: String! value: String! price: CartItemSelectedOptionValuePrice! - sort_order: Int! } type CartItemSelectedOptionValuePrice { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/AddProductToCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/AddProductToCartTest.php index c2fbfc1418dbf..708e034a4626b 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/AddProductToCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/AddProductToCartTest.php @@ -52,7 +52,7 @@ public function testAddProductIfQuantityIsNotAvailable() * @expectedException \Exception * @expectedExceptionMessage The product's required option(s) weren't entered. Make sure the options are entered and try again. */ - public function testAddProductWithoutRequiredCustomOPtions() + public function testAddProductWithoutRequiredCustomOptions() { $sku = 'simple_with_custom_options'; $qty = 1; @@ -66,7 +66,7 @@ public function testAddProductWithoutRequiredCustomOPtions() * @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php */ - public function testAddProductWithRequiredCustomOPtions() + public function testAddProductWithRequiredCustomOptions() { $sku = 'simple_with_custom_options'; $qty = 1; From 1315577e2099637207f02deec48607d81f7cde46 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Tue, 30 Apr 2019 11:33:53 -0500 Subject: [PATCH 5/7] GraphQL-474: Cannot return null for non-nullable field SelectedCustomizableOptionValue.sort_order and Call to a member function getPriceType() on null --- .../Model/Cart/AddSimpleProductToCart.php | 52 ++++++------- .../Magento/QuoteGraphQl/etc/schema.graphqls | 7 +- ...mpleProductWithCustomOptionsToCartTest.php | 75 +++++++------------ ...tualProductWithCustomOptionsToCartTest.php | 75 +++++++------------ 4 files changed, 84 insertions(+), 125 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php index bd81a15307e31..251f17619c2a8 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php @@ -13,21 +13,13 @@ use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; -use Magento\Framework\Stdlib\ArrayManager; use Magento\Quote\Model\Quote; /** * Add simple product to cart - * - * TODO: should be replaced for different types resolver */ class AddSimpleProductToCart { - /** - * @var ArrayManager - */ - private $arrayManager; - /** * @var DataObjectFactory */ @@ -39,16 +31,13 @@ class AddSimpleProductToCart private $productRepository; /** - * @param ArrayManager $arrayManager * @param DataObjectFactory $dataObjectFactory * @param ProductRepositoryInterface $productRepository */ public function __construct( - ArrayManager $arrayManager, DataObjectFactory $dataObjectFactory, ProductRepositoryInterface $productRepository ) { - $this->arrayManager = $arrayManager; $this->dataObjectFactory = $dataObjectFactory; $this->productRepository = $productRepository; } @@ -67,11 +56,6 @@ public function execute(Quote $cart, array $cartItemData): void { $sku = $this->extractSku($cartItemData); $quantity = $this->extractQuantity($cartItemData); - if ($quantity <= 0) { - throw new GraphQlInputException( - __('Please enter a number greater than 0 in this field.') - ); - } $customizableOptions = $this->extractCustomizableOptions($cartItemData); try { @@ -105,11 +89,10 @@ public function execute(Quote $cart, array $cartItemData): void */ private function extractSku(array $cartItemData): string { - $sku = $this->arrayManager->get('data/sku', $cartItemData); - if (!isset($sku)) { - throw new GraphQlInputException(__('Missing key "sku" in cart item data')); + if (!isset($cartItemData['data']['sku']) || empty($cartItemData['data']['sku'])) { + throw new GraphQlInputException(__('Missed "sku" in cart item data')); } - return (string)$sku; + return (string)$cartItemData['data']['sku']; } /** @@ -121,11 +104,17 @@ private function extractSku(array $cartItemData): string */ private function extractQuantity(array $cartItemData): float { - $quantity = $this->arrayManager->get('data/quantity', $cartItemData); - if (!isset($quantity)) { - throw new GraphQlInputException(__('Missing key "quantity" in cart item data')); + if (!isset($cartItemData['data']['quantity'])) { + throw new GraphQlInputException(__('Missed "qty" in cart item data')); } - return (float)$quantity; + $quantity = (float)$cartItemData['data']['quantity']; + + if ($quantity <= 0) { + throw new GraphQlInputException( + __('Please enter a number greater than 0 in this field.') + ); + } + return $quantity; } /** @@ -136,13 +125,17 @@ private function extractQuantity(array $cartItemData): float */ private function extractCustomizableOptions(array $cartItemData): array { - $customizableOptions = $this->arrayManager->get('customizable_options', $cartItemData, []); + if (!isset($cartItemData['customizable_options']) || empty($cartItemData['customizable_options'])) { + return []; + } $customizableOptionsData = []; - foreach ($customizableOptions as $customizableOption) { - $customizableOptionsData[$customizableOption['id']] = $this->convertCustomOptions( - $customizableOption['value'] - ); + foreach ($cartItemData['customizable_options'] as $customizableOption) { + if (isset($customizableOption['value_string'])) { + $customizableOptionsData[$customizableOption['id']] = $this->convertCustomOptions( + $customizableOption['value_string'] + ); + } } return $customizableOptionsData; } @@ -170,6 +163,7 @@ private function createBuyRequest(float $quantity, array $customOptions): DataOb */ private function convertCustomOptions(string $value) { + $value = trim($value); if (substr($value, 0, 1) === "[" && substr($value, strlen($value) - 1, 1) === "]") { return explode(',', substr($value, 1, -1)); diff --git a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls index 0b6b392c2ed9b..c2b92034c3294 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -52,7 +52,7 @@ input CartItemInput { input CustomizableOptionInput { id: Int! - value: String! + value_string: String! } input ApplyCouponToCartInput { @@ -314,8 +314,7 @@ interface CartItemInterface @typeResolver(class: "Magento\\QuoteGraphQl\\Model\\ type SelectedCustomizableOption { id: Int! label: String! - type: String! - is_required: Int! + is_required: Boolean! values: [SelectedCustomizableOptionValue!]! sort_order: Int! } @@ -323,7 +322,7 @@ type SelectedCustomizableOption { type SelectedCustomizableOptionValue { id: Int! label: String! - value: String! + value: String price: CartItemSelectedOptionValuePrice! } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/AddSimpleProductWithCustomOptionsToCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/AddSimpleProductWithCustomOptionsToCartTest.php index 63546298304b0..d64c51354129d 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/AddSimpleProductWithCustomOptionsToCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/AddSimpleProductWithCustomOptionsToCartTest.php @@ -50,41 +50,11 @@ public function testAddSimpleProductWithOptions() $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); $customOptionsValues = $this->getCustomOptionsValuesForQuery($sku); - /* Generate customizable options fragment for GraphQl request */ - $queryCustomizableOptions = preg_replace('/"([^"]+)"\s*:\s*/', '$1:', json_encode($customOptionsValues)); + $queryCustomizableOptionValues = preg_replace('/"([^"]+)"\s*:\s*/', '$1:', json_encode($customOptionsValues)); - $query = <<getQuery($maskedQuoteId, $sku, $quantity, $customizableOptions); $response = $this->graphQlMutation($query); @@ -95,7 +65,7 @@ public function testAddSimpleProductWithOptions() $assignedOptionsCount = count($customOptionsValues); for ($counter = 0; $counter < $assignedOptionsCount; $counter++) { self::assertEquals( - $customOptionsValues[$counter]['value'], + $customOptionsValues[$counter]['value_string'], $customizableOptionsOutput[$counter]['values'][0]['value'] ); } @@ -107,13 +77,31 @@ public function testAddSimpleProductWithOptions() * @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_options.php * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php */ - public function testAddSimpleProductWithNoRequiredOptionsSet() + public function testAddSimpleProductWithMissedRequiredOptionsSet() { + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); $sku = 'simple'; $quantity = 1; - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); + $customizableOptions = ''; - $query = <<getQuery($maskedQuoteId, $sku, $quantity, $customizableOptions); + + self::expectExceptionMessage( + 'The product\'s required option(s) weren\'t entered. Make sure the options are entered and try again.' + ); + $this->graphQlMutation($query); + } + + /** + * @param string $maskedQuoteId + * @param string $sku + * @param float $quantity + * @param string $customizableOptions + * @return string + */ + private function getQuery(string $maskedQuoteId, string $sku, float $quantity, string $customizableOptions): string + { + return <<graphQlMutation($query); } /** @@ -168,13 +151,13 @@ private function getCustomOptionsValuesForQuery(string $sku): array if ($optionType == 'field' || $optionType == 'area') { $customOptionsValues[] = [ 'id' => (int) $customOption->getOptionId(), - 'value' => 'test' + 'value_string' => 'test' ]; } elseif ($optionType == 'drop_down') { $optionSelectValues = $customOption->getValues(); $customOptionsValues[] = [ 'id' => (int) $customOption->getOptionId(), - 'value' => reset($optionSelectValues)->getOptionTypeId() + 'value_string' => reset($optionSelectValues)->getOptionTypeId() ]; } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/AddVirtualProductWithCustomOptionsToCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/AddVirtualProductWithCustomOptionsToCartTest.php index 94ac11ad8e0b1..55542919cc098 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/AddVirtualProductWithCustomOptionsToCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/AddVirtualProductWithCustomOptionsToCartTest.php @@ -50,41 +50,11 @@ public function testAddVirtualProductWithOptions() $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); $customOptionsValues = $this->getCustomOptionsValuesForQuery($sku); - /* Generate customizable options fragment for GraphQl request */ - $queryCustomizableOptions = preg_replace('/"([^"]+)"\s*:\s*/', '$1:', json_encode($customOptionsValues)); + $queryCustomizableOptionValues = preg_replace('/"([^"]+)"\s*:\s*/', '$1:', json_encode($customOptionsValues)); - $query = <<getQuery($maskedQuoteId, $sku, $quantity, $customizableOptions); $response = $this->graphQlMutation($query); @@ -95,7 +65,7 @@ public function testAddVirtualProductWithOptions() $assignedOptionsCount = count($customOptionsValues); for ($counter = 0; $counter < $assignedOptionsCount; $counter++) { self::assertEquals( - $customOptionsValues[$counter]['value'], + $customOptionsValues[$counter]['value_string'], $customizableOptionsOutput[$counter]['values'][0]['value'] ); } @@ -107,13 +77,31 @@ public function testAddVirtualProductWithOptions() * @magentoApiDataFixture Magento/Catalog/_files/product_virtual_with_options.php * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php */ - public function testAddVirtualProductWithNoRequiredOptionsSet() + public function testAddSimpleProductWithMissedRequiredOptionsSet() { + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); $sku = 'virtual'; $quantity = 1; - $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); + $customizableOptions = ''; - $query = <<getQuery($maskedQuoteId, $sku, $quantity, $customizableOptions); + + self::expectExceptionMessage( + 'The product\'s required option(s) weren\'t entered. Make sure the options are entered and try again.' + ); + $this->graphQlMutation($query); + } + + /** + * @param string $maskedQuoteId + * @param string $sku + * @param float $quantity + * @param string $customizableOptions + * @return string + */ + private function getQuery(string $maskedQuoteId, string $sku, float $quantity, string $customizableOptions): string + { + return <<graphQlMutation($query); } /** @@ -168,13 +151,13 @@ private function getCustomOptionsValuesForQuery(string $sku): array if ($optionType == 'field' || $optionType == 'area') { $customOptionsValues[] = [ 'id' => (int) $customOption->getOptionId(), - 'value' => 'test' + 'value_string' => 'test' ]; } elseif ($optionType == 'drop_down') { $optionSelectValues = $customOption->getValues(); $customOptionsValues[] = [ 'id' => (int) $customOption->getOptionId(), - 'value' => reset($optionSelectValues)->getOptionTypeId() + 'value_string' => reset($optionSelectValues)->getOptionTypeId() ]; } } From b115f1c546d5f09e67c7f369ec8b239c1b0a2984 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Tue, 30 Apr 2019 11:53:24 -0500 Subject: [PATCH 6/7] GraphQL-474: Cannot return null for non-nullable field SelectedCustomizableOptionValue.sort_order and Call to a member function getPriceType() on null --- .../CatalogInventory/AddProductToCartTest.php | 83 ------------------- 1 file changed, 83 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/AddProductToCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/AddProductToCartTest.php index 708e034a4626b..6f27693eeb4a7 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/AddProductToCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/CatalogInventory/AddProductToCartTest.php @@ -46,89 +46,6 @@ public function testAddProductIfQuantityIsNotAvailable() $this->graphQlMutation($query); } - /** - * @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php - * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php - * @expectedException \Exception - * @expectedExceptionMessage The product's required option(s) weren't entered. Make sure the options are entered and try again. - */ - public function testAddProductWithoutRequiredCustomOptions() - { - $sku = 'simple_with_custom_options'; - $qty = 1; - - $maskedQuoteId = $this->getMaskedQuoteId(); - $query = $this->getAddSimpleProductQuery($maskedQuoteId, $sku, $qty); - $this->graphQlQuery($query); - } - - /** - * @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php - * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php - */ - public function testAddProductWithRequiredCustomOptions() - { - $sku = 'simple_with_custom_options'; - $qty = 1; - $productCustomOptions = Bootstrap::getObjectManager() - ->get(\Magento\Catalog\Api\ProductCustomOptionRepositoryInterface::class) - ->getList($sku); - $customizableOptions = ''; - foreach ($productCustomOptions as $option) { - $value = $option->getValues() ? - '[' . key($option->getValues()) . ']' : - 'Test'; - $customizableOptions .= ' { - id: ' . $option->getId() . ' - value: "' . $value . '" - }'; - } - - $maskedQuoteId = $this->getMaskedQuoteId(); - $query = <<graphQlQuery($query); - self::assertArrayHasKey('cart', $response['addSimpleProductsToCart']); - - self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']); - self::assertEquals( - 1, - $response['addSimpleProductsToCart']['cart']['items'][0]['customizable_options'][0]['is_required'] - ); - } - /** * @magentoApiDataFixture Magento/Catalog/_files/products.php * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php From 05ea6ef10a470a76735219e705825d896bf3c848 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Tue, 30 Apr 2019 13:49:39 -0500 Subject: [PATCH 7/7] GraphQL-474: Cannot return null for non-nullable field SelectedCustomizableOptionValue.sort_order and Call to a member function getPriceType() on null --- .../QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php index 251f17619c2a8..b491b10730c10 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php @@ -132,7 +132,7 @@ private function extractCustomizableOptions(array $cartItemData): array $customizableOptionsData = []; foreach ($cartItemData['customizable_options'] as $customizableOption) { if (isset($customizableOption['value_string'])) { - $customizableOptionsData[$customizableOption['id']] = $this->convertCustomOptions( + $customizableOptionsData[$customizableOption['id']] = $this->convertCustomOptionValue( $customizableOption['value_string'] ); } @@ -158,10 +158,12 @@ private function createBuyRequest(float $quantity, array $customOptions): DataOb } /** + * Convert custom options vakue + * * @param string $value * @return string|array */ - private function convertCustomOptions(string $value) + private function convertCustomOptionValue(string $value) { $value = trim($value); if (substr($value, 0, 1) === "[" &&