Skip to content

Commit c484114

Browse files
committed
B2B-2677: [MediaGallery] Implement data caching for GraphQL results on resolver level
- Fix media gallery resolver cache invalidation on import when changing label on existing entry
1 parent 67556cf commit c484114

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

app/code/Magento/CatalogGraphQl/Observer/AfterImportDataObserver.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ public function __construct(
5555
public function execute(Observer $observer)
5656
{
5757
$mediaGalleryEntriesChanged = $observer->getEvent()->getMediaGallery();
58+
$mediaGalleryLabelsChanged = $observer->getEvent()->getMediaGalleryLabels();
5859

59-
if (empty($mediaGalleryEntriesChanged)) {
60+
if (empty($mediaGalleryEntriesChanged) &&
61+
empty($mediaGalleryLabelsChanged)
62+
) {
6063
return;
6164
}
6265

@@ -66,7 +69,11 @@ public function execute(Observer $observer)
6669
$productSkusToInvalidate[] = array_keys($productSkus);
6770
}
6871

69-
$productSkusToInvalidate = array_merge(...$productSkusToInvalidate);
72+
foreach ($mediaGalleryLabelsChanged as $label) {
73+
$productSkusToInvalidate[] = [$label['imageData']['sku']];
74+
}
75+
76+
$productSkusToInvalidate = array_unique(array_merge(...$productSkusToInvalidate));
7077
$products = $this->productRepository->getList(
7178
$this->criteriaBuilder->addFilter('sku', $productSkusToInvalidate, 'in')->create()
7279
)->getItems();

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,12 @@ protected function _saveProducts()
16941694
$this->_saveProductAttributes($attributes);
16951695
$this->_eventManager->dispatch(
16961696
'catalog_product_import_bunch_save_after',
1697-
['adapter' => $this, 'bunch' => $bunch, 'media_gallery' => $mediaGallery]
1697+
[
1698+
'adapter' => $this,
1699+
'bunch' => $bunch,
1700+
'media_gallery' => $mediaGallery,
1701+
'media_gallery_labels' => $labelsForUpdate,
1702+
]
16981703
);
16991704
}
17001705
return $this;

0 commit comments

Comments
 (0)