Skip to content

Commit 9569a40

Browse files
author
Eric Bohanon
committed
MAGETWO-82674: GraphQL Full Text Search
1 parent c00ff32 commit 9569a40

File tree

6 files changed

+26
-19
lines changed

6 files changed

+26
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct(
5454
public function format(Product $product)
5555
{
5656
$productData = $product->getData();
57-
$productData['id'] = $productData['entity_id'];
57+
$productData['id'] = $product->getId();
5858
unset($productData['entity_id']);
5959

6060
$productData = $this->mediaGalleryEntriesFormatter->format($product, $productData);

app/code/Magento/GraphQlConfigurableProduct/Model/Plugin/Model/Resolver/Products/DataProvider/ProductPlugin.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
use Magento\Catalog\Api\Data\ProductInterface;
1010
use Magento\Catalog\Api\ProductRepositoryInterface;
11-
use Magento\ConfigurableProduct\Api\Data\OptionInterface;
1211
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1312
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\Collection
1413
as AttributeCollection;
@@ -17,6 +16,7 @@
1716
use Magento\Framework\Api\SearchResultsInterface;
1817
use Magento\Framework\Api\SearchResultsInterfaceFactory;
1918
use Magento\Framework\DataObject;
19+
use Magento\Framework\EntityManager\MetadataPool;
2020
use Magento\GraphQlCatalog\Model\Resolver\Products\DataProvider\Product;
2121
use Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute;
2222

@@ -47,6 +47,11 @@ class ProductPlugin
4747
*/
4848
private $searchCriteriaBuilder;
4949

50+
/**
51+
* @var MetadataPool
52+
*/
53+
private $metadataPool;
54+
5055
/**
5156
* ProductPlugin constructor.
5257
*
@@ -55,19 +60,22 @@ class ProductPlugin
5560
* @param ProductCollection $productCollection
5661
* @param ProductRepositoryInterface $productRepository
5762
* @param SearchCriteriaBuilder $searchCriteriaBuilder
63+
* @param MetadataPool $metadataPool
5864
*/
5965
public function __construct(
6066
Configurable $configurable,
6167
AttributeCollection $attributeCollection,
6268
ProductCollection $productCollection,
6369
ProductRepositoryInterface $productRepository,
64-
SearchCriteriaBuilder $searchCriteriaBuilder
70+
SearchCriteriaBuilder $searchCriteriaBuilder,
71+
MetadataPool $metadataPool
6572
) {
6673
$this->configurable = $configurable;
6774
$this->attributeCollection = $attributeCollection;
6875
$this->productCollection = $productCollection;
6976
$this->productRepository = $productRepository;
7077
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
78+
$this->metadataPool = $metadataPool;
7179
}
7280

7381
/**
@@ -111,12 +119,13 @@ public function afterGetList(Product $subject, SearchResultsInterface $result)
111119
*/
112120
private function addConfigurableData($result, $children, $attributes)
113121
{
122+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
114123
foreach ($result->getItems() as $product) {
115124
if ($product->getTypeId() === Configurable::TYPE_CODE) {
116125
$extensionAttributes = $product->getExtensionAttributes();
117126
$childrenIds = [];
118127
foreach ($children as $child) {
119-
if ($child->getParentId() === $product->getId()) {
128+
if ($child->getParentId() === $product->getData($linkField)) {
120129
$childrenIds[] = $child->getId();
121130
}
122131
}

app/code/Magento/GraphQlConfigurableProduct/Model/Resolver/Products/Query/ConfigurableProductPostProcessor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ public function process(array $productData)
8282
$childData = $this->formatter->format($childProduct);
8383
$childId = (int)$childProduct->getId();
8484
foreach ($productData as $key => $item) {
85-
if (array_key_exists($childId, $item['configurable_product_links'])) {
85+
if (isset($item['configurable_product_links'])
86+
&& array_key_exists($childId, $item['configurable_product_links'])
87+
) {
8688
$productData[$key]['configurable_product_links'][$childId] = $childData;
8789
$categoryLinks = $this->productResource->getCategoryIds($childProduct);
8890
foreach ($categoryLinks as $position => $link) {

app/code/Magento/GraphQlConfigurableProduct/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"php": "7.0.2|7.0.4|~7.0.6|~7.1.0",
88
"magento/module-eav": "100.3.*",
99
"magento/module-catalog": "100.2.*",
10+
"magento/module-configurable-product": "100.2.*",
1011
"magento/module-graph-ql": "100.0.*",
1112
"magento/module-graph-ql-catalog": "100.0.*",
1213
"magento/framework": "100.3.*"

app/code/Magento/GraphQlConfigurableProduct/etc/module.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<module name="Magento_Catalog"/>
1212
<module name="Magento_ConfigurableProduct"/>
1313
<module name="Magento_GraphQl"/>
14+
<module name="Magento_GraphQlCatalog"/>
1415
</sequence>
1516
</module>
1617
</config>

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductViewTest.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -455,21 +455,15 @@ private function assertOptions($product, $actualResponse)
455455
{
456456
$productOptions = $product->getOptions();
457457
$this->assertNotEmpty($actualResponse['options'], "Precondition failed: 'options' must not be empty");
458-
usort(
459-
$actualResponse['options'],
460-
function ($a, $b) {
461-
return strcmp($a['title'], $b['title']);
462-
}
463-
);
464-
usort(
465-
$productOptions,
466-
function ($a, $b) {
467-
return strcmp($a['title'], $b['title']);
458+
foreach ($actualResponse['options'] as $optionsArray) {
459+
$option = null;
460+
/** @var \Magento\Catalog\Model\Product\Option $optionSelect */
461+
foreach ($productOptions as $optionSelect) {
462+
if ($optionSelect->getOptionId() == $optionsArray['option_id']) {
463+
$option = $optionSelect;
464+
break;
465+
}
468466
}
469-
);
470-
foreach ($actualResponse['options'] as $optionsIndex => $optionsArray) {
471-
/** @var \Magento\Catalog\Model\Product\Option $option */
472-
$option = $productOptions[$optionsIndex];
473467
$assertionMap = [
474468
['response_field' => 'product_sku', 'expected_value' => $option->getProductSku()],
475469
['response_field' => 'sort_order', 'expected_value' => $option->getSortOrder()],

0 commit comments

Comments
 (0)