Skip to content

Cannot use Catalog ImageBuilder for custom product image attribute #10161

@erfanimani

Description

@erfanimani

Preconditions

  1. Magento 2.1.7

Steps to reproduce

  1. Create product attribute with input type media image, and attribute code "side_image" for example
  2. Create a new product, add a few images, and select the role of one of the images to be the "side_image"
  3. In our template we want to show the side image (using the block \Magento\Catalog\Block\Product\View). Therefore we're adding the following code:
<?php /** @var $block \Magento\Catalog\Block\Product\View */ ?>
<?php
    $product = $block->getProduct();

    $image = $block->getImage(
        $product,
        'product_page_image_medium',
        ['type' => 'side_image']
    );
?>

<img src="<?php echo $image->getImageUrl() ?>" />

Expected result

  1. Product side image shows up

Actual result

  1. Product base image shows up

A stack exchange question related to this bug can be found here: https://magento.stackexchange.com/questions/102498/extending-the-complextype-named-imagetype-with-a-custom-image-type

Essentially, without having to specify the third parameter, one would expect to create new image types by adding them into the view.xml, like this:

    $image = $block->getImage(
        $product,
        'my_custom_image_id_with_custom_product_image_type'
    );

.. however, that's not possible given XSD validation, and hence devs are trying to overwrite the core XSD to simply add their own image types.

The problem here, however, is that the third parameter gets discarded along the way, and that definitely seems like a bug to me.

On top of that, the fact that it's not possible to add image types definitely seems like a design flaw, and maybe the XSD shouldn't be this strict.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions