diff --git a/app/code/Magento/BundleGraphQl/Model/Resolver/Options/BundleEnteredOptionValueIdV2.php b/app/code/Magento/BundleGraphQl/Model/Resolver/Options/BundleEnteredOptionValueIdV2.php new file mode 100644 index 0000000000000..c1a55d9db794a --- /dev/null +++ b/app/code/Magento/BundleGraphQl/Model/Resolver/Options/BundleEnteredOptionValueIdV2.php @@ -0,0 +1,68 @@ +///" format + * + * @param Field $field + * @param ContextInterface $context + * @param ResolveInfo $info + * @param array|null $value + * @param array|null $args + * + * @return string + * + * @throws GraphQlInputException + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function resolve( + Field $field, + $context, + ResolveInfo $info, + array $value = null, + array $args = null + ) { + if (!isset($value['option_id']) || empty($value['option_id'])) { + throw new GraphQlInputException(__('Wrong format option data: option_id should not be empty.')); + } + + if (!isset($value['selection_id']) || empty($value['selection_id'])) { + throw new GraphQlInputException(__('Wrong format option data: selection_id should not be empty.')); + } + + $optionDetails = [ + self::OPTION_TYPE, + $value['option_id'], + $value['selection_id'], + (int) $value['selection_qty'] + ]; + + $content = implode('/', $optionDetails); + + // phpcs:ignore Magento2.Functions.DiscouragedFunction + return base64_encode($content); + } +} diff --git a/app/code/Magento/BundleGraphQl/etc/schema.graphqls b/app/code/Magento/BundleGraphQl/etc/schema.graphqls index 0eff0e086180e..bab1a256f7f59 100644 --- a/app/code/Magento/BundleGraphQl/etc/schema.graphqls +++ b/app/code/Magento/BundleGraphQl/etc/schema.graphqls @@ -66,6 +66,7 @@ type BundleItemOption @doc(description: "BundleItemOption defines characteristic price_type: PriceTypeEnum @doc(description: "One of FIXED, PERCENT, or DYNAMIC.") can_change_quantity: Boolean @doc(description: "Indicates whether the customer can change the number of items for this option.") product: ProductInterface @doc(description: "Contains details about this product option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product") + id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\BundleGraphQl\\Model\\Resolver\\Options\\BundleEnteredOptionValueIdV2") } type BundleProduct implements ProductInterface, PhysicalProductInterface, CustomizableProductInterface @doc(description: "BundleProduct defines basic features of a bundle product and contains multiple BundleItems.") { diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableEnteredOptionValueIdV2.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableEnteredOptionValueIdV2.php new file mode 100644 index 0000000000000..efc15d5d92ca3 --- /dev/null +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableEnteredOptionValueIdV2.php @@ -0,0 +1,62 @@ +/" format + * + * @param Field $field + * @param ContextInterface $context + * @param ResolveInfo $info + * @param array|null $value + * @param array|null $args + * + * @return string + * + * @throws GraphQlInputException + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function resolve( + Field $field, + $context, + ResolveInfo $info, + array $value = null, + array $args = null + ) { + if (!isset($value['option_id']) || empty($value['option_id'])) { + throw new GraphQlInputException(__('Wrong format option data: option_id should not be empty.')); + } + + $optionDetails = [ + self::OPTION_TYPE, + $value['option_id'] + ]; + + $content = implode('/', $optionDetails); + + // phpcs:ignore Magento2.Functions.DiscouragedFunction + return base64_encode($content); + } +} diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableOptionValueIdV2.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableSelectedOptionValueIdV2.php similarity index 62% rename from app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableOptionValueIdV2.php rename to app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableSelectedOptionValueIdV2.php index 67ca953702716..f1dff2680ba93 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableOptionValueIdV2.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Product/CustomizableSelectedOptionValueIdV2.php @@ -7,34 +7,36 @@ namespace Magento\CatalogGraphQl\Model\Resolver\Product; -use Magento\Framework\Exception\LocalizedException; use Magento\Framework\GraphQl\Config\Element\Field; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; -use Magento\Framework\GraphQl\Query\Resolver\Value; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; /** - * @inheritdoc - * - * Format new option id_v2 in base64 encode for custom options + * Format new option id_v2 in base64 encode for selected custom options */ -class CustomizableOptionValueIdV2 implements ResolverInterface +class CustomizableSelectedOptionValueIdV2 implements ResolverInterface { + /** + * Option type name + */ private const OPTION_TYPE = 'custom-option'; /** - * @inheritdoc - * - * Create new option id_v2 that encodes details for each option and in most cases can be presented - * as base64("//") + * Create a option id_v2 for selected option in "//" format * * @param Field $field * @param ContextInterface $context * @param ResolveInfo $info * @param array|null $value * @param array|null $args - * @return Value|mixed|void + * + * @return string + * + * @throws GraphQlInputException + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function resolve( Field $field, @@ -43,23 +45,23 @@ public function resolve( array $value = null, array $args = null ) { + if (!isset($value['option_id']) || empty($value['option_id'])) { + throw new GraphQlInputException(__('Wrong format option data: option_id should not be empty.')); + } + + if (!isset($value['option_type_id']) || empty($value['option_type_id'])) { + throw new GraphQlInputException(__('Wrong format option data: option_type_id should not be empty.')); + } + $optionDetails = [ self::OPTION_TYPE, $value['option_id'], $value['option_type_id'] ]; - if (!isset($value['option_id']) || empty($value['option_id'])) { - throw new LocalizedException(__('Wrong format option data: option_id should not be empty.')); - } - - if (!isset($value['option_type_id']) || empty($value['option_type_id'])) { - throw new LocalizedException(__('Wrong format option data: option_type_id should not be empty.')); - } + $content = implode('/', $optionDetails); // phpcs:ignore Magento2.Functions.DiscouragedFunction - $content = \implode('/', $optionDetails); - return base64_encode($content); } } diff --git a/app/code/Magento/CatalogGraphQl/etc/schema.graphqls b/app/code/Magento/CatalogGraphQl/etc/schema.graphqls index 51fedcbfb6c49..008ed729350cd 100644 --- a/app/code/Magento/CatalogGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CatalogGraphQl/etc/schema.graphqls @@ -132,7 +132,7 @@ type CustomizableAreaValue @doc(description: "CustomizableAreaValue defines the price_type: PriceTypeEnum @doc(description: "FIXED, PERCENT, or DYNAMIC.") sku: String @doc(description: "The Stock Keeping Unit for this option.") max_characters: Int @doc(description: "The maximum number of characters that can be entered for this customizable option.") - id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableOptionValueIdV2") + id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueIdV2") } type CategoryTree implements CategoryInterface @doc(description: "Category Tree implementation.") { @@ -154,7 +154,7 @@ type CustomizableDateValue @doc(description: "CustomizableDateValue defines the price: Float @doc(description: "The price assigned to this option.") price_type: PriceTypeEnum @doc(description: "FIXED, PERCENT, or DYNAMIC.") sku: String @doc(description: "The Stock Keeping Unit for this option.") - id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableOptionValueIdV2") + id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueIdV2") } 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 sku: String @doc(description: "The Stock Keeping Unit for this option.") title: String @doc(description: "The display name for this option.") sort_order: Int @doc(description: "The order in which the option is displayed.") - id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableOptionValueIdV2") + id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableSelectedOptionValueIdV2") } 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 sku: String @doc(description: "The Stock Keeping Unit for this option.") title: String @doc(description: "The display name for this option.") sort_order: Int @doc(description: "The order in which the option is displayed.") - id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableOptionValueIdV2") + id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableSelectedOptionValueIdV2") } 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 price_type: PriceTypeEnum @doc(description: "FIXED, PERCENT, or DYNAMIC.") sku: String @doc(description: "The Stock Keeping Unit for this option.") max_characters: Int @doc(description: "The maximum number of characters that can be entered for this customizable option.") - id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableOptionValueIdV2") + id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueIdV2") } 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 file_extension: String @doc(description: "The file extension to accept.") image_size_x: Int @doc(description: "The maximum width of an image.") image_size_y: Int @doc(description: "The maximum height of an image.") - id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableOptionValueIdV2") + id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueIdV2") } 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 sku: String @doc(description: "The Stock Keeping Unit for this option.") title: String @doc(description: "The display name for this option.") sort_order: Int @doc(description: "The order in which the radio button is displayed.") - id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableOptionValueIdV2") + id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableSelectedOptionValueIdV2") } 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 sku: String @doc(description: "The Stock Keeping Unit for this option.") title: String @doc(description: "The display name for this option.") sort_order: Int @doc(description: "The order in which the checkbox value is displayed.") - id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableOptionValueIdV2") + id_v2: String @doc(description: "Base64 string, that encodes details for each option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableSelectedOptionValueIdV2") } 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.") { diff --git a/app/code/Magento/DownloadableGraphQl/Resolver/Product/DownloadableLinksValueIdV2.php b/app/code/Magento/DownloadableGraphQl/Resolver/Product/DownloadableLinksValueIdV2.php new file mode 100644 index 0000000000000..62da0ba8530fc --- /dev/null +++ b/app/code/Magento/DownloadableGraphQl/Resolver/Product/DownloadableLinksValueIdV2.php @@ -0,0 +1,46 @@ +