Skip to content

Commit 5c9abce

Browse files
authored
PWA-1673: View Product Attributes values on PDP - Content (#27)
* PWA-1673: View Product Attributes values on PDP - Content * PWA-1673: View Product Attributes values on PDP - Content * PWA-1673: View Product Attributes values on PDP - Content * PWA-1673: View Product Attributes values on PDP - Content * PWA-1673: View Product Attributes values on PDP - Content * PWA-1673: View Product Attributes values on PDP - Content * PWA-1673: View Product Attributes values on PDP - Content
1 parent 558abf0 commit 5c9abce

File tree

19 files changed

+380
-13
lines changed

19 files changed

+380
-13
lines changed

CatalogGraphQlAux/Model/Resolver/CustomAttributes.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
namespace Magento\CatalogGraphQlAux\Model\Resolver;
99

10+
use Magento\Catalog\Helper\Output as OutputHelper;
1011
use Magento\Catalog\Model\Product;
1112
use Magento\Framework\Exception\LocalizedException;
1213
use Magento\Framework\GraphQl\Config\Element\Field;
1314
use Magento\Framework\GraphQl\Query\ResolverInterface;
1415
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16+
use Magento\Framework\App\ObjectManager;
1517
use Magento\EavGraphQlAux\Model\Resolver\Query\Attributes;
1618
use Magento\Framework\GraphQl\Query\Uid;
1719
use Magento\EavGraphQlAux\Model\Resolver\DataProvider\AttributeMetadata;
@@ -24,6 +26,11 @@
2426
*/
2527
class CustomAttributes implements ResolverInterface
2628
{
29+
/**
30+
* @var OutputHelper
31+
*/
32+
private $outputHelper;
33+
2734
/**
2835
* @var string[]
2936
*/
@@ -55,19 +62,23 @@ class CustomAttributes implements ResolverInterface
5562
* @param AttributeMetadata $metadataProvider
5663
* @param AttributeOptions $attributeOptions
5764
* @param array|null $selectableTypes
65+
* @param OutputHelper|null $outputHelper
5866
*/
5967
public function __construct(
6068
Uid $uidEncoder,
6169
Attributes $attributes,
6270
AttributeMetadata $metadataProvider,
6371
AttributeOptions $attributeOptions,
64-
array $selectableTypes = null
72+
array $selectableTypes = null,
73+
OutputHelper $outputHelper = null
6574
) {
6675
$this->uidEncoder = $uidEncoder;
6776
$this->attributes = $attributes;
6877
$this->metadataProvider = $metadataProvider;
6978
$this->attributeOptions = $attributeOptions;
7079
$this->selectableTypes = $selectableTypes ?? ['SELECT'];
80+
$this->outputHelper = $outputHelper ?: ObjectManager::getInstance()
81+
->get(outputHelper::class);
7182
}
7283

7384
/**
@@ -110,7 +121,13 @@ public function resolve(
110121
];
111122
} else {
112123
$attributeData['entered_attribute_value'] = [
113-
'value' => $attributeValue
124+
'value' => $attribute->getIsHtmlAllowedOnFront() ?
125+
$this->outputHelper->productAttribute(
126+
$product,
127+
$attributeValue,
128+
$attribute->getAttributeCode()
129+
) :
130+
$attributeValue
114131
];
115132
$attributeData['selected_attribute_options'] = [];
116133
}

EavGraphQlAux/Model/Resolver/DataProvider/AttributeMetadata.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public function getAttributeMetadata(AttributeInterface $attribute, int $storeId
7272
$attribute->getEntityType()->getEntityTypeCode()
7373
);
7474
$dataType = $this->enumLookup->getEnumValueFromField('ObjectDataTypeEnum', $attributeType);
75+
$uiInputType = $attribute->getFrontendInput() === "textarea" && $attribute->getIsWysiwygEnabled() ?
76+
'texteditor' :
77+
$attribute->getFrontendInput();
7578

7679
return [
7780
'uid' => $this->uidEncoder->encode($entityType . '/' . $attribute->getAttributeCode()),
@@ -88,7 +91,7 @@ public function getAttributeMetadata(AttributeInterface $attribute, int $storeId
8891
'ui_input' => [
8992
'ui_input_type' => $this->enumLookup->getEnumValueFromField(
9093
'UiInputTypeEnum',
91-
$attribute->getFrontendInput()
94+
$uiInputType
9295
),
9396
'is_html_allowed' => $attribute->getIsHtmlAllowedOnFront(),
9497
'attribute' => $attribute
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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\EavGraphQlAux\Model\TypeResolver;
9+
10+
use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface;
11+
12+
/**
13+
* @inheritdoc
14+
*/
15+
class UiAttributeTypeTextEditor implements TypeResolverInterface
16+
{
17+
private const TYPE = 'UiAttributeTypeTextEditor';
18+
19+
/**
20+
* @inheritdoc
21+
*/
22+
public function resolveType(array $data) : string
23+
{
24+
if (isset($data['ui_input_type']) && $data['ui_input_type'] == 'TEXTEDITOR') {
25+
return self::TYPE;
26+
}
27+
return '';
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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\EavGraphQlAux\Model\TypeResolver;
9+
10+
use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface;
11+
12+
/**
13+
* @inheritdoc
14+
*/
15+
class UiAttributeTypeTextarea implements TypeResolverInterface
16+
{
17+
private const TYPE = 'UiAttributeTypeTextarea';
18+
19+
/**
20+
* @inheritdoc
21+
*/
22+
public function resolveType(array $data) : string
23+
{
24+
if (isset($data['ui_input_type']) && $data['ui_input_type'] == 'TEXTAREA') {
25+
return self::TYPE;
26+
}
27+
return '';
28+
}
29+
}

EavGraphQlAux/etc/graphql/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<item name="ui_select_type_resolver" xsi:type="object">Magento\EavGraphQlAux\Model\TypeResolver\UiAttributeTypeSelect</item>
1414
<item name="ui_multiselect_type_resolver" xsi:type="object">Magento\EavGraphQlAux\Model\TypeResolver\UiAttributeTypeMultiSelect</item>
1515
<item name="ui_boolean_type_resolver" xsi:type="object">Magento\EavGraphQlAux\Model\TypeResolver\UiAttributeTypeBoolean</item>
16+
<item name="ui_textarea_type_resolver" xsi:type="object">Magento\EavGraphQlAux\Model\TypeResolver\UiAttributeTypeTextarea</item>
17+
<item name="ui_texteditor_type_resolver" xsi:type="object">Magento\EavGraphQlAux\Model\TypeResolver\UiAttributeTypeTextEditor</item>
1618
</argument>
1719
</arguments>
1820
</type>
@@ -49,6 +51,7 @@
4951
<item name="swatch_visual" xsi:type="string">swatch_visual</item>
5052
<item name="text" xsi:type="string">text</item>
5153
<item name="textarea" xsi:type="string">textarea</item>
54+
<item name="texteditor" xsi:type="string">texteditor</item>
5255
<item name="weight" xsi:type="string">weight</item>
5356
</item>
5457
</argument>

EavGraphQlAux/etc/schema.graphqls

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ type UiAttributeTypeBoolean implements UiInputTypeInterface, AttributeOptionsInt
6464
type UiAttributeTypeAny implements UiInputTypeInterface {
6565
}
6666

67+
type UiAttributeTypeTextarea implements UiInputTypeInterface {
68+
}
69+
70+
type UiAttributeTypeTextEditor implements UiInputTypeInterface {
71+
}
72+
6773
type StoreLabels @doc(description: "Contains the store code and label of an attribute.") {
6874
store_code: String @doc(description: "The assigned store code.")
6975
label: String @doc(description: "The label assigned to the attribute.")
@@ -92,6 +98,7 @@ enum UiInputTypeEnum {
9298
SELECT
9399
TEXT
94100
TEXTAREA
101+
TEXTEDITOR
95102
WEIGHT
96103
}
97104

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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\PageBuilderPwa\Model\TypeResolver;
9+
10+
use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface;
11+
12+
/**
13+
* @inheritdoc
14+
*/
15+
class UiAttributeTypePageBuilder implements TypeResolverInterface
16+
{
17+
private const TYPE = 'UiAttributeTypePageBuilder';
18+
19+
/**
20+
* @inheritdoc
21+
*/
22+
public function resolveType(array $data) : string
23+
{
24+
if (isset($data['ui_input_type']) && $data['ui_input_type'] == 'PAGEBUILDER') {
25+
return self::TYPE;
26+
}
27+
return '';
28+
}
29+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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\PageBuilderPwa\Plugin;
9+
10+
use Magento\Eav\Api\Data\AttributeInterface;
11+
use Magento\EavGraphQlAux\Model\Resolver\DataProvider\AttributeMetadata;
12+
use Magento\Framework\GraphQl\Query\EnumLookup;
13+
use Magento\Framework\Exception\RuntimeException;
14+
15+
class UiInputTypePageBuilder
16+
{
17+
private const TYPE = 'pagebuilder';
18+
19+
/**
20+
* @var EnumLookup
21+
*/
22+
private $enumLookup;
23+
24+
/**
25+
* @param EnumLookup $enumLookup
26+
*/
27+
public function __construct(
28+
EnumLookup $enumLookup
29+
) {
30+
$this->enumLookup = $enumLookup;
31+
}
32+
33+
/**
34+
* Change ui input type for the attribute if PageBuilder is enabled for it
35+
*
36+
* @param AttributeMetadata $subject
37+
* @param array $result
38+
* @param AttributeInterface $attribute
39+
* @return array
40+
* @throws RuntimeException
41+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
42+
*/
43+
public function afterGetAttributeMetadata(
44+
AttributeMetadata $subject,
45+
array $result,
46+
AttributeInterface $attribute
47+
): array {
48+
if ($attribute->getIsPagebuilderEnabled()) {
49+
$result['ui_input']['ui_input_type'] = $this->enumLookup->getEnumValueFromField(
50+
'UiInputTypeEnum',
51+
self::TYPE
52+
);
53+
}
54+
return $result;
55+
}
56+
}

PageBuilderPwa/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"magento/framework": "*",
1414
"magento/module-cms": "*",
1515
"magento/module-page-builder": "*",
16+
"magento/module-eav-graph-ql-aux": "*",
1617
"php": "~7.4.0||~8.1.0",
1718
"phpgt/dom": "*"
1819
},

PageBuilderPwa/etc/graphql/di.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\EavGraphQlAux\Model\TypeResolver\UiInputComposite">
10+
<arguments>
11+
<argument name="uiInputTypeResolvers" xsi:type="array">
12+
<item name="ui_pagebuilder_type_resolver" xsi:type="object">Magento\PageBuilderPwa\Model\TypeResolver\UiAttributeTypePageBuilder</item>
13+
</argument>
14+
</arguments>
15+
</type>
16+
<type name="Magento\Framework\GraphQl\Schema\Type\Enum\DefaultDataMapper">
17+
<arguments>
18+
<argument name="map" xsi:type="array">
19+
<item name="UiInputTypeEnum" xsi:type="array">
20+
<item name="pagebuilder" xsi:type="string">pagebuilder</item>
21+
</item>
22+
</argument>
23+
</arguments>
24+
</type>
25+
<type name="Magento\EavGraphQlAux\Model\Resolver\DataProvider\AttributeMetadata">
26+
<plugin name="ui_input_type_pagebuilder" type="Magento\PageBuilderPwa\Plugin\UiInputTypePageBuilder"/>
27+
</type>
28+
</config>

0 commit comments

Comments
 (0)