Skip to content

Commit d9a67c5

Browse files
ENGCOM-7608: #257: create new id_v2 option #28210
- Merge Pull Request #28210 from mmezhensky/magento2:257-single-mutation-option-id-v2 - Merged commits: 1. 3140823 2. f4e2665 3. 54625d9 4. f990c5d 5. e2daca8 6. a095757
2 parents 1d8a6d7 + a095757 commit d9a67c5

File tree

13 files changed

+663
-5
lines changed

13 files changed

+663
-5
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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\BundleGraphQl\Model\Resolver\Options;
9+
10+
use Magento\Framework\GraphQl\Config\Element\Field;
11+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
12+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
13+
use Magento\Framework\GraphQl\Query\ResolverInterface;
14+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
16+
/**
17+
* Format new option uid in base64 encode for entered bundle options
18+
*/
19+
class BundleItemOptionUid implements ResolverInterface
20+
{
21+
/**
22+
* Option type name
23+
*/
24+
private const OPTION_TYPE = 'bundle';
25+
26+
/**
27+
* Create a option uid for entered option in "<option-type>/<option-id>/<option-value-id>/<quantity>" format
28+
*
29+
* @param Field $field
30+
* @param ContextInterface $context
31+
* @param ResolveInfo $info
32+
* @param array|null $value
33+
* @param array|null $args
34+
*
35+
* @return string
36+
*
37+
* @throws GraphQlInputException
38+
*
39+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
40+
*/
41+
public function resolve(
42+
Field $field,
43+
$context,
44+
ResolveInfo $info,
45+
array $value = null,
46+
array $args = null
47+
) {
48+
if (!isset($value['option_id']) || empty($value['option_id'])) {
49+
throw new GraphQlInputException(__('"option_id" value should be specified.'));
50+
}
51+
52+
if (!isset($value['selection_id']) || empty($value['selection_id'])) {
53+
throw new GraphQlInputException(__('"selection_id" value should be specified.'));
54+
}
55+
56+
$optionDetails = [
57+
self::OPTION_TYPE,
58+
$value['option_id'],
59+
$value['selection_id'],
60+
(int) $value['selection_qty']
61+
];
62+
63+
$content = implode('/', $optionDetails);
64+
65+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
66+
return base64_encode($content);
67+
}
68+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type BundleItemOption @doc(description: "BundleItemOption defines characteristic
6666
price_type: PriceTypeEnum @doc(description: "One of FIXED, PERCENT, or DYNAMIC.")
6767
can_change_quantity: Boolean @doc(description: "Indicates whether the customer can change the number of items for this option.")
6868
product: ProductInterface @doc(description: "Contains details about this product option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product")
69+
uid: ID! @doc(description: "A string that encodes option details.") @resolver(class: "Magento\\BundleGraphQl\\Model\\Resolver\\Options\\BundleItemOptionUid") # A Base64 string that encodes option details.
6970
}
7071

7172
type BundleProduct implements ProductInterface, PhysicalProductInterface, CustomizableProductInterface @doc(description: "BundleProduct defines basic features of a bundle product and contains multiple BundleItems.") {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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\Exception\GraphQlInputException;
12+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
13+
use Magento\Framework\GraphQl\Query\ResolverInterface;
14+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
16+
/**
17+
* Format new option uid in base64 encode for entered custom options
18+
*/
19+
class CustomizableEnteredOptionValueUid implements ResolverInterface
20+
{
21+
/**
22+
* Option type name
23+
*/
24+
private const OPTION_TYPE = 'custom-option';
25+
26+
/**
27+
* Create a option uid for entered option in "<option-type>/<option-id>" format
28+
*
29+
* @param Field $field
30+
* @param ContextInterface $context
31+
* @param ResolveInfo $info
32+
* @param array|null $value
33+
* @param array|null $args
34+
*
35+
* @return string
36+
*
37+
* @throws GraphQlInputException
38+
*
39+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
40+
*/
41+
public function resolve(
42+
Field $field,
43+
$context,
44+
ResolveInfo $info,
45+
array $value = null,
46+
array $args = null
47+
) {
48+
if (!isset($value['option_id']) || empty($value['option_id'])) {
49+
throw new GraphQlInputException(__('"option_id" value should be specified.'));
50+
}
51+
52+
$optionDetails = [
53+
self::OPTION_TYPE,
54+
$value['option_id']
55+
];
56+
57+
$content = implode('/', $optionDetails);
58+
59+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
60+
return base64_encode($content);
61+
}
62+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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\Exception\GraphQlInputException;
12+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
13+
use Magento\Framework\GraphQl\Query\ResolverInterface;
14+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
16+
/**
17+
* Format new option uid in base64 encode for selected custom options
18+
*/
19+
class CustomizableSelectedOptionValueUid implements ResolverInterface
20+
{
21+
/**
22+
* Option type name
23+
*/
24+
private const OPTION_TYPE = 'custom-option';
25+
26+
/**
27+
* Create a option uid for selected option in "<option-type>/<option-id>/<option-value-id>" format
28+
*
29+
* @param Field $field
30+
* @param ContextInterface $context
31+
* @param ResolveInfo $info
32+
* @param array|null $value
33+
* @param array|null $args
34+
*
35+
* @return string
36+
*
37+
* @throws GraphQlInputException
38+
*
39+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
40+
*/
41+
public function resolve(
42+
Field $field,
43+
$context,
44+
ResolveInfo $info,
45+
array $value = null,
46+
array $args = null
47+
) {
48+
if (!isset($value['option_id']) || empty($value['option_id'])) {
49+
throw new GraphQlInputException(__('"option_id" value should be specified.'));
50+
}
51+
52+
if (!isset($value['option_type_id']) || empty($value['option_type_id'])) {
53+
throw new GraphQlInputException(__('"option_type_id" value should be specified.'));
54+
}
55+
56+
$optionDetails = [
57+
self::OPTION_TYPE,
58+
$value['option_id'],
59+
$value['option_type_id']
60+
];
61+
62+
$content = implode('/', $optionDetails);
63+
64+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
65+
return base64_encode($content);
66+
}
67+
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ type CustomizableAreaValue @doc(description: "CustomizableAreaValue defines the
132132
price_type: PriceTypeEnum @doc(description: "FIXED, PERCENT, or DYNAMIC.")
133133
sku: String @doc(description: "The Stock Keeping Unit for this option.")
134134
max_characters: Int @doc(description: "The maximum number of characters that can be entered for this customizable option.")
135+
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.
135136
}
136137

137138
type CategoryTree implements CategoryInterface @doc(description: "Category Tree implementation.") {
@@ -153,6 +154,7 @@ type CustomizableDateValue @doc(description: "CustomizableDateValue defines the
153154
price: Float @doc(description: "The price assigned to this option.")
154155
price_type: PriceTypeEnum @doc(description: "FIXED, PERCENT, or DYNAMIC.")
155156
sku: String @doc(description: "The Stock Keeping Unit for this option.")
157+
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.
156158
}
157159

158160
type CustomizableDropDownOption implements CustomizableOptionInterface @doc(description: "CustomizableDropDownOption contains information about a drop down menu that is defined as part of a customizable option.") {
@@ -166,6 +168,7 @@ type CustomizableDropDownValue @doc(description: "CustomizableDropDownValue defi
166168
sku: String @doc(description: "The Stock Keeping Unit for this option.")
167169
title: String @doc(description: "The display name for this option.")
168170
sort_order: Int @doc(description: "The order in which the option is displayed.")
171+
uid: ID! @doc(description: "A string that encodes option details.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableSelectedOptionValueUid") # A Base64 string that encodes option details.
169172
}
170173

171174
type CustomizableMultipleOption implements CustomizableOptionInterface @doc(description: "CustomizableMultipleOption contains information about a multiselect that is defined as part of a customizable option.") {
@@ -179,6 +182,7 @@ type CustomizableMultipleValue @doc(description: "CustomizableMultipleValue defi
179182
sku: String @doc(description: "The Stock Keeping Unit for this option.")
180183
title: String @doc(description: "The display name for this option.")
181184
sort_order: Int @doc(description: "The order in which the option is displayed.")
185+
uid: ID! @doc(description: "A string that encodes option details.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableSelectedOptionValueUid")
182186
}
183187

184188
type CustomizableFieldOption implements CustomizableOptionInterface @doc(description: "CustomizableFieldOption contains information about a text field that is defined as part of a customizable option.") {
@@ -191,6 +195,7 @@ type CustomizableFieldValue @doc(description: "CustomizableFieldValue defines th
191195
price_type: PriceTypeEnum @doc(description: "FIXED, PERCENT, or DYNAMIC.")
192196
sku: String @doc(description: "The Stock Keeping Unit for this option.")
193197
max_characters: Int @doc(description: "The maximum number of characters that can be entered for this customizable option.")
198+
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.
194199
}
195200

196201
type CustomizableFileOption implements CustomizableOptionInterface @doc(description: "CustomizableFileOption contains information about a file picker that is defined as part of a customizable option.") {
@@ -205,6 +210,7 @@ type CustomizableFileValue @doc(description: "CustomizableFileValue defines the
205210
file_extension: String @doc(description: "The file extension to accept.")
206211
image_size_x: Int @doc(description: "The maximum width of an image.")
207212
image_size_y: Int @doc(description: "The maximum height of an image.")
213+
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.
208214
}
209215

210216
interface MediaGalleryInterface @doc(description: "Contains basic information about a product image or video.") @typeResolver(class: "Magento\\CatalogGraphQl\\Model\\MediaGalleryTypeResolver") {
@@ -274,6 +280,7 @@ type CustomizableRadioValue @doc(description: "CustomizableRadioValue defines th
274280
sku: String @doc(description: "The Stock Keeping Unit for this option.")
275281
title: String @doc(description: "The display name for this option.")
276282
sort_order: Int @doc(description: "The order in which the radio button is displayed.")
283+
uid: ID! @doc(description: "A string that encodes option details.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableSelectedOptionValueUid") # A Base64 string that encodes option details.
277284
}
278285

279286
type CustomizableCheckboxOption implements CustomizableOptionInterface @doc(description: "CustomizableCheckbbixOption contains information about a set of checkbox values that are defined as part of a customizable option.") {
@@ -287,6 +294,7 @@ type CustomizableCheckboxValue @doc(description: "CustomizableCheckboxValue defi
287294
sku: String @doc(description: "The Stock Keeping Unit for this option.")
288295
title: String @doc(description: "The display name for this option.")
289296
sort_order: Int @doc(description: "The order in which the checkbox value is displayed.")
297+
uid: ID! @doc(description: "A string that encodes option details.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableSelectedOptionValueUid") # A Base64 string that encodes option details.
290298
}
291299

292300
type VirtualProduct implements ProductInterface, CustomizableProductInterface @doc(description: "A virtual product is non-tangible product that does not require shipping and is not kept in inventory.") {

app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public function resolve(
6060
$option['options_map'] ?? [],
6161
$code,
6262
(int) $optionId,
63-
(int) $model->getData($code)
63+
(int) $model->getData($code),
64+
(int) $option['attribute_id']
6465
);
6566
if (!empty($optionsFromMap)) {
6667
$data[] = $optionsFromMap;
@@ -77,14 +78,20 @@ public function resolve(
7778
* @param string $code
7879
* @param int $optionId
7980
* @param int $attributeCodeId
81+
* @param int $attributeId
8082
* @return array
8183
*/
82-
private function getOptionsFromMap(array $optionMap, string $code, int $optionId, int $attributeCodeId): array
83-
{
84+
private function getOptionsFromMap(
85+
array $optionMap,
86+
string $code,
87+
int $optionId,
88+
int $attributeCodeId,
89+
int $attributeId
90+
): array {
8491
$data = [];
8592
if (isset($optionMap[$optionId . ':' . $attributeCodeId])) {
8693
$optionValue = $optionMap[$optionId . ':' . $attributeCodeId];
87-
$data = $this->getOptionsArray($optionValue, $code);
94+
$data = $this->getOptionsArray($optionValue, $code, $attributeId);
8895
}
8996
return $data;
9097
}
@@ -94,15 +101,17 @@ private function getOptionsFromMap(array $optionMap, string $code, int $optionId
94101
*
95102
* @param array $optionValue
96103
* @param string $code
104+
* @param int $attributeId
97105
* @return array
98106
*/
99-
private function getOptionsArray(array $optionValue, string $code): array
107+
private function getOptionsArray(array $optionValue, string $code, int $attributeId): array
100108
{
101109
return [
102110
'label' => $optionValue['label'] ?? null,
103111
'code' => $code,
104112
'use_default_value' => $optionValue['use_default_value'] ?? null,
105113
'value_index' => $optionValue['value_index'] ?? null,
114+
'attribute_id' => $attributeId,
106115
];
107116
}
108117
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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\ConfigurableProductGraphQl\Model\Resolver\Variant\Attributes;
9+
10+
use Magento\Framework\GraphQl\Config\Element\Field;
11+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
12+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
13+
use Magento\Framework\GraphQl\Query\ResolverInterface;
14+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
16+
/**
17+
* Format new option uid in base64 encode for super attribute options
18+
*/
19+
class ConfigurableAttributeUid implements ResolverInterface
20+
{
21+
/**
22+
* Option type name
23+
*/
24+
private const OPTION_TYPE = 'configurable';
25+
26+
/**
27+
* Create a option uid for super attribute in "<option-type>/<attribute-id>/<value-index>" format
28+
*
29+
* @param Field $field
30+
* @param ContextInterface $context
31+
* @param ResolveInfo $info
32+
* @param array|null $value
33+
* @param array|null $args
34+
*
35+
* @return string
36+
*
37+
* @throws GraphQlInputException
38+
*
39+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
40+
*/
41+
public function resolve(
42+
Field $field,
43+
$context,
44+
ResolveInfo $info,
45+
array $value = null,
46+
array $args = null
47+
) {
48+
if (!isset($value['attribute_id']) || empty($value['attribute_id'])) {
49+
throw new GraphQlInputException(__('"attribute_id" value should be specified.'));
50+
}
51+
52+
if (!isset($value['value_index']) || empty($value['value_index'])) {
53+
throw new GraphQlInputException(__('"value_index" value should be specified.'));
54+
}
55+
56+
$optionDetails = [
57+
self::OPTION_TYPE,
58+
$value['attribute_id'],
59+
$value['value_index']
60+
];
61+
62+
$content = implode('/', $optionDetails);
63+
64+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
65+
return base64_encode($content);
66+
}
67+
}

0 commit comments

Comments
 (0)