Getting a custom attribute imageCustom image attribute is not displayed on search listMagento Checkout Cart...
When was drinking water recognized as crucial in marathon running?
What is this waxed root vegetable?
Test pad's ESD protection
In Adventurer's League, is it possible to keep the Ring of Winter if you manage to acquire it in the Tomb of Annihilation adventure?
Borrowing Characters
Are there any other Chaos-worshipping races?
Toast materialize
Is there any relevance to Thor getting his hair cut other than comedic value?
Can we carry rice to Japan?
Starting index at zero
What are the issues with an additional (limited) concentration slot instead of Bladesong?
What is a term for a function that when called repeatedly, has the same effect as calling once?
What happened to QGIS 2.x LTR?
Where is the fallacy here?
Source for Cremation Specifically Not Jewish
Calculating Hyperbolic Sin faster than using a standard power series
What is the difference between a forward slip and a side slip?
Should we avoid writing fiction about historical events without extensive research?
School performs periodic password audits. Is my password compromised?
The need of reserving one's ability in job interviews
Is divide-by-zero a security vulnerability?
How to mitigate "bandwagon attacking" from players?
Are paired adjectives bad style?
Where is the line between being obedient and getting bullied by a boss?
Getting a custom attribute image
Custom image attribute is not displayed on search listMagento Checkout Cart Image Thumbnail Resize White Frame/BorderGetting resulting size of Catalog Image Helper resize functionHow do I stop the Magento cache increasing image filesize?Storeviews not showing the same product image after importReceive Magento Logo when getting product imageGet product attribute in cart in Magento2Magento 2 product image custom resizeUse same image on 2 products from same image fileMagento 2 product image gallery not responsive/resizing
Magento 2 question here:
I've made a custom attribute (media type) with the name of 'bike_range_image', and tried googling and searching in the core and everything I could to get the image with a custom size and such, but can't find the right approach.
I can get it as text, but obviously that's not enough, so this won't cut it:
$productImage = $product->getCustomAttribute( 'bike_range_image' );
Now, some examples in themes that are out there suggest I do this:
$this->helper('MagentoCatalogHelperImage')->init($product, 'bike_range_image');
But this gives me an enormous MagentoCatalogHelperImage object that doesn't seem to have the right data. (I've got the right product if you're wondering).
Does anyone have some pointers for me?
magento2 image product-images
add a comment |
Magento 2 question here:
I've made a custom attribute (media type) with the name of 'bike_range_image', and tried googling and searching in the core and everything I could to get the image with a custom size and such, but can't find the right approach.
I can get it as text, but obviously that's not enough, so this won't cut it:
$productImage = $product->getCustomAttribute( 'bike_range_image' );
Now, some examples in themes that are out there suggest I do this:
$this->helper('MagentoCatalogHelperImage')->init($product, 'bike_range_image');
But this gives me an enormous MagentoCatalogHelperImage object that doesn't seem to have the right data. (I've got the right product if you're wondering).
Does anyone have some pointers for me?
magento2 image product-images
add a comment |
Magento 2 question here:
I've made a custom attribute (media type) with the name of 'bike_range_image', and tried googling and searching in the core and everything I could to get the image with a custom size and such, but can't find the right approach.
I can get it as text, but obviously that's not enough, so this won't cut it:
$productImage = $product->getCustomAttribute( 'bike_range_image' );
Now, some examples in themes that are out there suggest I do this:
$this->helper('MagentoCatalogHelperImage')->init($product, 'bike_range_image');
But this gives me an enormous MagentoCatalogHelperImage object that doesn't seem to have the right data. (I've got the right product if you're wondering).
Does anyone have some pointers for me?
magento2 image product-images
Magento 2 question here:
I've made a custom attribute (media type) with the name of 'bike_range_image', and tried googling and searching in the core and everything I could to get the image with a custom size and such, but can't find the right approach.
I can get it as text, but obviously that's not enough, so this won't cut it:
$productImage = $product->getCustomAttribute( 'bike_range_image' );
Now, some examples in themes that are out there suggest I do this:
$this->helper('MagentoCatalogHelperImage')->init($product, 'bike_range_image');
But this gives me an enormous MagentoCatalogHelperImage object that doesn't seem to have the right data. (I've got the right product if you're wondering).
Does anyone have some pointers for me?
magento2 image product-images
magento2 image product-images
asked Mar 10 '16 at 17:20
TommyKTommyK
3414
3414
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
I guess you want to do it in .phtml file. Try this way
<?php
$productImageAttr = $product->getCustomAttribute( 'bike_range_image' );
$productImage = $this->helper('MagentoCatalogHelperImage')
->init($product, 'bike_range_image')
->setImageFile($productImageAttr->getValue());
?>
and then in img tag
<img src="<?php echo $productImage->getUrl() ?>" alt="<?php echo $block->escapeHtml($product->getTitle()) ?>" />
The image size can be defined in xml file, for example view.xml
<media>
<images module="Magento_Catalog">
<image id="bike_range_image" type="thumbnail">
<width>100</width>
<height>100</height>
</image>
</images>
</media>
It was a while ago, but yes, ended up doing it like this. I can't vote it up yet, so please someone else do it!
– TommyK
Jul 15 '16 at 15:10
$product->getCustomAttribute('bike_range_image')
is NULL in catalog category pages when$product
is loaded from$block->getLoadedProductCollection()
– LucScu
Oct 18 '17 at 9:33
add a comment |
Use the following code:
$value = $_product->getCustomImage();
if(isset($value) && $value != 'no_selection'):
$imageUrl = Mage::getHelper('catalog/image')->init($_product,'custom_image');
echo "<img src='".$imageUrl."' />";
endif;
That is Magento 1 code, but still I managed to get it like that:$value = $product->getBikeRangeImage();
However, this is not working yet:$value = $product->getBikeRangeImage(); if( isset($value) && $value != 'no_selection' ): echo $this->helper( 'MagentoCatalogHelperImage' )->init( $product, 'bike_range_image' )->resize( 310 ); endif;
That gives me an error saying it returns an object rather than an url as it should. Any idea?
– TommyK
Mar 14 '16 at 14:51
can anyone shed a light to how I can call an image for a drop-down attribute? Thank you
– roger
Oct 18 '16 at 16:55
add a comment |
You can do this trick mentioned here:
https://stackoverflow.com/questions/34082459/magento2-add-product-attribute-as-media-image
but with one thing that isn't mentioned there is you will be able to just do: $_product->getAttributeCode()
it will work and give you the value.
As doing this
$product->getCustomAttribute( 'attribute_code' )->getValue()
will return null;
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f105677%2fgetting-a-custom-attribute-image%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I guess you want to do it in .phtml file. Try this way
<?php
$productImageAttr = $product->getCustomAttribute( 'bike_range_image' );
$productImage = $this->helper('MagentoCatalogHelperImage')
->init($product, 'bike_range_image')
->setImageFile($productImageAttr->getValue());
?>
and then in img tag
<img src="<?php echo $productImage->getUrl() ?>" alt="<?php echo $block->escapeHtml($product->getTitle()) ?>" />
The image size can be defined in xml file, for example view.xml
<media>
<images module="Magento_Catalog">
<image id="bike_range_image" type="thumbnail">
<width>100</width>
<height>100</height>
</image>
</images>
</media>
It was a while ago, but yes, ended up doing it like this. I can't vote it up yet, so please someone else do it!
– TommyK
Jul 15 '16 at 15:10
$product->getCustomAttribute('bike_range_image')
is NULL in catalog category pages when$product
is loaded from$block->getLoadedProductCollection()
– LucScu
Oct 18 '17 at 9:33
add a comment |
I guess you want to do it in .phtml file. Try this way
<?php
$productImageAttr = $product->getCustomAttribute( 'bike_range_image' );
$productImage = $this->helper('MagentoCatalogHelperImage')
->init($product, 'bike_range_image')
->setImageFile($productImageAttr->getValue());
?>
and then in img tag
<img src="<?php echo $productImage->getUrl() ?>" alt="<?php echo $block->escapeHtml($product->getTitle()) ?>" />
The image size can be defined in xml file, for example view.xml
<media>
<images module="Magento_Catalog">
<image id="bike_range_image" type="thumbnail">
<width>100</width>
<height>100</height>
</image>
</images>
</media>
It was a while ago, but yes, ended up doing it like this. I can't vote it up yet, so please someone else do it!
– TommyK
Jul 15 '16 at 15:10
$product->getCustomAttribute('bike_range_image')
is NULL in catalog category pages when$product
is loaded from$block->getLoadedProductCollection()
– LucScu
Oct 18 '17 at 9:33
add a comment |
I guess you want to do it in .phtml file. Try this way
<?php
$productImageAttr = $product->getCustomAttribute( 'bike_range_image' );
$productImage = $this->helper('MagentoCatalogHelperImage')
->init($product, 'bike_range_image')
->setImageFile($productImageAttr->getValue());
?>
and then in img tag
<img src="<?php echo $productImage->getUrl() ?>" alt="<?php echo $block->escapeHtml($product->getTitle()) ?>" />
The image size can be defined in xml file, for example view.xml
<media>
<images module="Magento_Catalog">
<image id="bike_range_image" type="thumbnail">
<width>100</width>
<height>100</height>
</image>
</images>
</media>
I guess you want to do it in .phtml file. Try this way
<?php
$productImageAttr = $product->getCustomAttribute( 'bike_range_image' );
$productImage = $this->helper('MagentoCatalogHelperImage')
->init($product, 'bike_range_image')
->setImageFile($productImageAttr->getValue());
?>
and then in img tag
<img src="<?php echo $productImage->getUrl() ?>" alt="<?php echo $block->escapeHtml($product->getTitle()) ?>" />
The image size can be defined in xml file, for example view.xml
<media>
<images module="Magento_Catalog">
<image id="bike_range_image" type="thumbnail">
<width>100</width>
<height>100</height>
</image>
</images>
</media>
answered Jul 14 '16 at 12:26
Jaanek LiiskmaaJaanek Liiskmaa
18114
18114
It was a while ago, but yes, ended up doing it like this. I can't vote it up yet, so please someone else do it!
– TommyK
Jul 15 '16 at 15:10
$product->getCustomAttribute('bike_range_image')
is NULL in catalog category pages when$product
is loaded from$block->getLoadedProductCollection()
– LucScu
Oct 18 '17 at 9:33
add a comment |
It was a while ago, but yes, ended up doing it like this. I can't vote it up yet, so please someone else do it!
– TommyK
Jul 15 '16 at 15:10
$product->getCustomAttribute('bike_range_image')
is NULL in catalog category pages when$product
is loaded from$block->getLoadedProductCollection()
– LucScu
Oct 18 '17 at 9:33
It was a while ago, but yes, ended up doing it like this. I can't vote it up yet, so please someone else do it!
– TommyK
Jul 15 '16 at 15:10
It was a while ago, but yes, ended up doing it like this. I can't vote it up yet, so please someone else do it!
– TommyK
Jul 15 '16 at 15:10
$product->getCustomAttribute('bike_range_image')
is NULL in catalog category pages when $product
is loaded from $block->getLoadedProductCollection()
– LucScu
Oct 18 '17 at 9:33
$product->getCustomAttribute('bike_range_image')
is NULL in catalog category pages when $product
is loaded from $block->getLoadedProductCollection()
– LucScu
Oct 18 '17 at 9:33
add a comment |
Use the following code:
$value = $_product->getCustomImage();
if(isset($value) && $value != 'no_selection'):
$imageUrl = Mage::getHelper('catalog/image')->init($_product,'custom_image');
echo "<img src='".$imageUrl."' />";
endif;
That is Magento 1 code, but still I managed to get it like that:$value = $product->getBikeRangeImage();
However, this is not working yet:$value = $product->getBikeRangeImage(); if( isset($value) && $value != 'no_selection' ): echo $this->helper( 'MagentoCatalogHelperImage' )->init( $product, 'bike_range_image' )->resize( 310 ); endif;
That gives me an error saying it returns an object rather than an url as it should. Any idea?
– TommyK
Mar 14 '16 at 14:51
can anyone shed a light to how I can call an image for a drop-down attribute? Thank you
– roger
Oct 18 '16 at 16:55
add a comment |
Use the following code:
$value = $_product->getCustomImage();
if(isset($value) && $value != 'no_selection'):
$imageUrl = Mage::getHelper('catalog/image')->init($_product,'custom_image');
echo "<img src='".$imageUrl."' />";
endif;
That is Magento 1 code, but still I managed to get it like that:$value = $product->getBikeRangeImage();
However, this is not working yet:$value = $product->getBikeRangeImage(); if( isset($value) && $value != 'no_selection' ): echo $this->helper( 'MagentoCatalogHelperImage' )->init( $product, 'bike_range_image' )->resize( 310 ); endif;
That gives me an error saying it returns an object rather than an url as it should. Any idea?
– TommyK
Mar 14 '16 at 14:51
can anyone shed a light to how I can call an image for a drop-down attribute? Thank you
– roger
Oct 18 '16 at 16:55
add a comment |
Use the following code:
$value = $_product->getCustomImage();
if(isset($value) && $value != 'no_selection'):
$imageUrl = Mage::getHelper('catalog/image')->init($_product,'custom_image');
echo "<img src='".$imageUrl."' />";
endif;
Use the following code:
$value = $_product->getCustomImage();
if(isset($value) && $value != 'no_selection'):
$imageUrl = Mage::getHelper('catalog/image')->init($_product,'custom_image');
echo "<img src='".$imageUrl."' />";
endif;
answered Mar 13 '16 at 1:07
Mr. LewisMr. Lewis
1,288710
1,288710
That is Magento 1 code, but still I managed to get it like that:$value = $product->getBikeRangeImage();
However, this is not working yet:$value = $product->getBikeRangeImage(); if( isset($value) && $value != 'no_selection' ): echo $this->helper( 'MagentoCatalogHelperImage' )->init( $product, 'bike_range_image' )->resize( 310 ); endif;
That gives me an error saying it returns an object rather than an url as it should. Any idea?
– TommyK
Mar 14 '16 at 14:51
can anyone shed a light to how I can call an image for a drop-down attribute? Thank you
– roger
Oct 18 '16 at 16:55
add a comment |
That is Magento 1 code, but still I managed to get it like that:$value = $product->getBikeRangeImage();
However, this is not working yet:$value = $product->getBikeRangeImage(); if( isset($value) && $value != 'no_selection' ): echo $this->helper( 'MagentoCatalogHelperImage' )->init( $product, 'bike_range_image' )->resize( 310 ); endif;
That gives me an error saying it returns an object rather than an url as it should. Any idea?
– TommyK
Mar 14 '16 at 14:51
can anyone shed a light to how I can call an image for a drop-down attribute? Thank you
– roger
Oct 18 '16 at 16:55
That is Magento 1 code, but still I managed to get it like that:
$value = $product->getBikeRangeImage();
However, this is not working yet: $value = $product->getBikeRangeImage(); if( isset($value) && $value != 'no_selection' ): echo $this->helper( 'MagentoCatalogHelperImage' )->init( $product, 'bike_range_image' )->resize( 310 ); endif;
That gives me an error saying it returns an object rather than an url as it should. Any idea?– TommyK
Mar 14 '16 at 14:51
That is Magento 1 code, but still I managed to get it like that:
$value = $product->getBikeRangeImage();
However, this is not working yet: $value = $product->getBikeRangeImage(); if( isset($value) && $value != 'no_selection' ): echo $this->helper( 'MagentoCatalogHelperImage' )->init( $product, 'bike_range_image' )->resize( 310 ); endif;
That gives me an error saying it returns an object rather than an url as it should. Any idea?– TommyK
Mar 14 '16 at 14:51
can anyone shed a light to how I can call an image for a drop-down attribute? Thank you
– roger
Oct 18 '16 at 16:55
can anyone shed a light to how I can call an image for a drop-down attribute? Thank you
– roger
Oct 18 '16 at 16:55
add a comment |
You can do this trick mentioned here:
https://stackoverflow.com/questions/34082459/magento2-add-product-attribute-as-media-image
but with one thing that isn't mentioned there is you will be able to just do: $_product->getAttributeCode()
it will work and give you the value.
As doing this
$product->getCustomAttribute( 'attribute_code' )->getValue()
will return null;
add a comment |
You can do this trick mentioned here:
https://stackoverflow.com/questions/34082459/magento2-add-product-attribute-as-media-image
but with one thing that isn't mentioned there is you will be able to just do: $_product->getAttributeCode()
it will work and give you the value.
As doing this
$product->getCustomAttribute( 'attribute_code' )->getValue()
will return null;
add a comment |
You can do this trick mentioned here:
https://stackoverflow.com/questions/34082459/magento2-add-product-attribute-as-media-image
but with one thing that isn't mentioned there is you will be able to just do: $_product->getAttributeCode()
it will work and give you the value.
As doing this
$product->getCustomAttribute( 'attribute_code' )->getValue()
will return null;
You can do this trick mentioned here:
https://stackoverflow.com/questions/34082459/magento2-add-product-attribute-as-media-image
but with one thing that isn't mentioned there is you will be able to just do: $_product->getAttributeCode()
it will work and give you the value.
As doing this
$product->getCustomAttribute( 'attribute_code' )->getValue()
will return null;
edited 29 mins ago
Teja Bhagavan Kollepara
2,98641847
2,98641847
answered Oct 18 '17 at 18:44
Juliano VargasJuliano Vargas
527522
527522
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f105677%2fgetting-a-custom-attribute-image%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown