Skip to content

Commit 7ea95b3

Browse files
committed
Merge remote-tracking branch 'origin/MC-29677' into 2.4-develop-pr5
2 parents 666e37e + e248c24 commit 7ea95b3

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/ProductCustomOptionsDataProviderTest.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use Magento\Framework\App\RequestInterface;
1212
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
1313
use Magento\Framework\DB\Select as DbSelect;
14+
use Magento\Framework\EntityManager\MetadataPool;
15+
use Magento\Framework\EntityManager\EntityMetadataInterface;
16+
use Magento\Ui\DataProvider\Modifier\PoolInterface;
1417

1518
class ProductCustomOptionsDataProviderTest extends \PHPUnit\Framework\TestCase
1619
{
@@ -44,6 +47,21 @@ class ProductCustomOptionsDataProviderTest extends \PHPUnit\Framework\TestCase
4447
*/
4548
protected $dbSelectMock;
4649

50+
/**
51+
* @var MetadataPool|\PHPUnit_Framework_MockObject_MockObject
52+
*/
53+
private $metadataPool;
54+
55+
/**
56+
* @var EntityMetadataInterface|\PHPUnit_Framework_MockObject_MockObject
57+
*/
58+
private $entityMetadata;
59+
60+
/**
61+
* @var PoolInterface|\PHPUnit_Framework_MockObject_MockObject
62+
*/
63+
private $modifiersPool;
64+
4765
protected function setUp()
4866
{
4967
$this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)
@@ -73,12 +91,29 @@ protected function setUp()
7391
->method('create')
7492
->willReturn($this->collectionMock);
7593

94+
$this->modifiersPool = $this->getMockBuilder(PoolInterface::class)
95+
->getMockForAbstractClass();
96+
$this->entityMetadata = $this->getMockBuilder(EntityMetadataInterface::class)
97+
->getMockForAbstractClass();
98+
$this->entityMetadata->expects($this->any())
99+
->method('getLinkField')
100+
->willReturn('entity_id');
101+
$this->metadataPool = $this->getMockBuilder(MetadataPool::class)
102+
->disableOriginalConstructor()
103+
->setMethods(['getMetadata'])
104+
->getMock();
105+
$this->metadataPool->expects($this->any())
106+
->method('getMetadata')
107+
->willReturn($this->entityMetadata);
108+
76109
$this->objectManagerHelper = new ObjectManagerHelper($this);
77110
$this->dataProvider = $this->objectManagerHelper->getObject(
78111
ProductCustomOptionsDataProvider::class,
79112
[
80113
'collectionFactory' => $this->collectionFactoryMock,
81-
'request' => $this->requestMock
114+
'request' => $this->requestMock,
115+
'modifiersPool' => $this->modifiersPool,
116+
'metadataPool' => $this->metadataPool
82117
]
83118
);
84119
}

app/code/Magento/Catalog/Ui/DataProvider/Product/ProductCustomOptionsDataProvider.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
use Magento\Catalog\Api\Data\ProductInterface;
1313
use Magento\Catalog\Model\Product\Option as ProductOption;
1414
use 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

Comments
 (0)