Skip to content

Using Media Image custom attribute type could not display on frontend.  #19054

Closed
@nimitaemipro

Description

@nimitaemipro

Using Media Image custom attribute type could not display on frontend.

Preconditions (*)

  1. Magento Community Edition V2.2.6 with sample data (PHP 7.0)

Steps to reproduce (*)

  1. Create custom attribute named 'icon_image' of product from admin.
  2. Set attribute type Media Image.
  3. assign icon_image attribute in attribute set.
  4. Update product image and set new role 'icon_image'.
  5. 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 (*)

  1. Custom image / media type custom attribute should be display on frontend.

Actual result (*)

  1. Custom image / media type custom attribute is not displayed on frontend anymore.

Metadata

Metadata

Assignees

Labels

Component: EavFixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: Format is validGate 1 Passed. Automatic verification of issue format passed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions