Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 16da117

Browse files
author
Eric Bohanon
committed
MAGETWO-82674: GraphQL Full Text Search
1 parent 520740d commit 16da117

File tree

13 files changed

+382
-195
lines changed

13 files changed

+382
-195
lines changed

app/code/Magento/GraphQl/Model/SchemaGenerator.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ public function generate()
8484
'fields' => $schemaConfig['fields'],
8585
'resolveField' => function ($value, $args, $context, ResolveInfo $info) {
8686
$fieldName = $info->fieldName;
87+
$fieldNodes = $info->fieldNodes;
88+
$selections = [];
89+
// foreach ($fieldNodes as $fieldNode) {
90+
// foreach ($fieldNode->selectionSet->selections as $field) {
91+
// $name = $field->name;
92+
// if (isset($field->selectionSet)) {
93+
// $selections[$name] = $this->getFields;
94+
// }
95+
// foreach ($field->selectionSet->selections as $selection) {
96+
// $selections[$name] = $selection->name;
97+
// }
98+
// }
99+
// }
87100
$resolver = $this->resolverFactory->create($fieldName);
88101

89102
$fieldArguments = [];

app/code/Magento/GraphQlCatalog/Model/Resolver/Products/DataProvider/MediaGalleryEntries.php

Lines changed: 0 additions & 75 deletions
This file was deleted.

app/code/Magento/GraphQlCatalog/Model/Resolver/Products/DataProvider/Product.php

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,6 @@
2525
*/
2626
class Product
2727
{
28-
/**
29-
* @var ServiceOutputProcessor
30-
*/
31-
private $serviceOutputProcessor;
32-
33-
/**
34-
* @var MediaGalleryEntries
35-
*/
36-
private $mediaGalleryResolver;
37-
38-
/**
39-
* @var SerializerInterface
40-
*/
41-
private $jsonSerializer;
42-
4328
/**
4429
* @var CollectionFactory
4530
*/
@@ -61,78 +46,23 @@ class Product
6146
private $searchResultsFactory;
6247

6348
/**
64-
* @param ServiceOutputProcessor $serviceOutputProcessor
65-
* @param MediaGalleryEntries $mediaGalleryResolver
66-
* @param SerializerInterface $jsonSerializer
6749
* @param CollectionFactory $collectionFactory
6850
* @param JoinProcessorInterface $joinProcessor
6951
* @param CollectionProcessorInterface $collectionProcessor
7052
* @param ProductSearchResultsInterfaceFactory $searchResultsFactory
7153
*/
7254
public function __construct(
73-
ServiceOutputProcessor $serviceOutputProcessor,
74-
MediaGalleryEntries $mediaGalleryResolver,
75-
SerializerInterface $jsonSerializer,
7655
CollectionFactory $collectionFactory,
7756
JoinProcessorInterface $joinProcessor,
7857
CollectionProcessorInterface $collectionProcessor,
7958
ProductSearchResultsInterfaceFactory $searchResultsFactory
8059
) {
81-
$this->serviceOutputProcessor = $serviceOutputProcessor;
82-
$this->mediaGalleryResolver = $mediaGalleryResolver;
83-
$this->jsonSerializer = $jsonSerializer;
8460
$this->collectionFactory = $collectionFactory;
8561
$this->joinProcessor = $joinProcessor;
8662
$this->collectionProcessor = $collectionProcessor;
8763
$this->searchResultsFactory = $searchResultsFactory;
8864
}
8965

90-
/**
91-
* Transform single product data from object to in array format
92-
*
93-
* @param \Magento\Catalog\Api\Data\ProductInterface $productObject
94-
* @return array|null
95-
*/
96-
public function processProduct(\Magento\Catalog\Api\Data\ProductInterface $productObject)
97-
{
98-
/** @var \Magento\Catalog\Model\Product $productObject */
99-
$productArray = $productObject->getData();
100-
$productArray['id'] = $productArray['entity_id'];
101-
unset($productArray['entity_id']);
102-
$productArray['media_gallery_entries'] = $productObject->getMediaGalleryEntries();
103-
if (isset($productArray['media_gallery_entries'])) {
104-
foreach ($productArray['media_gallery_entries'] as $key => $entry) {
105-
if ($entry->getExtensionAttributes() && $entry->getExtensionAttributes()->getVideoContent()) {
106-
$productArray['media_gallery_entries'][$key]['video_content']
107-
= $entry->getExtensionAttributes()->getVideoContent()->getData();
108-
}
109-
}
110-
}
111-
if (isset($productArray['options'])) {
112-
/** @var Option $option */
113-
foreach ($productArray['options'] as $key => $option) {
114-
$productArray['options'][$key] = $option->getData();
115-
$productArray['options'][$key]['product_sku'] = $option->getProductSku();
116-
$values = $option->getValues() ?: [];
117-
/** @var Option\Value $value */
118-
foreach ($values as $value) {
119-
$productArray['options'][$key]['values'][] = $value->getData();
120-
}
121-
}
122-
}
123-
$tierPrices = $productObject->getTierPrices();
124-
if ($tierPrices) {
125-
/** @var TierPrice $tierPrice */
126-
foreach ($tierPrices as $tierPrice) {
127-
$productArray['tier_prices'][] = $tierPrice->getData();
128-
}
129-
} else {
130-
$productArray['tier_prices'] = null;
131-
}
132-
133-
return $productArray;
134-
}
135-
13666
/**
13767
* Gets list of product data with full data set
13868
*
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\GraphQlCatalog\Model\Resolver\Products\DataProvider\Product;
8+
9+
use Magento\Catalog\Model\Product;
10+
use Magento\Catalog\Model\Product\Option;
11+
use Magento\Catalog\Model\Product\TierPrice;
12+
use Magento\GraphQlCatalog\Model\Resolver\Products\DataProvider\Product\Formatter\MediaGalleryEntries;
13+
use Magento\GraphQlCatalog\Model\Resolver\Products\DataProvider\Product\Formatter\Options;
14+
use Magento\GraphQlCatalog\Model\Resolver\Products\DataProvider\Product\Formatter\TierPrices;
15+
16+
class Formatter
17+
{
18+
/**
19+
* @var MediaGalleryEntries
20+
*/
21+
private $mediaGalleryEntriesFormatter;
22+
23+
/**
24+
* @var Options
25+
*/
26+
private $optionsFormatter;
27+
28+
/**
29+
* @var TierPrices
30+
*/
31+
private $tierPricesFormatter;
32+
33+
/**
34+
* @param MediaGalleryEntries $mediaGalleryEntriesFormatter
35+
* @param Options $optionsFormatter
36+
* @param TierPrices $tierPricesFormatter
37+
*/
38+
public function __construct(
39+
MediaGalleryEntries $mediaGalleryEntriesFormatter,
40+
Options $optionsFormatter,
41+
TierPrices $tierPricesFormatter
42+
) {
43+
$this->mediaGalleryEntriesFormatter = $mediaGalleryEntriesFormatter;
44+
$this->optionsFormatter = $optionsFormatter;
45+
$this->tierPricesFormatter = $tierPricesFormatter;
46+
}
47+
48+
/**
49+
* Format single product data from object to an array
50+
*
51+
* @param Product $product
52+
* @return array
53+
*/
54+
public function format(Product $product)
55+
{
56+
$productData = $product->getData();
57+
$productData['id'] = $productData['entity_id'];
58+
unset($productData['entity_id']);
59+
60+
$productData = $this->mediaGalleryEntriesFormatter->format($product, $productData);
61+
$productData = $this->optionsFormatter->format($productData);
62+
$productData = $this->tierPricesFormatter->format($product, $productData);
63+
64+
return $productData;
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\GraphQlCatalog\Model\Resolver\Products\DataProvider\Product\Formatter;
8+
9+
use Magento\Catalog\Model\Product;
10+
11+
/**
12+
* Format a product's media gallery information to conform to GraphQL schema representation
13+
*/
14+
class MediaGalleryEntries
15+
{
16+
/**
17+
* Format product's media gallery entry data to conform to GraphQL schema
18+
*
19+
* @param Product $product
20+
* @param array $productData
21+
* @return array
22+
*/
23+
public function format(Product $product, array $productData)
24+
{
25+
$productData['media_gallery_entries'] = $product->getMediaGalleryEntries();
26+
if (isset($productData['media_gallery_entries'])) {
27+
foreach ($productData['media_gallery_entries'] as $key => $entry) {
28+
if ($entry->getExtensionAttributes() && $entry->getExtensionAttributes()->getVideoContent()) {
29+
$productData['media_gallery_entries'][$key]['video_content']
30+
= $entry->getExtensionAttributes()->getVideoContent()->getData();
31+
}
32+
}
33+
}
34+
35+
return $productData;
36+
}
37+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\GraphQlCatalog\Model\Resolver\Products\DataProvider\Product\Formatter;
8+
9+
use Magento\Catalog\Model\Product;
10+
use Magento\Catalog\Model\Product\Option;
11+
12+
/**
13+
* Format a product's option information to conform to GraphQL schema representation
14+
*/
15+
class Options
16+
{
17+
/**
18+
* Format product's option data to conform to GraphQL schema
19+
*
20+
* @param array $productData
21+
* @return array
22+
*/
23+
public function format(array $productData)
24+
{
25+
if (isset($productData['options'])) {
26+
/** @var Option $option */
27+
foreach ($productData['options'] as $key => $option) {
28+
$productData['options'][$key] = $option->getData();
29+
$productData['options'][$key]['product_sku'] = $option->getProductSku();
30+
$values = $option->getValues() ?: [];
31+
/** @var Option\Value $value */
32+
foreach ($values as $value) {
33+
$productData['options'][$key]['values'][] = $value->getData();
34+
}
35+
}
36+
}
37+
38+
return $productData;
39+
}
40+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\GraphQlCatalog\Model\Resolver\Products\DataProvider\Product\Formatter;
8+
9+
use Magento\Catalog\Model\Product;
10+
use Magento\Catalog\Model\Product\TierPrice;
11+
12+
/**
13+
* Format a product's tier price information to conform to GraphQL schema representation
14+
*/
15+
class TierPrices
16+
{
17+
/**
18+
* Format product's tier price data to conform to GraphQL schema
19+
*
20+
* @param Product $product
21+
* @param array $productData
22+
* @return array
23+
*/
24+
public function format(Product $product, array $productData)
25+
{
26+
$tierPrices = $product->getTierPrices();
27+
if ($tierPrices) {
28+
/** @var TierPrice $tierPrice */
29+
foreach ($tierPrices as $tierPrice) {
30+
$productData['tier_prices'][] = $tierPrice->getData();
31+
}
32+
} else {
33+
$productData['tier_prices'] = null;
34+
}
35+
36+
return $productData;
37+
}
38+
}

0 commit comments

Comments
 (0)