15
15
use Magento \Framework \Exception \RuntimeException ;
16
16
use Magento \Framework \GraphQl \Query \EnumLookup ;
17
17
use Magento \Framework \GraphQl \Query \Uid ;
18
- use Magento \Catalog \Api \ProductRepositoryInterface ;
19
18
use Zend_Db_Select_Exception ;
20
19
21
20
/**
@@ -51,29 +50,20 @@ class Collection
51
50
/** @var Uid */
52
51
private $ uidEncoder ;
53
52
54
- /**
55
- * @var ProductRepositoryInterface
56
- */
57
- private $ productRepository ;
58
-
59
53
/**
60
54
* @param CollectionFactory $linkCollectionFactory
61
55
* @param EnumLookup $enumLookup
62
56
* @param Uid|null $uidEncoder
63
- * @param ProductRepositoryInterface|null $productRepository
64
57
*/
65
58
public function __construct (
66
59
CollectionFactory $ linkCollectionFactory ,
67
60
EnumLookup $ enumLookup ,
68
- Uid $ uidEncoder = null ,
69
- ?ProductRepositoryInterface $ productRepository = null
61
+ Uid $ uidEncoder = null
70
62
) {
71
63
$ this ->linkCollectionFactory = $ linkCollectionFactory ;
72
64
$ this ->enumLookup = $ enumLookup ;
73
65
$ this ->uidEncoder = $ uidEncoder ?: ObjectManager::getInstance ()
74
66
->get (Uid::class);
75
- $ this ->productRepository = $ productRepository ?: ObjectManager::getInstance ()
76
- ->get (ProductRepositoryInterface::class);
77
67
}
78
68
79
69
/**
@@ -117,7 +107,6 @@ public function getLinksForOptionId(int $optionId) : array
117
107
* Fetch link data and return in array format. Keys for links will be their option Ids.
118
108
*
119
109
* @return array
120
- * @throws NoSuchEntityException
121
110
* @throws RuntimeException
122
111
* @throws Zend_Db_Select_Exception
123
112
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
@@ -143,33 +132,26 @@ private function fetch() : array
143
132
144
133
/** @var Selection $link */
145
134
foreach ($ linkCollection as $ link ) {
146
- $ productDetails = [];
147
135
$ data = $ link ->getData ();
148
- if (isset ($ data ['product_id ' ])) {
149
- $ productDetails = $ this ->productRepository ->getById ($ data ['product_id ' ]);
150
- }
151
-
152
- if ($ productDetails && $ productDetails ->getIsSalable ()) {
153
- $ formattedLink = [
154
- 'price ' => $ link ->getSelectionPriceValue (),
155
- 'position ' => $ link ->getPosition (),
156
- 'id ' => $ link ->getSelectionId (),
157
- 'uid ' => $ this ->uidEncoder ->encode ((string )$ link ->getSelectionId ()),
158
- 'qty ' => (float )$ link ->getSelectionQty (),
159
- 'quantity ' => (float )$ link ->getSelectionQty (),
160
- 'is_default ' => (bool )$ link ->getIsDefault (),
161
- 'price_type ' => $ this ->enumLookup ->getEnumValueFromField (
162
- 'PriceTypeEnum ' ,
163
- (string )$ link ->getSelectionPriceType ()
164
- ) ?: 'DYNAMIC ' ,
165
- 'can_change_quantity ' => $ link ->getSelectionCanChangeQty (),
166
- ];
167
- $ data = array_replace ($ data , $ formattedLink );
168
- if (!isset ($ this ->links [$ link ->getOptionId ()])) {
169
- $ this ->links [$ link ->getOptionId ()] = [];
170
- }
171
- $ this ->links [$ link ->getOptionId ()][] = $ data ;
136
+ $ formattedLink = [
137
+ 'price ' => $ link ->getSelectionPriceValue (),
138
+ 'position ' => $ link ->getPosition (),
139
+ 'id ' => $ link ->getSelectionId (),
140
+ 'uid ' => $ this ->uidEncoder ->encode ((string )$ link ->getSelectionId ()),
141
+ 'qty ' => (float )$ link ->getSelectionQty (),
142
+ 'quantity ' => (float )$ link ->getSelectionQty (),
143
+ 'is_default ' => (bool )$ link ->getIsDefault (),
144
+ 'price_type ' => $ this ->enumLookup ->getEnumValueFromField (
145
+ 'PriceTypeEnum ' ,
146
+ (string )$ link ->getSelectionPriceType ()
147
+ ) ?: 'DYNAMIC ' ,
148
+ 'can_change_quantity ' => $ link ->getSelectionCanChangeQty (),
149
+ ];
150
+ $ data = array_replace ($ data , $ formattedLink );
151
+ if (!isset ($ this ->links [$ link ->getOptionId ()])) {
152
+ $ this ->links [$ link ->getOptionId ()] = [];
172
153
}
154
+ $ this ->links [$ link ->getOptionId ()][] = $ data ;
173
155
}
174
156
175
157
return $ this ->links ;
0 commit comments