Skip to content

Commit 28d3102

Browse files
author
Eric Bohanon
committed
MAGETWO-87147: Add customizable option type resolver implementation
- Refactor existing type resolver implementations
1 parent 2226341 commit 28d3102

File tree

18 files changed

+176
-34
lines changed

18 files changed

+176
-34
lines changed

app/code/Magento/BundleGraphQl/Model/BundleProductTypeResolver.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace Magento\BundleGraphQl\Model;
88

99
use Magento\Framework\GraphQl\Config\Data\TypeResolverInterface;
10-
use Magento\Framework\Exception\InputException;
1110

1211
/**
1312
* {@inheritdoc}

app/code/Magento/BundleGraphQl/etc/di.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,13 @@
1616
</argument>
1717
</arguments>
1818
</type>
19+
<type name="Magento\Framework\GraphQl\Type\Entity\DefaultMapper">
20+
<arguments>
21+
<argument name="map" xsi:type="array">
22+
<item name="catalog_product" xsi:type="array">
23+
<item name="bundle" xsi:type="string">BundleProduct</item>
24+
</item>
25+
</argument>
26+
</arguments>
27+
</type>
1928
</config>

app/code/Magento/BundleGraphQl/etc/graphql.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,4 @@
4545
<item name="price_range">PRICE_RANGE</item>
4646
<item name="as_low_as">AS_LOW_AS</item>
4747
</type>
48-
<type xsi:type="Enum" name="PriceTypeEnum">
49-
<item name="fixed">FIXED</item>
50-
<item name="percent">PERCENT</item>
51-
<item name="dynamic">DYNAMIC</item>
52-
</type>
5348
</config>

app/code/Magento/CatalogGraphQl/Model/CatalogProductTypeResolver.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace Magento\CatalogGraphQl\Model;
88

99
use Magento\Framework\GraphQl\Config\Data\TypeResolverInterface;
10-
use Magento\Framework\Exception\InputException;
1110

1211
/**
1312
* {@inheritdoc}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogGraphQl\Model;
8+
9+
use Magento\Framework\GraphQl\Config\Data\TypeResolverInterface;
10+
use Magento\Framework\GraphQl\Type\Entity\MapperInterface;
11+
12+
/**
13+
* Class CustomizableOptionTypeResolver
14+
*/
15+
class CustomizableOptionTypeResolver implements TypeResolverInterface
16+
{
17+
const ENTITY_TYPE = 'customizable_options';
18+
19+
/**
20+
* @var MapperInterface
21+
*/
22+
private $mapper;
23+
24+
/**
25+
* {@inheritDoc}
26+
*/
27+
public function resolveType(array $data)
28+
{
29+
$map = $this->mapper->getMappedTypes(self::ENTITY_TYPE);
30+
if (!isset($map[$data['type']]) || !isset($map[$data['type']])) {
31+
return null;
32+
}
33+
34+
return $map[$data['type']];
35+
}
36+
}

app/code/Magento/CatalogGraphQl/Model/ProductInterfaceTypeResolverComposite.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Magento\CatalogGraphQl\Model;
88

99
use Magento\Framework\GraphQl\Config\Data\TypeResolverInterface;
10-
use Magento\Framework\Exception\InputException;
10+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1111

1212
/**
1313
* {@inheritdoc}
@@ -29,14 +29,15 @@ public function __construct(array $productTypeNameResolvers = [])
2929

3030
/**
3131
* {@inheritdoc}
32+
* @throws GraphQlInputException
3233
*/
3334
public function resolveType(array $data)
3435
{
3536
$resolvedType = null;
3637

3738
foreach ($this->productTypeNameResolvers as $productTypeNameResolver) {
3839
if (!isset($data['type_id'])) {
39-
throw new InputException(
40+
throw new GraphQlInputException(
4041
__('%1 key doesn\'t exist in product data', ['type_id'])
4142
);
4243
}
@@ -47,8 +48,8 @@ public function resolveType(array $data)
4748
}
4849

4950
if (!$resolvedType) {
50-
throw new InputException(
51-
__('Concrete type for %1 not implemented', 'ProductInterface')
51+
throw new GraphQlInputException(
52+
__('Concrete type for %1 not implemented', ['ProductInterface'])
5253
);
5354
}
5455
}

app/code/Magento/CatalogGraphQl/Model/ProductLinkTypeResolverComposite.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Magento\CatalogGraphQl\Model;
88

99
use Magento\Framework\GraphQl\Config\Data\TypeResolverInterface;
10-
use Magento\Framework\Exception\InputException;
10+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1111

1212
/**
1313
* {@inheritdoc}
@@ -29,28 +29,27 @@ public function __construct(array $productLinksTypeNameResolvers = [])
2929

3030
/**
3131
* {@inheritdoc}
32+
* @throws GraphQlInputException
3233
*/
3334
public function resolveType(array $data)
3435
{
3536
$resolvedType = null;
3637

3738
foreach ($this->productLinksTypeNameResolvers as $productLinksTypeNameResolvers) {
38-
$linkType = $data['link_type'];
39-
if (!isset($linkType)) {
40-
throw new InputException(
39+
if (!isset($data['link_type'])) {
40+
throw new GraphQlInputException(
4141
__('%1 key doesn\'t exist in product data', ['link_type'])
4242
);
4343
}
4444
$resolvedType = $productLinksTypeNameResolvers->resolveType($data);
45-
if ($resolvedType) {
46-
return $resolvedType;
45+
46+
if (!$resolvedType) {
47+
throw new GraphQlInputException(
48+
__('Concrete type for %1 not implemented', ['ProductLinksInterface'])
49+
);
4750
}
4851
}
4952

50-
if (!$resolvedType) {
51-
throw new InputException(
52-
__('Concrete type for %1 not implemented', 'ProductLinksInterface')
53-
);
54-
}
53+
return $resolvedType;
5554
}
5655
}

app/code/Magento/CatalogGraphQl/Model/ProductLinksTypeResolver.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace Magento\CatalogGraphQl\Model;
88

99
use Magento\Framework\GraphQl\Config\Data\TypeResolverInterface;
10-
use Magento\Framework\Exception\InputException;
1110

1211
/**
1312
* {@inheritdoc}

app/code/Magento/CatalogGraphQl/etc/di.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@
3232
<item name="catalog_product" xsi:type="array">
3333
<item name="product" xsi:type="string">ProductInterface</item>
3434
<item name="simple" xsi:type="string">SimpleProduct</item>
35-
<item name="configurable" xsi:type="string">ConfigurableProduct</item>
36-
<item name="bundle" xsi:type="string">BundleProduct</item>
37-
<item name="downloadable" xsi:type="string">DownloadableProduct</item>
3835
<item name="virtual" xsi:type="string">VirtualProduct</item>
39-
<item name="grouped" xsi:type="string">GroupedProduct</item>
36+
</item>
37+
<item name="customizable_options" xsi:type="array">
38+
<item name="field" xsi:type="string">CustomizableFieldOption</item>
39+
<item name="date_time" xsi:type="string">CustomizableDateOption</item>
40+
<item name="file" xsi:type="string">CustomizableFileOption</item>
41+
<item name="area" xsi:type="string">CustomizableAreaOption</item>
42+
<item name="drop_down" xsi:type="string">CustomizableDropDownOption</item>
43+
<item name="radio" xsi:type="string">CustomizableRadioOption</item>
4044
</item>
4145
</argument>
4246
</arguments>

app/code/Magento/CatalogGraphQl/etc/graphql.xml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,15 @@
300300
<type xsi:type="OutputInterface" name="PhysicalProductInterface" typeResolver="Magento\CatalogGraphQl\Model\ProductInterfaceTypeResolverComposite">
301301
<field xsi:type="ScalarOutputField" name="weight" type="Float"/>
302302
</type>
303+
<type xsi:type="OutputInterface" name="CustomizableProductInterface" typeResolver="Magento\CatalogGraphQl\Model\ProductInterfaceTypeResolverComposite">
304+
<field xsi:type="ObjectArrayOutputField" name="options" itemType="CustomizableOptionInterface"/>
305+
</type>
306+
<type xsi:type="OutputInterface" name="CustomizableOptionInterface" typeResolver="Magento\CatalogGraphQl\Model\CustomizableOptionTypeResolver">
307+
<field xsi:type="ScalarOutputField" name="title" type="String"/>
308+
<field xsi:type="ScalarOutputField" name="required" type="Boolean"/>
309+
<field xsi:type="ScalarOutputField" name="sort_order" type="Int"/>
310+
<field xsi:type="ScalarOutputField" name="previous_group" type="String"/>
311+
</type>
303312
<type xsi:type="OutputType" name="VirtualProduct">
304313
<implements interface="ProductInterface" copyFields="true"/>
305314
</type>
@@ -415,4 +424,76 @@
415424
<field xsi:type="ScalarOutputField" name="video_description" type="String"/>
416425
<field xsi:type="ScalarOutputField" name="video_metadata" type="String"/>
417426
</type>
427+
<type xsi:type="OutputType" name="CustomizableFieldOption">
428+
<implements interface="CustomizableOptionInterface" copyFields="true"/>
429+
<field xsi:type="ObjectOutputField" name="value" type="CustomizableFieldValue"/>
430+
</type>
431+
<type xsi:type="OutputType" name="CustomizableFileOption">
432+
<implements interface="CustomizableOptionInterface" copyFields="true"/>
433+
<field xsi:type="ObjectOutputField" name="value" type="CustomizableFileValue"/>
434+
</type>
435+
<type xsi:type="OutputType" name="CustomizableDateOption">
436+
<implements interface="CustomizableOptionInterface" copyFields="true"/>
437+
<<field xsi:type="ObjectOutputField" name="value" type="CustomizableDateValue"/>
438+
</type>
439+
<type xsi:type="OutputType" name="CustomizableDropDownOption">
440+
<implements interface="CustomizableOptionInterface" copyFields="true"/>
441+
<field xsi:type="ObjectArrayOutputField" name="value" itemType="CustomizableDropDownValue"/>
442+
</type>
443+
<type xsi:type="OutputType" name="CustomizableRadioOption">
444+
<implements interface="CustomizableOptionInterface" copyFields="true"/>
445+
<field xsi:type="ObjectArrayOutputField" name="value" itemType="CustomizableRadioValue"/>
446+
</type>
447+
<type xsi:type="OutputType" name="CustomizableAreaOption">
448+
<implements interface="CustomizableOptionInterface" copyFields="true"/>
449+
<field xsi:type="ObjectOutputField" name="value" type="CustomizableAreaValue"/>
450+
</type>
451+
<type xsi:type="OutputType" name="CustomizableFieldValue">
452+
<field xsi:type="ScalarOutputField" name="price" type="Float"/>
453+
<field xsi:type="ObjectOutputField" name="price_type" type="PriceTypeEnum"/>
454+
<field xsi:type="ScalarOutputField" name="sku" type="String"/>
455+
<field xsi:type="ScalarOutputField" name="max_characters" type="Int"/>
456+
<field xsi:type="ScalarOutputField" name="product_sku" type="String"/>
457+
</type>
458+
<type xsi:type="OutputType" name="CustomizableFileValue">
459+
<field xsi:type="ScalarOutputField" name="price" type="Float"/>
460+
<field xsi:type="ObjectOutputField" name="price_type" type="PriceTypeEnum"/>
461+
<field xsi:type="ScalarOutputField" name="sku" type="String"/>
462+
<field xsi:type="ScalarOutputField" name="file_extension" type="String"/>
463+
<field xsi:type="ScalarOutputField" name="image_size_x" type="Int"/>
464+
<field xsi:type="ScalarOutputField" name="image_size_y" type="Int"/>
465+
<field xsi:type="ScalarOutputField" name="product_sku" type="String"/>
466+
</type>
467+
<type xsi:type="OutputType" name="CustomizableDateValue">
468+
<field xsi:type="ScalarOutputField" name="price" type="Float"/>
469+
<field xsi:type="ObjectOutputField" name="price_type" type="PriceTypeEnum"/>
470+
<field xsi:type="ScalarOutputField" name="sku" type="String"/>
471+
<field xsi:type="ScalarOutputField" name="product_sku" type="String"/>
472+
</type>
473+
<type xsi:type="OutputType" name="CustomizableDropDownValue">
474+
<field xsi:type="ScalarOutputField" name="option_type_id" type="Int"/>
475+
<field xsi:type="ScalarOutputField" name="price" type="Float"/>
476+
<field xsi:type="ObjectOutputField" name="price_type" type="PriceTypeEnum"/>
477+
<field xsi:type="ScalarOutputField" name="sku" type="String"/>
478+
<field xsi:type="ScalarOutputField" name="title" type="String"/>
479+
</type>
480+
<type xsi:type="OutputType" name="CustomizableRadioValue">
481+
<field xsi:type="ScalarOutputField" name="option_type_id" type="Int"/>
482+
<field xsi:type="ScalarOutputField" name="price" type="Float"/>
483+
<field xsi:type="ObjectOutputField" name="price_type" type="PriceTypeEnum"/>
484+
<field xsi:type="ScalarOutputField" name="sku" type="String"/>
485+
<field xsi:type="ScalarOutputField" name="title" type="String"/>
486+
</type>
487+
<type xsi:type="OutputType" name="CustomizableAreaValue">
488+
<field xsi:type="ScalarOutputField" name="price" type="Float"/>
489+
<field xsi:type="ObjectOutputField" name="price_type" type="PriceTypeEnum"/>
490+
<field xsi:type="ScalarOutputField" name="sku" type="String"/>
491+
<field xsi:type="ScalarOutputField" name="product_sku" type="String"/>
492+
<field xsi:type="ScalarOutputField" name="max_characters" type="Int"/>
493+
</type>
494+
<type xsi:type="Enum" name="PriceTypeEnum">
495+
<item name="fixed">FIXED</item>
496+
<item name="percent">PERCENT</item>
497+
<item name="dynamic">DYNAMIC</item>
498+
</type>
418499
</config>

0 commit comments

Comments
 (0)