Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
EntryResolver.php
Go to the documentation of this file.
1 <?php
9 
11 
13 {
21  public function getEntryFilePathById(Product $product, $entryId)
22  {
23  $mediaGalleryData = $product->getData('media_gallery');
24  if (!isset($mediaGalleryData['images']) || !is_array($mediaGalleryData['images'])) {
25  return null;
26  }
27 
28  foreach ($mediaGalleryData['images'] as $image) {
29  if (isset($image['value_id']) && $image['value_id'] == $entryId) {
30  return isset($image['file']) ? $image['file'] : null;
31  }
32  }
33  return null;
34  }
35 
43  public function getEntryIdByFilePath(Product $product, $filePath)
44  {
45  $mediaGalleryData = $product->getData('media_gallery');
46  if (!isset($mediaGalleryData['images']) || !is_array($mediaGalleryData['images'])) {
47  return null;
48  }
49 
50  foreach ($mediaGalleryData['images'] as $image) {
51  if (isset($image['file']) && $image['file'] == $filePath) {
52  return isset($image['value_id']) ? $image['value_id'] : null;
53  }
54  }
55  return null;
56  }
57 }
getEntryFilePathById(Product $product, $entryId)
getEntryIdByFilePath(Product $product, $filePath)