From f45d97f9b26dc7c4edf9e87e647f8af9b08c9582 Mon Sep 17 00:00:00 2001 From: korovitskyi Date: Fri, 4 Dec 2020 11:11:26 +0200 Subject: [PATCH 1/4] 31075-added type to CustomizableDateValue for detect from one of three types --- .../CatalogGraphQl/etc/schema.graphqls | 1 + .../Options/CustomizableOptionsTest.php | 134 ++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/Options/CustomizableOptionsTest.php diff --git a/app/code/Magento/CatalogGraphQl/etc/schema.graphqls b/app/code/Magento/CatalogGraphQl/etc/schema.graphqls index 812965228682f..55a78db4a8b55 100644 --- a/app/code/Magento/CatalogGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CatalogGraphQl/etc/schema.graphqls @@ -153,6 +153,7 @@ type CustomizableDateOption implements CustomizableOptionInterface @doc(descript type CustomizableDateValue @doc(description: "CustomizableDateValue defines the price and sku of a product whose page contains a customized date picker.") { price: Float @doc(description: "The price assigned to this option.") price_type: PriceTypeEnum @doc(description: "FIXED, PERCENT, or DYNAMIC.") + type: String @doc(description: "date, date_time or time") sku: String @doc(description: "The Stock Keeping Unit for this option.") uid: ID! @doc(description: "A string that encodes option details.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueUid") # A Base64 string that encodes option details. } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/Options/CustomizableOptionsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/Options/CustomizableOptionsTest.php new file mode 100644 index 0000000000000..0cb5d9c1ad124 --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/Options/CustomizableOptionsTest.php @@ -0,0 +1,134 @@ +compareArraysRecursively = $objectManager->create(CompareArraysRecursively::class); + } + + /** + * @magentoApiDataFixture Magento/Catalog/_files/product_with_options.php + * + * @param array $optionDataProvider + * + * @dataProvider getProductCustomizableOptionsProvider + * @throws Exception + */ + public function testQueryCustomizableOptions(array $optionDataProvider): void + { + $productSku = 'simple'; + $query = $this->getQuery($productSku); + $response = $this->graphQlQuery($query); + $responseProduct = reset($response['products']['items']); + self::assertNotEmpty($responseProduct['options']); + + foreach ($optionDataProvider as $key => $data) { + $this->compareArraysRecursively->execute($data, $responseProduct[$key]); + } + } + + /** + * Get query. + * + * @param string $sku + * + * @return string + */ + private function getQuery(string $sku): string + { + return << [ + 'items' => [ + 'options' => [ + [ + 'title' => 'test_option_code_1' + ], + [ + 'title' => 'area option' + ], + [ + 'title' => 'file option' + ], + [ + 'title' => 'radio option' + ], + [ + 'title' => 'multiple option' + ], + [ + 'title' => 'date option', + 'values' => [ + 'type' => 'date' + ] + ], + [ + 'title' => 'date_time option', + 'values' => [ + 'type' => 'date_time' + ] + ], + [ + 'title' => 'time option', + 'values' => [ + 'type' => 'time' + ] + ] + ] + ] + ] + ]; + } +} From 5ca8332a899f081283f9f660b4d37e2b37f6e6d1 Mon Sep 17 00:00:00 2001 From: korovitskyi Date: Wed, 9 Dec 2020 10:25:47 +0200 Subject: [PATCH 2/4] 31075-update option as enum type --- app/code/Magento/CatalogGraphQl/etc/schema.graphqls | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogGraphQl/etc/schema.graphqls b/app/code/Magento/CatalogGraphQl/etc/schema.graphqls index 55a78db4a8b55..a44081003b9c0 100644 --- a/app/code/Magento/CatalogGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CatalogGraphQl/etc/schema.graphqls @@ -49,6 +49,12 @@ enum PriceTypeEnum @doc(description: "This enumeration the price type.") { DYNAMIC } +enum CustomizableDateTypeEnum @doc(description: "This enumeration customizable date type.") { + date + date_time + time +} + type ProductPrices @doc(description: "ProductPrices is deprecated, replaced by PriceRange. The ProductPrices object contains the regular price of an item, as well as its minimum and maximum prices. Only composite products, which include bundle, configurable, and grouped products, can contain a minimum and maximum price.") { minimalPrice: Price @deprecated(reason: "Use PriceRange.minimum_price.") @doc(description: "The lowest possible final price for all the options defined within a composite product. If you are specifying a price range, this would be the from value.") maximalPrice: Price @deprecated(reason: "Use PriceRange.maximum_price.") @doc(description: "The highest possible final price for all the options defined within a composite product. If you are specifying a price range, this would be the to value.") @@ -153,7 +159,7 @@ type CustomizableDateOption implements CustomizableOptionInterface @doc(descript type CustomizableDateValue @doc(description: "CustomizableDateValue defines the price and sku of a product whose page contains a customized date picker.") { price: Float @doc(description: "The price assigned to this option.") price_type: PriceTypeEnum @doc(description: "FIXED, PERCENT, or DYNAMIC.") - type: String @doc(description: "date, date_time or time") + type: CustomizableDateTypeEnum @doc(description: "date, date_time or time") sku: String @doc(description: "The Stock Keeping Unit for this option.") uid: ID! @doc(description: "A string that encodes option details.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueUid") # A Base64 string that encodes option details. } From 23a286ed172efd4db23f8fcf45c06cefb15d0c3e Mon Sep 17 00:00:00 2001 From: korovitskyi Date: Wed, 16 Dec 2020 10:59:02 +0200 Subject: [PATCH 3/4] fix static fail --- .../Magento/GraphQl/Catalog/Options/CustomizableOptionsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/Options/CustomizableOptionsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/Options/CustomizableOptionsTest.php index 0cb5d9c1ad124..29f2584c37c1f 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/Options/CustomizableOptionsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/Options/CustomizableOptionsTest.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magento\GraphQl\Catalog\Options\Uid; +namespace Magento\GraphQl\Catalog\Options; use Exception; use Magento\TestFramework\Helper\Bootstrap; From e7a9780d6bf60859d262d361635e7433e6fc2f23 Mon Sep 17 00:00:00 2001 From: Korovitskyi Date: Fri, 29 Jan 2021 18:38:12 +0200 Subject: [PATCH 4/4] fix enum formt --- .../CustomizableDateTypeOptionValue.php | 42 +++++++++++++++++++ .../CatalogGraphQl/etc/schema.graphqls | 8 ++-- .../Options/CustomizableOptionsTest.php | 6 +-- 3 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableDateTypeOptionValue.php diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableDateTypeOptionValue.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableDateTypeOptionValue.php new file mode 100644 index 0000000000000..1b9583cc7239e --- /dev/null +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableDateTypeOptionValue.php @@ -0,0 +1,42 @@ + 'date option', 'values' => [ - 'type' => 'date' + 'type' => 'DATE' ] ], [ 'title' => 'date_time option', 'values' => [ - 'type' => 'date_time' + 'type' => 'DATE_TIME' ] ], [ 'title' => 'time option', 'values' => [ - 'type' => 'time' + 'type' => 'TIME' ] ] ]