Skip to content

Commit 80669e3

Browse files
author
vitaliyboyko
committed
graphQl-44: added ProductTextAttributeInput
1 parent 476f14f commit 80669e3

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextAttribute.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(
3939
}
4040

4141
/**
42-
* {@inheritdoc}
42+
* @inheritdoc
4343
*/
4444
public function resolve(
4545
Field $field,
@@ -55,8 +55,8 @@ public function resolve(
5555
/* @var $product Product */
5656
$product = $value['model'];
5757
$fieldName = $field->getName();
58-
$formatIdentifier = $args['format'] ?? $this->defaultFormat;
59-
$format = $this->formatList->create($formatIdentifier);
58+
$formatIdentifier = $args['filter']['description']['format'] ?? $this->defaultFormat;
59+
$format = $this->formatList->getFormatByIdentifier($formatIdentifier);
6060
$result = ['content' => $format->getContent($product, $fieldName)];
6161

6262
return $result;

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextAttribute/FormatList.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77

88
namespace Magento\CatalogGraphQl\Model\Resolver\Product\ProductTextAttribute;
99

10+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1011
use Magento\Framework\ObjectManagerInterface;
1112

13+
/**
14+
* Class FormatList
15+
* @package Magento\CatalogGraphQl\Model\Resolver\Product\ProductTextAttribute
16+
*/
1217
class FormatList
1318
{
1419
/**
@@ -37,10 +42,12 @@ public function __construct(
3742
* @param string $formatIdentifier
3843
* @return FormatInterface
3944
*/
40-
public function create(string $formatIdentifier) : FormatInterface
45+
public function getFormatByIdentifier(string $formatIdentifier) : FormatInterface
4146
{
42-
$formatClassName = 'Magento\CatalogGraphQl\Model\Resolver\Product\ProductTextAttribute\\' . ucfirst($formatIdentifier);
43-
$formatInstance = $this->objectManager->get($formatClassName);
47+
if (!isset($this->formats[$formatIdentifier])) {
48+
throw new GraphQlInputException(__('Format %1 does not exist.', [$formatIdentifier]));
49+
}
50+
$formatInstance = $this->objectManager->get($this->formats[$formatIdentifier]);
4451

4552
return $formatInstance;
4653
}

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductTextAttribute/Html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ public function getContent(
4444
): string {
4545
return $this->outputHelper->productAttribute($product, $product->getData($fieldName), $fieldName);
4646
}
47-
}
47+
}

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ interface ProductInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\
248248
id: Int @doc(description: "The ID number assigned to the product") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\EntityIdToId")
249249
name: String @doc(description: "The product name. Customers use this name to identify the product.")
250250
sku: String @doc(description: "A number or code assigned to a product to identify the product, options, price, and manufacturer")
251-
description: ProductTextAttribute @doc(description: "Detailed information about the product. The value can include simple HTML tags.")
252-
short_description: ProductTextAttribute @doc(description: "A short description of the product. Its use depends on the theme.")
251+
description: ProductTextAttribute @doc(description: "Detailed information about the product. The value can include simple HTML tags.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductTextAttribute")
252+
short_description: ProductTextAttribute @doc(description: "A short description of the product. Its use depends on the theme.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductTextAttribute")
253253
special_price: Float @doc(description: "The discounted price of the product")
254254
special_from_date: String @doc(description: "The beginning date that a product has a special price")
255255
special_to_date: String @doc(description: "The end date that a product has a special price")
@@ -433,8 +433,8 @@ type CategoryProducts @doc(description: "The category products object returned i
433433
input ProductFilterInput @doc(description: "ProductFilterInput defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.") {
434434
name: FilterTypeInput @doc(description: "The product name. Customers use this name to identify the product.")
435435
sku: FilterTypeInput @doc(description: "A number or code assigned to a product to identify the product, options, price, and manufacturer")
436-
description: FilterTypeInput @doc(description: "Detailed information about the product. The value can include simple HTML tags.")
437-
short_description: FilterTypeInput @doc(description: "A short description of the product. Its use depends on the theme.")
436+
description: ProductTextAttributeTypeInput @doc(description: "Detailed information about the product. The value can include simple HTML tags.")
437+
short_description: ProductTextAttributeTypeInput @doc(description: "A short description of the product. Its use depends on the theme.")
438438
price: FilterTypeInput @doc(description: "The price of an item")
439439
special_price: FilterTypeInput @doc(description: "The discounted price of the product")
440440
special_from_date: FilterTypeInput @doc(description: "The beginning date that a product has a special price")
@@ -557,9 +557,25 @@ type SortFields @doc(description: "SortFields contains a default value for sort
557557
options: [SortField] @doc(description: "Available sort fields")
558558
}
559559

560-
type ProductTextAttribute {
561-
content (
562-
format: String @doc(description: "The format of content")
563-
): String @doc(description: "The format of content")
564-
@resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductTextAttribute")
560+
type ProductTextAttribute @doc(description: "Product text attribute.") {
561+
content: String
562+
}
563+
564+
input ProductTextAttributeTypeInput @doc(description: "FilterTypeInput specifies which action will be performed in a query ") {
565+
format: String @doc(description: "Format of the content")
566+
eq: String @doc(description: "Equals")
567+
finset: [String] @doc(description: "Find in set. The value can contain a set of comma-separated values")
568+
from: String @doc(description: "From. Must be used with 'to'")
569+
gt: String @doc(description: "Greater than")
570+
gteq: String @doc(description: "Greater than or equal to")
571+
in: [String] @doc(description: "In. The value can contain a set of comma-separated values")
572+
like: String @doc(description: "Like. The specified value can contain % (percent signs) to allow matching of 0 or more characters")
573+
lt: String @doc(description: "Less than")
574+
lteq: String @doc(description: "Less than or equal to")
575+
moreq: String @doc(description: "More than or equal to")
576+
neq: String @doc(description: "Not equal to")
577+
notnull: String @doc(description: "Not null")
578+
null: String @doc(description: "Is null")
579+
to: String@doc(description: "To. Must be used with 'from'")
580+
nin: [String] @doc(description: "Not in. The value can contain a set of comma-separated values")
565581
}

0 commit comments

Comments
 (0)