7
7
8
8
namespace Magento \BundleGraphQl \Model \Resolver ;
9
9
10
- use Magento \Framework \Exception \LocalizedException ;
11
- use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
12
10
use Magento \BundleGraphQl \Model \Resolver \Links \Collection ;
11
+ use Magento \BundleGraphQl \Model \Resolver \Links \CollectionFactory ;
12
+ use Magento \Framework \App \ObjectManager ;
13
+ use Magento \Framework \Exception \LocalizedException ;
13
14
use Magento \Framework \GraphQl \Config \Element \Field ;
14
15
use Magento \Framework \GraphQl \Query \Resolver \ValueFactory ;
15
16
use Magento \Framework \GraphQl \Query \ResolverInterface ;
17
+ use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
16
18
17
19
/**
18
20
* @inheritdoc
19
21
*/
20
22
class BundleItemLinks implements ResolverInterface
21
23
{
22
24
/**
23
- * @var Collection
25
+ * @var CollectionFactory
24
26
*/
25
- private $ linkCollection ;
27
+ private CollectionFactory $ linkCollectionFactory ;
26
28
27
29
/**
28
30
* @var ValueFactory
29
31
*/
30
- private $ valueFactory ;
32
+ private ValueFactory $ valueFactory ;
31
33
32
34
/**
33
- * @param Collection $linkCollection
35
+ * @param Collection $linkCollection Deprecated. Use $linkCollectionFactory instead
34
36
* @param ValueFactory $valueFactory
37
+ * @param CollectionFactory|null $linkCollectionFactory
38
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
35
39
*/
36
40
public function __construct (
37
41
Collection $ linkCollection ,
38
- ValueFactory $ valueFactory
42
+ ValueFactory $ valueFactory ,
43
+ CollectionFactory $ linkCollectionFactory = null
39
44
) {
40
- $ this ->linkCollection = $ linkCollection ;
45
+ $ this ->linkCollectionFactory = $ linkCollectionFactory
46
+ ?: ObjectManager::getInstance ()->get (CollectionFactory::class);
41
47
$ this ->valueFactory = $ valueFactory ;
42
48
}
43
49
@@ -49,12 +55,11 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
49
55
if (!isset ($ value ['option_id ' ]) || !isset ($ value ['parent_id ' ])) {
50
56
throw new LocalizedException (__ ('"option_id" and "parent_id" values should be specified ' ));
51
57
}
52
-
53
- $ this -> linkCollection ->addIdFilters ((int )$ value ['option_id ' ], (int )$ value ['parent_id ' ]);
54
- $ result = function () use ($ value ) {
55
- return $ this -> linkCollection ->getLinksForOptionId ((int )$ value ['option_id ' ]);
58
+ $ linkCollection = $ this -> linkCollectionFactory -> create ();
59
+ $ linkCollection ->addIdFilters ((int )$ value ['option_id ' ], (int )$ value ['parent_id ' ]);
60
+ $ result = function () use ($ value, $ linkCollection ) {
61
+ return $ linkCollection ->getLinksForOptionId ((int )$ value ['option_id ' ]);
56
62
};
57
-
58
63
return $ this ->valueFactory ->create ($ result );
59
64
}
60
65
}
0 commit comments