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