1515use Magento \Framework \Exception \RuntimeException ;
1616use Magento \Framework \GraphQl \Query \EnumLookup ;
1717use Magento \Framework \GraphQl \Query \Uid ;
18- use Magento \Catalog \Api \ProductRepositoryInterface ;
1918use Zend_Db_Select_Exception ;
2019
2120/**
@@ -51,29 +50,20 @@ class Collection
5150 /** @var Uid */
5251 private $ uidEncoder ;
5352
54- /**
55- * @var ProductRepositoryInterface
56- */
57- private $ productRepository ;
58-
5953 /**
6054 * @param CollectionFactory $linkCollectionFactory
6155 * @param EnumLookup $enumLookup
6256 * @param Uid|null $uidEncoder
63- * @param ProductRepositoryInterface|null $productRepository
6457 */
6558 public function __construct (
6659 CollectionFactory $ linkCollectionFactory ,
6760 EnumLookup $ enumLookup ,
68- Uid $ uidEncoder = null ,
69- ?ProductRepositoryInterface $ productRepository = null
61+ Uid $ uidEncoder = null
7062 ) {
7163 $ this ->linkCollectionFactory = $ linkCollectionFactory ;
7264 $ this ->enumLookup = $ enumLookup ;
7365 $ this ->uidEncoder = $ uidEncoder ?: ObjectManager::getInstance ()
7466 ->get (Uid::class);
75- $ this ->productRepository = $ productRepository ?: ObjectManager::getInstance ()
76- ->get (ProductRepositoryInterface::class);
7767 }
7868
7969 /**
@@ -117,7 +107,6 @@ public function getLinksForOptionId(int $optionId) : array
117107 * Fetch link data and return in array format. Keys for links will be their option Ids.
118108 *
119109 * @return array
120- * @throws NoSuchEntityException
121110 * @throws RuntimeException
122111 * @throws Zend_Db_Select_Exception
123112 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
@@ -143,33 +132,26 @@ private function fetch() : array
143132
144133 /** @var Selection $link */
145134 foreach ($ linkCollection as $ link ) {
146- $ productDetails = [];
147135 $ 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 ()] = [];
172153 }
154+ $ this ->links [$ link ->getOptionId ()][] = $ data ;
173155 }
174156
175157 return $ this ->links ;
0 commit comments