Skip to content

Commit f990c5d

Browse files
committed
Small improvements and API Test coveragefor uid
1 parent 54625d9 commit f990c5d

File tree

14 files changed

+437
-116
lines changed

14 files changed

+437
-116
lines changed

app/code/Magento/BundleGraphQl/Model/Resolver/Options/BundleEnteredOptionValueIdV2.php renamed to app/code/Magento/BundleGraphQl/Model/Resolver/Options/BundleItemOptionUid.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1515

1616
/**
17-
* Format new option id_v2 in base64 encode for entered bundle options
17+
* Format new option uid in base64 encode for entered bundle options
1818
*/
19-
class BundleEnteredOptionValueIdV2 implements ResolverInterface
19+
class BundleItemOptionUid implements ResolverInterface
2020
{
2121
/**
2222
* Option type name
2323
*/
2424
private const OPTION_TYPE = 'bundle';
2525

2626
/**
27-
* Create a option id_v2 for entered option in "<option-type>/<option-id>/<option-value-id>/<quantity>" format
27+
* Create a option uid for entered option in "<option-type>/<option-id>/<option-value-id>/<quantity>" format
2828
*
2929
* @param Field $field
3030
* @param ContextInterface $context
@@ -46,11 +46,11 @@ public function resolve(
4646
array $args = null
4747
) {
4848
if (!isset($value['option_id']) || empty($value['option_id'])) {
49-
throw new GraphQlInputException(__('Wrong format option data: option_id should not be empty.'));
49+
throw new GraphQlInputException(__('"option_id" value should be specified.'));
5050
}
5151

5252
if (!isset($value['selection_id']) || empty($value['selection_id'])) {
53-
throw new GraphQlInputException(__('Wrong format option data: selection_id should not be empty.'));
53+
throw new GraphQlInputException(__('"selection_id" value should be specified.'));
5454
}
5555

5656
$optionDetails = [

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +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-
id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\BundleGraphQl\\Model\\Resolver\\Options\\BundleEnteredOptionValueIdV2")
69+
uid: ID @doc(description: "An encoded string that encodes option details.") @resolver(class: "Magento\\BundleGraphQl\\Model\\Resolver\\Options\\BundleItemOptionUid") # A Base64 string that encodes option details.
7070
}
7171

7272
type BundleProduct implements ProductInterface, PhysicalProductInterface, CustomizableProductInterface @doc(description: "BundleProduct defines basic features of a bundle product and contains multiple BundleItems.") {

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableEnteredOptionValueIdV2.php renamed to app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableEnteredOptionValueUid.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1515

1616
/**
17-
* Format new option id_v2 in base64 encode for entered custom options
17+
* Format new option uid in base64 encode for entered custom options
1818
*/
19-
class CustomizableEnteredOptionValueIdV2 implements ResolverInterface
19+
class CustomizableEnteredOptionValueUid implements ResolverInterface
2020
{
2121
/**
2222
* Option type name
2323
*/
2424
private const OPTION_TYPE = 'custom-option';
2525

2626
/**
27-
* Create a option id_v2 for entered option in "<option-type>/<option-id>" format
27+
* Create a option uid for entered option in "<option-type>/<option-id>" format
2828
*
2929
* @param Field $field
3030
* @param ContextInterface $context
@@ -46,7 +46,7 @@ public function resolve(
4646
array $args = null
4747
) {
4848
if (!isset($value['option_id']) || empty($value['option_id'])) {
49-
throw new GraphQlInputException(__('Wrong format option data: option_id should not be empty.'));
49+
throw new GraphQlInputException(__('"option_id" value should be specified.'));
5050
}
5151

5252
$optionDetails = [

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableSelectedOptionValueIdV2.php renamed to app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableSelectedOptionValueUid.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1515

1616
/**
17-
* Format new option id_v2 in base64 encode for selected custom options
17+
* Format new option uid in base64 encode for selected custom options
1818
*/
19-
class CustomizableSelectedOptionValueIdV2 implements ResolverInterface
19+
class CustomizableSelectedOptionValueUid implements ResolverInterface
2020
{
2121
/**
2222
* Option type name
2323
*/
2424
private const OPTION_TYPE = 'custom-option';
2525

2626
/**
27-
* Create a option id_v2 for selected option in "<option-type>/<option-id>/<option-value-id>" format
27+
* Create a option uid for selected option in "<option-type>/<option-id>/<option-value-id>" format
2828
*
2929
* @param Field $field
3030
* @param ContextInterface $context
@@ -46,11 +46,11 @@ public function resolve(
4646
array $args = null
4747
) {
4848
if (!isset($value['option_id']) || empty($value['option_id'])) {
49-
throw new GraphQlInputException(__('Wrong format option data: option_id should not be empty.'));
49+
throw new GraphQlInputException(__('"option_id" value should be specified.'));
5050
}
5151

5252
if (!isset($value['option_type_id']) || empty($value['option_type_id'])) {
53-
throw new GraphQlInputException(__('Wrong format option data: option_type_id should not be empty.'));
53+
throw new GraphQlInputException(__('"option_type_id" value should be specified.'));
5454
}
5555

5656
$optionDetails = [

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +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-
id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueIdV2")
135+
uid: ID @doc(description: "An encoded string that encodes option details.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueUid") # A Base64 string that encodes option details.
136136
}
137137

138138
type CategoryTree implements CategoryInterface @doc(description: "Category Tree implementation.") {
@@ -154,7 +154,7 @@ type CustomizableDateValue @doc(description: "CustomizableDateValue defines the
154154
price: Float @doc(description: "The price assigned to this option.")
155155
price_type: PriceTypeEnum @doc(description: "FIXED, PERCENT, or DYNAMIC.")
156156
sku: String @doc(description: "The Stock Keeping Unit for this option.")
157-
id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueIdV2")
157+
uid: ID @doc(description: "An encoded string that encodes option details.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueUid") # A Base64 string that encodes option details.
158158
}
159159

160160
type CustomizableDropDownOption implements CustomizableOptionInterface @doc(description: "CustomizableDropDownOption contains information about a drop down menu that is defined as part of a customizable option.") {
@@ -168,7 +168,7 @@ type CustomizableDropDownValue @doc(description: "CustomizableDropDownValue defi
168168
sku: String @doc(description: "The Stock Keeping Unit for this option.")
169169
title: String @doc(description: "The display name for this option.")
170170
sort_order: Int @doc(description: "The order in which the option is displayed.")
171-
id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableSelectedOptionValueIdV2")
171+
uid: ID @doc(description: "An encoded string that encodes option details.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableSelectedOptionValueUid") # A Base64 string that encodes option details.
172172
}
173173

174174
type CustomizableMultipleOption implements CustomizableOptionInterface @doc(description: "CustomizableMultipleOption contains information about a multiselect that is defined as part of a customizable option.") {
@@ -182,7 +182,7 @@ type CustomizableMultipleValue @doc(description: "CustomizableMultipleValue defi
182182
sku: String @doc(description: "The Stock Keeping Unit for this option.")
183183
title: String @doc(description: "The display name for this option.")
184184
sort_order: Int @doc(description: "The order in which the option is displayed.")
185-
id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableSelectedOptionValueIdV2")
185+
uid: ID @doc(description: "An encoded string that encodes option details.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableSelectedOptionValueUid")
186186
}
187187

188188
type CustomizableFieldOption implements CustomizableOptionInterface @doc(description: "CustomizableFieldOption contains information about a text field that is defined as part of a customizable option.") {
@@ -195,7 +195,7 @@ type CustomizableFieldValue @doc(description: "CustomizableFieldValue defines th
195195
price_type: PriceTypeEnum @doc(description: "FIXED, PERCENT, or DYNAMIC.")
196196
sku: String @doc(description: "The Stock Keeping Unit for this option.")
197197
max_characters: Int @doc(description: "The maximum number of characters that can be entered for this customizable option.")
198-
id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueIdV2")
198+
uid: ID @doc(description: "An encoded string that encodes option details.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueUid") # A Base64 string that encodes option details.
199199
}
200200

201201
type CustomizableFileOption implements CustomizableOptionInterface @doc(description: "CustomizableFileOption contains information about a file picker that is defined as part of a customizable option.") {
@@ -210,7 +210,7 @@ type CustomizableFileValue @doc(description: "CustomizableFileValue defines the
210210
file_extension: String @doc(description: "The file extension to accept.")
211211
image_size_x: Int @doc(description: "The maximum width of an image.")
212212
image_size_y: Int @doc(description: "The maximum height of an image.")
213-
id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueIdV2")
213+
uid: ID @doc(description: "An encoded string that encodes option details.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueUid") # A Base64 string that encodes option details.
214214
}
215215

216216
interface MediaGalleryInterface @doc(description: "Contains basic information about a product image or video.") @typeResolver(class: "Magento\\CatalogGraphQl\\Model\\MediaGalleryTypeResolver") {
@@ -280,7 +280,7 @@ type CustomizableRadioValue @doc(description: "CustomizableRadioValue defines th
280280
sku: String @doc(description: "The Stock Keeping Unit for this option.")
281281
title: String @doc(description: "The display name for this option.")
282282
sort_order: Int @doc(description: "The order in which the radio button is displayed.")
283-
id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableSelectedOptionValueIdV2")
283+
uid: ID @doc(description: "An encoded string that encodes option details.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableSelectedOptionValueUid") # A Base64 string that encodes option details.
284284
}
285285

286286
type CustomizableCheckboxOption implements CustomizableOptionInterface @doc(description: "CustomizableCheckbbixOption contains information about a set of checkbox values that are defined as part of a customizable option.") {
@@ -294,7 +294,7 @@ type CustomizableCheckboxValue @doc(description: "CustomizableCheckboxValue defi
294294
sku: String @doc(description: "The Stock Keeping Unit for this option.")
295295
title: String @doc(description: "The display name for this option.")
296296
sort_order: Int @doc(description: "The order in which the checkbox value is displayed.")
297-
id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableSelectedOptionValueIdV2")
297+
uid: ID @doc(description: "An encoded string that encodes option details.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableSelectedOptionValueUid") # A Base64 string that encodes option details.
298298
}
299299

300300
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
}

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

Lines changed: 0 additions & 83 deletions
This file was deleted.
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)