Skip to content

Commit

Permalink
graphQl-44: added ProductTextAttributeInput
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaliyboyko committed Oct 20, 2018
1 parent 476f14f commit 80669e3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function resolve(
Field $field,
Expand All @@ -55,8 +55,8 @@ public function resolve(
/* @var $product Product */
$product = $value['model'];
$fieldName = $field->getName();
$formatIdentifier = $args['format'] ?? $this->defaultFormat;
$format = $this->formatList->create($formatIdentifier);
$formatIdentifier = $args['filter']['description']['format'] ?? $this->defaultFormat;
$format = $this->formatList->getFormatByIdentifier($formatIdentifier);
$result = ['content' => $format->getContent($product, $fieldName)];

return $result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@

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

use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\ObjectManagerInterface;

/**
* Class FormatList
* @package Magento\CatalogGraphQl\Model\Resolver\Product\ProductTextAttribute
*/
class FormatList
{
/**
Expand Down Expand Up @@ -37,10 +42,12 @@ public function __construct(
* @param string $formatIdentifier
* @return FormatInterface
*/
public function create(string $formatIdentifier) : FormatInterface
public function getFormatByIdentifier(string $formatIdentifier) : FormatInterface
{
$formatClassName = 'Magento\CatalogGraphQl\Model\Resolver\Product\ProductTextAttribute\\' . ucfirst($formatIdentifier);
$formatInstance = $this->objectManager->get($formatClassName);
if (!isset($this->formats[$formatIdentifier])) {
throw new GraphQlInputException(__('Format %1 does not exist.', [$formatIdentifier]));
}
$formatInstance = $this->objectManager->get($this->formats[$formatIdentifier]);

return $formatInstance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ public function getContent(
): string {
return $this->outputHelper->productAttribute($product, $product->getData($fieldName), $fieldName);
}
}
}
34 changes: 25 additions & 9 deletions app/code/Magento/CatalogGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ interface ProductInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\
id: Int @doc(description: "The ID number assigned to the product") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\EntityIdToId")
name: String @doc(description: "The product name. Customers use this name to identify the product.")
sku: String @doc(description: "A number or code assigned to a product to identify the product, options, price, and manufacturer")
description: ProductTextAttribute @doc(description: "Detailed information about the product. The value can include simple HTML tags.")
short_description: ProductTextAttribute @doc(description: "A short description of the product. Its use depends on the theme.")
description: ProductTextAttribute @doc(description: "Detailed information about the product. The value can include simple HTML tags.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductTextAttribute")
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")
special_price: Float @doc(description: "The discounted price of the product")
special_from_date: String @doc(description: "The beginning date that a product has a special price")
special_to_date: String @doc(description: "The end date that a product has a special price")
Expand Down Expand Up @@ -433,8 +433,8 @@ type CategoryProducts @doc(description: "The category products object returned i
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.") {
name: FilterTypeInput @doc(description: "The product name. Customers use this name to identify the product.")
sku: FilterTypeInput @doc(description: "A number or code assigned to a product to identify the product, options, price, and manufacturer")
description: FilterTypeInput @doc(description: "Detailed information about the product. The value can include simple HTML tags.")
short_description: FilterTypeInput @doc(description: "A short description of the product. Its use depends on the theme.")
description: ProductTextAttributeTypeInput @doc(description: "Detailed information about the product. The value can include simple HTML tags.")
short_description: ProductTextAttributeTypeInput @doc(description: "A short description of the product. Its use depends on the theme.")
price: FilterTypeInput @doc(description: "The price of an item")
special_price: FilterTypeInput @doc(description: "The discounted price of the product")
special_from_date: FilterTypeInput @doc(description: "The beginning date that a product has a special price")
Expand Down Expand Up @@ -557,9 +557,25 @@ type SortFields @doc(description: "SortFields contains a default value for sort
options: [SortField] @doc(description: "Available sort fields")
}

type ProductTextAttribute {
content (
format: String @doc(description: "The format of content")
): String @doc(description: "The format of content")
@resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductTextAttribute")
type ProductTextAttribute @doc(description: "Product text attribute.") {
content: String
}

input ProductTextAttributeTypeInput @doc(description: "FilterTypeInput specifies which action will be performed in a query ") {
format: String @doc(description: "Format of the content")
eq: String @doc(description: "Equals")
finset: [String] @doc(description: "Find in set. The value can contain a set of comma-separated values")
from: String @doc(description: "From. Must be used with 'to'")
gt: String @doc(description: "Greater than")
gteq: String @doc(description: "Greater than or equal to")
in: [String] @doc(description: "In. The value can contain a set of comma-separated values")
like: String @doc(description: "Like. The specified value can contain % (percent signs) to allow matching of 0 or more characters")
lt: String @doc(description: "Less than")
lteq: String @doc(description: "Less than or equal to")
moreq: String @doc(description: "More than or equal to")
neq: String @doc(description: "Not equal to")
notnull: String @doc(description: "Not null")
null: String @doc(description: "Is null")
to: String@doc(description: "To. Must be used with 'from'")
nin: [String] @doc(description: "Not in. The value can contain a set of comma-separated values")
}

0 comments on commit 80669e3

Please sign in to comment.