Skip to content

Commit bc0353d

Browse files
committed
B2B-2677: [MediaGallery]Implement data caching for GraphQL results on resolver level
- Load product from DB
1 parent 209ee51 commit bc0353d

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

app/code/Magento/CatalogGraphQl/Plugin/Product/UpdateIdentities.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\CatalogGraphQl\Plugin\Product;
99

10+
use Magento\Catalog\Api\ProductRepositoryInterface;
1011
use Magento\Catalog\Model\Product;
1112
use Magento\CatalogGraphQl\Model\Resolver\Cache\Product\MediaGallery\ResolverCacheIdentity;
1213
use Magento\Framework\Serialize\SerializerInterface;
@@ -17,16 +18,25 @@
1718
*/
1819
class UpdateIdentities
1920
{
21+
/**
22+
* @var ProductRepositoryInterface
23+
*/
24+
private $productRepository;
25+
2026
/**
2127
* @var SerializerInterface
2228
*/
2329
private $serializer;
2430

2531
/**
32+
* @param ProductRepositoryInterface $productRepository
2633
* @param SerializerInterface $serializer
2734
*/
28-
public function __construct(SerializerInterface $serializer)
29-
{
35+
public function __construct(
36+
ProductRepositoryInterface $productRepository,
37+
SerializerInterface $serializer
38+
) {
39+
$this->productRepository = $productRepository;
3040
$this->serializer = $serializer;
3141
}
3242

@@ -57,7 +67,12 @@ private function isMediaGalleryChanged(Product $product): bool
5767
return false;
5868
}
5969

60-
$mediaGalleryImages = $product->getMediaGallery('images') ?? [];
70+
$mediaGalleryImages = $this->productRepository->get(
71+
$product->getSku(),
72+
false,
73+
null,
74+
true
75+
)->getMediaGallery('images') ?? [];
6176

6277
$origMediaGalleryImages = $product->getOrigData('media_gallery')['images'] ?? [];
6378

0 commit comments

Comments
 (0)