Closed
Description
Using Media Image custom attribute type could not display on frontend.
Preconditions (*)
- Magento Community Edition V2.2.6 with sample data (PHP 7.0)
Steps to reproduce (*)
- Create custom attribute named 'icon_image' of product from admin.
- Set attribute type Media Image.
- assign icon_image attribute in attribute set.
- Update product image and set new role 'icon_image'.
- Create custom code for displaying image in front end. code is like:
Sample code: 1
$productImageAttr = $product->getCustomAttribute( 'icon_image' );
$productImage = $this->helper('Magento\Catalog\Helper\Image')
->init($product, 'icon_image')
->setImageFile($productImageAttr->getValue());
<img src="<?php echo $productImage->getUrl() ?>" alt="<?php echo $block->escapeHtml($product->getTitle()) ?>" />
Sample code:2
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$mediaUrl = $objectManager->get('Magento\Store\Model\StoreManagerInterface')
->getStore()
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
$diamondIcon=$product->getResource()->getAttribute('diamond_icon')->getFrontend()->getValue($product);
<img src=" <?php echo $mediaUrl."catalog/product".$diamondIcon ?>" />
Expected result (*)
- Custom image / media type custom attribute should be display on frontend.
Actual result (*)
- Custom image / media type custom attribute is not displayed on frontend anymore.