Skip to content

Commit

Permalink
ENGCOM-7608: #257: create new id_v2 option #28210
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhuram93 authored Jul 15, 2020
2 parents 1d8a6d7 + d9a67c5 commit d1cdced
Show file tree
Hide file tree
Showing 13 changed files with 663 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\BundleGraphQl\Model\Resolver\Options;

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\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

/**
* Format new option uid in base64 encode for entered bundle options
*/
class BundleItemOptionUid implements ResolverInterface
{
/**
* Option type name
*/
private const OPTION_TYPE = 'bundle';

/**
* Create a option uid for entered option in "<option-type>/<option-id>/<option-value-id>/<quantity>" 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(__('"option_id" value should be specified.'));
}

if (!isset($value['selection_id']) || empty($value['selection_id'])) {
throw new GraphQlInputException(__('"selection_id" value should be specified.'));
}

$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);
}
}
1 change: 1 addition & 0 deletions app/code/Magento/BundleGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -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")
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.
}

type BundleProduct implements ProductInterface, PhysicalProductInterface, CustomizableProductInterface @doc(description: "BundleProduct defines basic features of a bundle product and contains multiple BundleItems.") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogGraphQl\Model\Resolver\Product;

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\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

/**
* Format new option uid in base64 encode for entered custom options
*/
class CustomizableEnteredOptionValueUid implements ResolverInterface
{
/**
* Option type name
*/
private const OPTION_TYPE = 'custom-option';

/**
* Create a option uid for entered option in "<option-type>/<option-id>" 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(__('"option_id" value should be specified.'));
}

$optionDetails = [
self::OPTION_TYPE,
$value['option_id']
];

$content = implode('/', $optionDetails);

// phpcs:ignore Magento2.Functions.DiscouragedFunction
return base64_encode($content);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogGraphQl\Model\Resolver\Product;

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\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

/**
* Format new option uid in base64 encode for selected custom options
*/
class CustomizableSelectedOptionValueUid implements ResolverInterface
{
/**
* Option type name
*/
private const OPTION_TYPE = 'custom-option';

/**
* Create a option uid for selected option in "<option-type>/<option-id>/<option-value-id>" 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(__('"option_id" value should be specified.'));
}

if (!isset($value['option_type_id']) || empty($value['option_type_id'])) {
throw new GraphQlInputException(__('"option_type_id" value should be specified.'));
}

$optionDetails = [
self::OPTION_TYPE,
$value['option_id'],
$value['option_type_id']
];

$content = implode('/', $optionDetails);

// phpcs:ignore Magento2.Functions.DiscouragedFunction
return base64_encode($content);
}
}
8 changes: 8 additions & 0 deletions app/code/Magento/CatalogGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +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.")
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.
}

type CategoryTree implements CategoryInterface @doc(description: "Category Tree implementation.") {
Expand All @@ -153,6 +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.")
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.
}

type CustomizableDropDownOption implements CustomizableOptionInterface @doc(description: "CustomizableDropDownOption contains information about a drop down menu that is defined as part of a customizable option.") {
Expand All @@ -166,6 +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.")
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.
}

type CustomizableMultipleOption implements CustomizableOptionInterface @doc(description: "CustomizableMultipleOption contains information about a multiselect that is defined as part of a customizable option.") {
Expand All @@ -179,6 +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.")
uid: ID! @doc(description: "A string that encodes option details.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableSelectedOptionValueUid")
}

type CustomizableFieldOption implements CustomizableOptionInterface @doc(description: "CustomizableFieldOption contains information about a text field that is defined as part of a customizable option.") {
Expand All @@ -191,6 +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.")
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.
}

type CustomizableFileOption implements CustomizableOptionInterface @doc(description: "CustomizableFileOption contains information about a file picker that is defined as part of a customizable option.") {
Expand All @@ -205,6 +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.")
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.
}

interface MediaGalleryInterface @doc(description: "Contains basic information about a product image or video.") @typeResolver(class: "Magento\\CatalogGraphQl\\Model\\MediaGalleryTypeResolver") {
Expand Down Expand Up @@ -274,6 +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.")
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.
}

type CustomizableCheckboxOption implements CustomizableOptionInterface @doc(description: "CustomizableCheckbbixOption contains information about a set of checkbox values that are defined as part of a customizable option.") {
Expand All @@ -287,6 +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.")
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.
}

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.") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public function resolve(
$option['options_map'] ?? [],
$code,
(int) $optionId,
(int) $model->getData($code)
(int) $model->getData($code),
(int) $option['attribute_id']
);
if (!empty($optionsFromMap)) {
$data[] = $optionsFromMap;
Expand All @@ -77,14 +78,20 @@ public function resolve(
* @param string $code
* @param int $optionId
* @param int $attributeCodeId
* @param int $attributeId
* @return array
*/
private function getOptionsFromMap(array $optionMap, string $code, int $optionId, int $attributeCodeId): array
{
private function getOptionsFromMap(
array $optionMap,
string $code,
int $optionId,
int $attributeCodeId,
int $attributeId
): array {
$data = [];
if (isset($optionMap[$optionId . ':' . $attributeCodeId])) {
$optionValue = $optionMap[$optionId . ':' . $attributeCodeId];
$data = $this->getOptionsArray($optionValue, $code);
$data = $this->getOptionsArray($optionValue, $code, $attributeId);
}
return $data;
}
Expand All @@ -94,15 +101,17 @@ private function getOptionsFromMap(array $optionMap, string $code, int $optionId
*
* @param array $optionValue
* @param string $code
* @param int $attributeId
* @return array
*/
private function getOptionsArray(array $optionValue, string $code): array
private function getOptionsArray(array $optionValue, string $code, int $attributeId): array
{
return [
'label' => $optionValue['label'] ?? null,
'code' => $code,
'use_default_value' => $optionValue['use_default_value'] ?? null,
'value_index' => $optionValue['value_index'] ?? null,
'attribute_id' => $attributeId,
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProductGraphQl\Model\Resolver\Variant\Attributes;

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\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

/**
* Format new option uid in base64 encode for super attribute options
*/
class ConfigurableAttributeUid implements ResolverInterface
{
/**
* Option type name
*/
private const OPTION_TYPE = 'configurable';

/**
* Create a option uid for super attribute in "<option-type>/<attribute-id>/<value-index>" 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['attribute_id']) || empty($value['attribute_id'])) {
throw new GraphQlInputException(__('"attribute_id" value should be specified.'));
}

if (!isset($value['value_index']) || empty($value['value_index'])) {
throw new GraphQlInputException(__('"value_index" value should be specified.'));
}

$optionDetails = [
self::OPTION_TYPE,
$value['attribute_id'],
$value['value_index']
];

$content = implode('/', $optionDetails);

// phpcs:ignore Magento2.Functions.DiscouragedFunction
return base64_encode($content);
}
}
Loading

0 comments on commit d1cdced

Please sign in to comment.