Magento2: how to get product video by product id or sku?
-
09-10-2020 - |
質問
I've tried to get video on product page on other place not on gallery. But i can't retrieve it. I've seen it stored on catalog_product_entity_media_gallery_value_video
I want to get it proper not direct query. anybody knows proper way?
解決
I suggest you to use $product->getMediaGalleryImages()
$galleryImages = $product->getMediaGalleryImages();
if ($galleryImages) {
foreach ($galleryImages as $image) {
$imageData = $image->getData();
// Check media type
if (isset($imageData['media_type']) && $imageData['media_type'] == 'external-video') {
// Your code here
}
}
}
所属していません magento.stackexchange