Skip to content

Commit 9a22997

Browse files
committed
#27948: Returned metadata pool
1 parent c80630b commit 9a22997

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

app/code/Magento/MediaContentCatalog/Observer/Category.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
namespace Magento\MediaContentCatalog\Observer;
99

10+
use Magento\Catalog\Api\Data\CategoryInterface;
1011
use Magento\Catalog\Model\Category as CatalogCategory;
12+
use Magento\Framework\EntityManager\MetadataPool;
1113
use Magento\Framework\Event\Observer;
1214
use Magento\Framework\Event\ObserverInterface;
1315
use Magento\MediaContentApi\Api\UpdateContentAssetLinksInterface;
@@ -44,6 +46,11 @@ class Category implements ObserverInterface
4446
*/
4547
private $getContent;
4648

49+
/**
50+
* @var MetadataPool
51+
*/
52+
private $metadataPool;
53+
4754
/**
4855
* @param ContentIdentityInterfaceFactory $contentIdentityFactory
4956
* @param GetContent $getContent
@@ -54,11 +61,13 @@ public function __construct(
5461
ContentIdentityInterfaceFactory $contentIdentityFactory,
5562
GetContent $getContent,
5663
UpdateContentAssetLinksInterface $updateContentAssetLinks,
64+
MetadataPool $metadataPool,
5765
array $fields
5866
) {
5967
$this->contentIdentityFactory = $contentIdentityFactory;
6068
$this->getContent = $getContent;
6169
$this->updateContentAssetLinks = $updateContentAssetLinks;
70+
$this->metadataPool = $metadataPool;
6271
$this->fields = $fields;
6372
}
6473

@@ -73,6 +82,7 @@ public function execute(Observer $observer): void
7382
$model = $observer->getEvent()->getData('category');
7483

7584
if ($model instanceof CatalogCategory) {
85+
$id = (int) $model->getData($this->metadataPool->getMetadata(CategoryInterface::class)->getLinkField());
7686
foreach ($this->fields as $field) {
7787
if (!$model->dataHasChangedFor($field)) {
7888
continue;
@@ -85,7 +95,7 @@ public function execute(Observer $observer): void
8595
self::ENTITY_ID => (string) $model->getId(),
8696
]
8797
),
88-
$this->getContent->execute((int) $model->getId(), $model->getAttributes()[$field])
98+
$this->getContent->execute($id, $model->getAttributes()[$field])
8999
);
90100
}
91101
}

app/code/Magento/MediaContentCatalog/Observer/Product.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
namespace Magento\MediaContentCatalog\Observer;
99

10+
use Magento\Catalog\Api\Data\ProductInterface;
1011
use Magento\Catalog\Model\Product as CatalogProduct;
12+
use Magento\Framework\EntityManager\MetadataPool;
1113
use Magento\Framework\Event\Observer;
1214
use Magento\Framework\Event\ObserverInterface;
1315
use Magento\MediaContentApi\Api\UpdateContentAssetLinksInterface;
@@ -44,6 +46,11 @@ class Product implements ObserverInterface
4446
*/
4547
private $getContent;
4648

49+
/**
50+
* @var MetadataPool
51+
*/
52+
private $metadataPool;
53+
4754
/**
4855
* @param ContentIdentityInterfaceFactory $contentIdentityFactory
4956
* @param GetContent $getContent
@@ -54,11 +61,13 @@ public function __construct(
5461
ContentIdentityInterfaceFactory $contentIdentityFactory,
5562
GetContent $getContent,
5663
UpdateContentAssetLinksInterface $updateContentAssetLinks,
64+
MetadataPool $metadataPool,
5765
array $fields
5866
) {
5967
$this->contentIdentityFactory = $contentIdentityFactory;
6068
$this->getContent = $getContent;
6169
$this->updateContentAssetLinks = $updateContentAssetLinks;
70+
$this->metadataPool = $metadataPool;
6271
$this->fields = $fields;
6372
}
6473

@@ -73,6 +82,7 @@ public function execute(Observer $observer): void
7382
$model = $observer->getEvent()->getData('product');
7483

7584
if ($model instanceof CatalogProduct) {
85+
$id = (int) $model->getData($this->metadataPool->getMetadata(ProductInterface::class)->getLinkField());
7686
foreach ($this->fields as $field) {
7787
if (!$model->dataHasChangedFor($field)) {
7888
continue;
@@ -85,7 +95,7 @@ public function execute(Observer $observer): void
8595
self::ENTITY_ID => (string) $model->getId(),
8696
]
8797
),
88-
$this->getContent->execute((int) $model->getId(), $model->getAttributes()[$field])
98+
$this->getContent->execute($id, $model->getAttributes()[$field])
8999
);
90100
}
91101
}

dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetContentTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
namespace Magento\MediaContentCatalog\Model\ResourceModel;
1010

11+
use Magento\Catalog\Api\Data\ProductInterface;
1112
use Magento\Catalog\Api\ProductRepositoryInterface;
13+
use Magento\Framework\EntityManager\MetadataPool;
1214
use Magento\TestFramework\Helper\Bootstrap;
1315
use PHPUnit\Framework\TestCase;
1416

@@ -27,6 +29,11 @@ class GetContentTest extends TestCase
2729
*/
2830
private $productRepository;
2931

32+
/**
33+
* @var MetadataPool
34+
*/
35+
private $metadataPool;
36+
3037
/**
3138
* @inheritdoc
3239
*/
@@ -35,6 +42,7 @@ public function setUp(): void
3542
$objectManager = Bootstrap::getObjectManager();
3643
$this->getContent = $objectManager->get(GetContent::class);
3744
$this->productRepository = $objectManager->get(ProductRepositoryInterface::class);
45+
$this->metadataPool = $objectManager->get(MetadataPool::class);
3846
}
3947

4048
/**
@@ -45,9 +53,10 @@ public function setUp(): void
4553
public function testProduct(): void
4654
{
4755
$product = $this->productRepository->get('simple');
56+
$id = (int) $product->getData($this->metadataPool->getMetadata(ProductInterface::class)->getLinkField());
4857
$this->assertEquals(
4958
'Description with <b>html tag</b>',
50-
$this->getContent->execute((int) $product->getId(), $product->getAttributes()['description'])
59+
$this->getContent->execute($id, $product->getAttributes()['description'])
5160
);
5261
}
5362

@@ -59,9 +68,10 @@ public function testProduct(): void
5968
public function testProductTwoWebsites(): void
6069
{
6170
$product = $this->productRepository->get('simple-on-two-websites-different-description');
71+
$id = (int) $product->getData($this->metadataPool->getMetadata(ProductInterface::class)->getLinkField());
6272
$this->assertEquals(
6373
'<p>Product base description</p>' . PHP_EOL . '<p>Product second description</p>',
64-
$this->getContent->execute((int) $product->getId(), $product->getAttributes()['description'])
74+
$this->getContent->execute($id, $product->getAttributes()['description'])
6575
);
6676
}
6777
}

0 commit comments

Comments
 (0)