1212use Magento \Catalog \Api \Data \ProductInterface ;
1313use Magento \Catalog \Model \Product \Option as ProductOption ;
1414use Magento \Framework \DataObject ;
15+ use Magento \Framework \EntityManager \MetadataPool ;
16+ use Magento \Framework \App \ObjectManager ;
17+ use Magento \Ui \DataProvider \Modifier \PoolInterface ;
1518
1619/**
1720 * DataProvider for grid on Import Custom Options modal panel
@@ -39,6 +42,11 @@ class ProductCustomOptionsDataProvider extends ProductDataProvider
3942 */
4043 protected $ productOptionValueModel ;
4144
45+ /**
46+ * @var MetadataPool
47+ */
48+ private $ metadataPool ;
49+
4250 /**
4351 * @param string $name
4452 * @param string $primaryFieldName
@@ -51,6 +59,8 @@ class ProductCustomOptionsDataProvider extends ProductDataProvider
5159 * @param \Magento\Ui\DataProvider\AddFilterToCollectionInterface[] $addFilterStrategies
5260 * @param array $meta
5361 * @param array $data
62+ * @param PoolInterface|null $modifiersPool
63+ * @param MetadataPool|null $metadataPool
5464 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
5565 */
5666 public function __construct (
@@ -64,7 +74,9 @@ public function __construct(
6474 array $ addFieldStrategies = [],
6575 array $ addFilterStrategies = [],
6676 array $ meta = [],
67- array $ data = []
77+ array $ data = [],
78+ PoolInterface $ modifiersPool = null ,
79+ MetadataPool $ metadataPool = null
6880 ) {
6981 parent ::__construct (
7082 $ name ,
@@ -74,16 +86,19 @@ public function __construct(
7486 $ addFieldStrategies ,
7587 $ addFilterStrategies ,
7688 $ meta ,
77- $ data
89+ $ data ,
90+ $ modifiersPool
7891 );
7992
8093 $ this ->request = $ request ;
8194 $ this ->productOptionRepository = $ productOptionRepository ;
8295 $ this ->productOptionValueModel = $ productOptionValueModel ;
96+ $ this ->metadataPool = $ metadataPool ?: ObjectManager::getInstance ()
97+ ->get (MetadataPool::class);
8398 }
8499
85100 /**
86- * { @inheritdoc}
101+ * @inheritdoc
87102 * @since 101.0.0
88103 */
89104 public function getData ()
@@ -95,9 +110,16 @@ public function getData()
95110 $ this ->getCollection ()->getSelect ()->where ('e.entity_id != ? ' , $ currentProductId );
96111 }
97112
113+ try {
114+ $ entityMetadata = $ this ->metadataPool ->getMetadata (ProductInterface::class);
115+ $ linkField = $ entityMetadata ->getLinkField ();
116+ } catch (\Exception $ e ) {
117+ $ linkField = 'entity_id ' ;
118+ }
119+
98120 $ this ->getCollection ()->getSelect ()->distinct ()->join (
99121 ['opt ' => $ this ->getCollection ()->getTable ('catalog_product_option ' )],
100- 'opt.product_id = e.entity_id ' ,
122+ 'opt.product_id = e. ' . $ linkField ,
101123 null
102124 );
103125 $ this ->getCollection ()->load ();
0 commit comments