Skip to content

Commit bec680f

Browse files
author
Prabhu Ram
committed
Merge remote-tracking branch 'koro/31075-add-type-to-customizabledatevalue' into 31660_Config_addToCart
2 parents 3e3646a + e7a9780 commit bec680f

File tree

3 files changed

+183
-0
lines changed

3 files changed

+183
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogGraphQl\Model\Resolver\Product;
9+
10+
use Magento\Framework\GraphQl\Config\Element\Field;
11+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
12+
use Magento\Framework\GraphQl\Query\ResolverInterface;
13+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
14+
15+
/**
16+
* Format the option type value.
17+
*/
18+
class CustomizableDateTypeOptionValue implements ResolverInterface
19+
{
20+
/**
21+
* Resolver option code.
22+
*/
23+
private const OPTION_CODE = 'type';
24+
25+
/**
26+
* Resolver enum type options to up case format.
27+
*
28+
* @param Field $field
29+
* @param ContextInterface $context
30+
* @param ResolveInfo $info
31+
* @param array|null $value
32+
* @param array|null $args
33+
*
34+
* @return string
35+
*/
36+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null): string
37+
{
38+
$dteType = $value[self::OPTION_CODE] ?? '';
39+
40+
return strtoupper($dteType);
41+
}
42+
}

app/code/Magento/CatalogGraphQl/etc/schema.graphqls

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ enum PriceTypeEnum @doc(description: "This enumeration the price type.") {
4949
DYNAMIC
5050
}
5151

52+
enum CustomizableDateTypeEnum @doc(description: "This enumeration customizable date type.") {
53+
DATE
54+
DATE_TIME
55+
TIME
56+
}
57+
5258
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.") {
5359
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.")
5460
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.")
@@ -154,6 +160,7 @@ type CustomizableDateOption implements CustomizableOptionInterface @doc(descript
154160
type CustomizableDateValue @doc(description: "CustomizableDateValue defines the price and sku of a product whose page contains a customized date picker.") {
155161
price: Float @doc(description: "The price assigned to this option.")
156162
price_type: PriceTypeEnum @doc(description: "FIXED, PERCENT, or DYNAMIC.")
163+
type: CustomizableDateTypeEnum @doc(description: "DATE, DATE_TIME or TIME") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableDateTypeOptionValue")
157164
sku: String @doc(description: "The Stock Keeping Unit for this option.")
158165
uid: ID! @doc(description: "The unique ID for a `CustomizableDateValue` object.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueUid")
159166
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Catalog\Options;
9+
10+
use Exception;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use Magento\TestFramework\Helper\CompareArraysRecursively;
13+
use Magento\TestFramework\TestCase\GraphQlAbstract;
14+
15+
/**
16+
* Test for customizable product options.
17+
*/
18+
class CustomizableOptionsTest extends GraphQlAbstract
19+
{
20+
/**
21+
* @var CompareArraysRecursively
22+
*/
23+
private $compareArraysRecursively;
24+
25+
/**
26+
* @inheritDoc
27+
*/
28+
protected function setUp(): void
29+
{
30+
$objectManager = Bootstrap::getObjectManager();
31+
$this->compareArraysRecursively = $objectManager->create(CompareArraysRecursively::class);
32+
}
33+
34+
/**
35+
* @magentoApiDataFixture Magento/Catalog/_files/product_with_options.php
36+
*
37+
* @param array $optionDataProvider
38+
*
39+
* @dataProvider getProductCustomizableOptionsProvider
40+
* @throws Exception
41+
*/
42+
public function testQueryCustomizableOptions(array $optionDataProvider): void
43+
{
44+
$productSku = 'simple';
45+
$query = $this->getQuery($productSku);
46+
$response = $this->graphQlQuery($query);
47+
$responseProduct = reset($response['products']['items']);
48+
self::assertNotEmpty($responseProduct['options']);
49+
50+
foreach ($optionDataProvider as $key => $data) {
51+
$this->compareArraysRecursively->execute($data, $responseProduct[$key]);
52+
}
53+
}
54+
55+
/**
56+
* Get query.
57+
*
58+
* @param string $sku
59+
*
60+
* @return string
61+
*/
62+
private function getQuery(string $sku): string
63+
{
64+
return <<<QUERY
65+
query {
66+
products(filter: { sku: { eq: "$sku" } }) {
67+
items {
68+
... on CustomizableProductInterface {
69+
options {
70+
option_id
71+
title
72+
... on CustomizableDateOption {
73+
value {
74+
type
75+
}
76+
}
77+
}
78+
}
79+
}
80+
}
81+
}
82+
QUERY;
83+
}
84+
85+
/**
86+
* Get product customizable options provider.
87+
*
88+
* @return array
89+
*/
90+
public function getProductCustomizableOptionsProvider(): array
91+
{
92+
return [
93+
'products' => [
94+
'items' => [
95+
'options' => [
96+
[
97+
'title' => 'test_option_code_1'
98+
],
99+
[
100+
'title' => 'area option'
101+
],
102+
[
103+
'title' => 'file option'
104+
],
105+
[
106+
'title' => 'radio option'
107+
],
108+
[
109+
'title' => 'multiple option'
110+
],
111+
[
112+
'title' => 'date option',
113+
'values' => [
114+
'type' => 'DATE'
115+
]
116+
],
117+
[
118+
'title' => 'date_time option',
119+
'values' => [
120+
'type' => 'DATE_TIME'
121+
]
122+
],
123+
[
124+
'title' => 'time option',
125+
'values' => [
126+
'type' => 'TIME'
127+
]
128+
]
129+
]
130+
]
131+
]
132+
];
133+
}
134+
}

0 commit comments

Comments
 (0)