8
8
9
9
use Magento \Catalog \Api \Data \ProductInterface ;
10
10
use Magento \Catalog \Api \ProductRepositoryInterface ;
11
+ use Magento \Framework \App \ObjectManager ;
11
12
use Magento \Framework \Exception \CouldNotSaveException ;
12
13
use Magento \Framework \Exception \InputException ;
13
14
use Magento \Framework \Model \Entity \MetadataPool ;
@@ -50,7 +51,7 @@ class LinkManagement implements \Magento\Bundle\Api\ProductLinkManagementInterfa
50
51
/**
51
52
* @var MetadataPool
52
53
*/
53
- protected $ metadataPool ;
54
+ private $ metadataPool ;
54
55
55
56
/**
56
57
* @param ProductRepositoryInterface $productRepository
@@ -60,7 +61,6 @@ class LinkManagement implements \Magento\Bundle\Api\ProductLinkManagementInterfa
60
61
* @param \Magento\Bundle\Model\ResourceModel\Option\CollectionFactory $optionCollection
61
62
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
62
63
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
63
- * @param MetadataPool $metadataPool
64
64
*/
65
65
public function __construct (
66
66
ProductRepositoryInterface $ productRepository ,
@@ -69,8 +69,7 @@ public function __construct(
69
69
\Magento \Bundle \Model \ResourceModel \BundleFactory $ bundleFactory ,
70
70
\Magento \Bundle \Model \ResourceModel \Option \CollectionFactory $ optionCollection ,
71
71
\Magento \Store \Model \StoreManagerInterface $ storeManager ,
72
- \Magento \Framework \Api \DataObjectHelper $ dataObjectHelper ,
73
- MetadataPool $ metadataPool
72
+ \Magento \Framework \Api \DataObjectHelper $ dataObjectHelper
74
73
) {
75
74
$ this ->productRepository = $ productRepository ;
76
75
$ this ->linkFactory = $ linkFactory ;
@@ -79,7 +78,6 @@ public function __construct(
79
78
$ this ->optionCollection = $ optionCollection ;
80
79
$ this ->storeManager = $ storeManager ;
81
80
$ this ->dataObjectHelper = $ dataObjectHelper ;
82
- $ this ->metadataPool = $ metadataPool ;
83
81
}
84
82
85
83
/**
@@ -147,7 +145,7 @@ public function saveChild(
147
145
if (!$ selectionModel ->getId ()) {
148
146
throw new InputException (__ ('Can not find product link with id "%1" ' , [$ linkedProduct ->getId ()]));
149
147
}
150
- $ linkField = $ this ->metadataPool ->getMetadata (ProductInterface::class)->getLinkField ();
148
+ $ linkField = $ this ->getMetadataPool () ->getMetadata (ProductInterface::class)->getLinkField ();
151
149
$ selectionModel = $ this ->mapProductLinkToSelectionModel (
152
150
$ selectionModel ,
153
151
$ linkedProduct ,
@@ -231,7 +229,7 @@ public function addChild(
231
229
);
232
230
}
233
231
234
- $ linkField = $ this ->metadataPool ->getMetadata (ProductInterface::class)->getLinkField ();
232
+ $ linkField = $ this ->getMetadataPool () ->getMetadata (ProductInterface::class)->getLinkField ();
235
233
/* @var $resource \Magento\Bundle\Model\ResourceModel\Bundle */
236
234
$ resource = $ this ->bundleFactory ->create ();
237
235
$ selections = $ resource ->getSelectionsData ($ product ->getData ($ linkField ));
@@ -303,7 +301,7 @@ public function removeChild($sku, $optionId, $childSku)
303
301
__ ('Requested bundle option product doesn \'t exist ' )
304
302
);
305
303
}
306
- $ linkField = $ this ->metadataPool ->getMetadata (ProductInterface::class)->getLinkField ();
304
+ $ linkField = $ this ->getMetadataPool () ->getMetadata (ProductInterface::class)->getLinkField ();
307
305
/* @var $resource \Magento\Bundle\Model\ResourceModel\Bundle */
308
306
$ resource = $ this ->bundleFactory ->create ();
309
307
$ resource ->dropAllUnneededSelections ($ product ->getData ($ linkField ), $ excludeSelectionIds );
@@ -366,4 +364,16 @@ private function getOptions(\Magento\Catalog\Api\Data\ProductInterface $product)
366
364
$ options = $ optionCollection ->appendSelections ($ selectionCollection );
367
365
return $ options ;
368
366
}
367
+
368
+ /**
369
+ * Get MetadataPool instance
370
+ * @return MetadataPool
371
+ */
372
+ private function getMetadataPool ()
373
+ {
374
+ if (!$ this ->metadataPool ) {
375
+ $ this ->metadataPool = ObjectManager::getInstance ()->get (MetadataPool::class);
376
+ }
377
+ return $ this ->metadataPool ;
378
+ }
369
379
}
0 commit comments