Skip to content

Commit eb09566

Browse files
authored
Merge pull request #2318 from magento-honey-badgers/MAGETWO-89292-SDL
[honey] GraphQL sprint 10
2 parents 286b00f + 7e7ad98 commit eb09566

File tree

372 files changed

+22710
-7192
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

372 files changed

+22710
-7192
lines changed

app/code/Magento/Bundle/Model/ResourceModel/Option/Collection.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
2626
*/
2727
protected $_selectionsAppended = false;
2828

29+
/**
30+
* @var int[]
31+
*/
32+
private $productIds = [];
33+
2934
/**
3035
* Init model and resource model
3136
*
@@ -94,20 +99,34 @@ public function joinValues($storeId)
9499
*/
95100
public function setProductIdFilter($productId)
96101
{
102+
$this->productIds[] = $productId;
103+
97104
$productTable = $this->getTable('catalog_product_entity');
98105
$linkField = $this->getConnection()->getAutoIncrementField($productTable);
99106
$this->getSelect()->join(
100107
['cpe' => $productTable],
101108
'cpe.'.$linkField.' = main_table.parent_id',
102109
[]
103110
)->where(
104-
"cpe.entity_id = ?",
105-
$productId
111+
"cpe.entity_id = (?)",
112+
$this->productIds
106113
);
107114

108115
return $this;
109116
}
110117

118+
/**
119+
* Clear product id's after load to insure valid future usage of collection.
120+
*
121+
* @return $this
122+
*/
123+
protected function _afterLoad()
124+
{
125+
$this->productIds = [];
126+
127+
return parent::_afterLoad();
128+
}
129+
111130
/**
112131
* Set product link filter
113132
*

app/code/Magento/BundleGraphQl/Model/BundleProductTypeResolver.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\BundleGraphQl\Model;
89

9-
use Magento\Framework\GraphQl\Config\Data\TypeResolverInterface;
10+
use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface;
1011

1112
/**
1213
* {@inheritdoc}
@@ -16,10 +17,11 @@ class BundleProductTypeResolver implements TypeResolverInterface
1617
/**
1718
* {@inheritdoc}
1819
*/
19-
public function resolveType(array $data)
20+
public function resolveType(array $data) : string
2021
{
2122
if (isset($data['type_id']) && $data['type_id'] == 'bundle') {
2223
return 'BundleProduct';
2324
}
25+
return '';
2426
}
2527
}

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

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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\BundleGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
11+
use Magento\BundleGraphQl\Model\Resolver\Links\Collection;
12+
use Magento\Framework\GraphQl\Config\Element\Field;
13+
use Magento\Framework\GraphQl\Query\Resolver\Value;
14+
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
15+
use Magento\Framework\GraphQl\Query\ResolverInterface;
16+
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
class BundleItemLinks implements ResolverInterface
21+
{
22+
/**
23+
* @var Collection
24+
*/
25+
private $linkCollection;
26+
27+
/**
28+
* @var ValueFactory
29+
*/
30+
private $valueFactory;
31+
32+
/**
33+
* @param Collection $linkCollection
34+
* @param ValueFactory $valueFactory
35+
*/
36+
public function __construct(
37+
Collection $linkCollection,
38+
ValueFactory $valueFactory
39+
) {
40+
$this->linkCollection = $linkCollection;
41+
$this->valueFactory = $valueFactory;
42+
}
43+
44+
/**
45+
* {@inheritDoc}
46+
*/
47+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) : Value
48+
{
49+
if (!isset($value['option_id']) || !isset($value['parent_id'])) {
50+
$result = function () {
51+
return null;
52+
};
53+
return $this->valueFactory->create($result);
54+
}
55+
$this->linkCollection->addIdFilters((int)$value['option_id'], (int)$value['parent_id']);
56+
$result = function () use ($value) {
57+
return $this->linkCollection->getLinksForOptionId((int)$value['option_id']);
58+
};
59+
60+
return $this->valueFactory->create($result);
61+
}
62+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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\BundleGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
11+
use Magento\Bundle\Model\Product\Type;
12+
use Magento\BundleGraphQl\Model\Resolver\Options\Collection;
13+
use Magento\Catalog\Api\Data\ProductInterface;
14+
use Magento\Framework\EntityManager\MetadataPool;
15+
use Magento\Framework\GraphQl\Config\Element\Field;
16+
use Magento\Framework\GraphQl\Query\Resolver\Value;
17+
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
18+
use Magento\Framework\GraphQl\Query\ResolverInterface;
19+
20+
/**
21+
* {@inheritdoc}
22+
*/
23+
class BundleItems implements ResolverInterface
24+
{
25+
/**
26+
* @var Collection
27+
*/
28+
private $bundleOptionCollection;
29+
30+
/**
31+
* @var ValueFactory
32+
*/
33+
private $valueFactory;
34+
35+
/**
36+
* @var MetadataPool
37+
*/
38+
private $metdataPool;
39+
40+
/**
41+
* @param Collection $bundleOptionCollection
42+
* @param ValueFactory $valueFactory
43+
* @param MetadataPool $metdataPool
44+
*/
45+
public function __construct(
46+
Collection $bundleOptionCollection,
47+
ValueFactory $valueFactory,
48+
MetadataPool $metdataPool
49+
) {
50+
$this->bundleOptionCollection = $bundleOptionCollection;
51+
$this->valueFactory = $valueFactory;
52+
$this->metdataPool = $metdataPool;
53+
}
54+
55+
/**
56+
* Fetch and format bundle option items.
57+
*
58+
* {@inheritDoc}
59+
*/
60+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) : Value
61+
{
62+
$linkField = $this->metdataPool->getMetadata(ProductInterface::class)->getLinkField();
63+
if ($value['type_id'] !== Type::TYPE_CODE
64+
|| !isset($value[$linkField])
65+
|| !isset($value[ProductInterface::SKU])
66+
) {
67+
$result = function () {
68+
return null;
69+
};
70+
return $this->valueFactory->create($result);
71+
}
72+
73+
$this->bundleOptionCollection->addParentFilterData(
74+
(int)$value[$linkField],
75+
(int)$value['entity_id'],
76+
$value[ProductInterface::SKU]
77+
);
78+
79+
$result = function () use ($value, $linkField) {
80+
return $this->bundleOptionCollection->getOptionsByParentId((int)$value[$linkField]);
81+
};
82+
83+
return $this->valueFactory->create($result);
84+
}
85+
}

0 commit comments

Comments
 (0)