Magento Product image on Hover not working
I want to add a hover image for my product.
So the first step :
1- i've create a new attribute with code named hover_image
for all types of the products.
2- in php file catalog->product->list.phtml
i've add onmouseover
javascript function to image
tag like below
onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'hover_image')->resize(500,659)?>'"
but it's not working any suggestions ?
magento-1.9 product product-attribute product-images media-images
|
show 7 more comments
I want to add a hover image for my product.
So the first step :
1- i've create a new attribute with code named hover_image
for all types of the products.
2- in php file catalog->product->list.phtml
i've add onmouseover
javascript function to image
tag like below
onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'hover_image')->resize(500,659)?>'"
but it's not working any suggestions ?
magento-1.9 product product-attribute product-images media-images
put it inmedia/catalog/product/placeholder
and provide what you are adding /storing in that attribute?
– Gopal Patel
Mar 6 '17 at 7:38
but theurl value
is thepath
of thehover_image
inmedia folder
i want to get thehover_image
value selected for the product in the admin .
– mahmoudismail
Mar 6 '17 at 7:41
sry but still not clear
– Gopal Patel
Mar 6 '17 at 7:44
i've update my question
– mahmoudismail
Mar 6 '17 at 7:46
just place your image inmedia/catalog/product/placeholder
– Gopal Patel
Mar 6 '17 at 7:50
|
show 7 more comments
I want to add a hover image for my product.
So the first step :
1- i've create a new attribute with code named hover_image
for all types of the products.
2- in php file catalog->product->list.phtml
i've add onmouseover
javascript function to image
tag like below
onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'hover_image')->resize(500,659)?>'"
but it's not working any suggestions ?
magento-1.9 product product-attribute product-images media-images
I want to add a hover image for my product.
So the first step :
1- i've create a new attribute with code named hover_image
for all types of the products.
2- in php file catalog->product->list.phtml
i've add onmouseover
javascript function to image
tag like below
onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'hover_image')->resize(500,659)?>'"
but it's not working any suggestions ?
magento-1.9 product product-attribute product-images media-images
magento-1.9 product product-attribute product-images media-images
edited Mar 6 '17 at 8:02
mahmoudismail
asked Mar 6 '17 at 7:36
mahmoudismailmahmoudismail
3631322
3631322
put it inmedia/catalog/product/placeholder
and provide what you are adding /storing in that attribute?
– Gopal Patel
Mar 6 '17 at 7:38
but theurl value
is thepath
of thehover_image
inmedia folder
i want to get thehover_image
value selected for the product in the admin .
– mahmoudismail
Mar 6 '17 at 7:41
sry but still not clear
– Gopal Patel
Mar 6 '17 at 7:44
i've update my question
– mahmoudismail
Mar 6 '17 at 7:46
just place your image inmedia/catalog/product/placeholder
– Gopal Patel
Mar 6 '17 at 7:50
|
show 7 more comments
put it inmedia/catalog/product/placeholder
and provide what you are adding /storing in that attribute?
– Gopal Patel
Mar 6 '17 at 7:38
but theurl value
is thepath
of thehover_image
inmedia folder
i want to get thehover_image
value selected for the product in the admin .
– mahmoudismail
Mar 6 '17 at 7:41
sry but still not clear
– Gopal Patel
Mar 6 '17 at 7:44
i've update my question
– mahmoudismail
Mar 6 '17 at 7:46
just place your image inmedia/catalog/product/placeholder
– Gopal Patel
Mar 6 '17 at 7:50
put it in
media/catalog/product/placeholder
and provide what you are adding /storing in that attribute?– Gopal Patel
Mar 6 '17 at 7:38
put it in
media/catalog/product/placeholder
and provide what you are adding /storing in that attribute?– Gopal Patel
Mar 6 '17 at 7:38
but the
url value
is the path
of the hover_image
in media folder
i want to get the hover_image
value selected for the product in the admin .– mahmoudismail
Mar 6 '17 at 7:41
but the
url value
is the path
of the hover_image
in media folder
i want to get the hover_image
value selected for the product in the admin .– mahmoudismail
Mar 6 '17 at 7:41
sry but still not clear
– Gopal Patel
Mar 6 '17 at 7:44
sry but still not clear
– Gopal Patel
Mar 6 '17 at 7:44
i've update my question
– mahmoudismail
Mar 6 '17 at 7:46
i've update my question
– mahmoudismail
Mar 6 '17 at 7:46
just place your image in
media/catalog/product/placeholder
– Gopal Patel
Mar 6 '17 at 7:50
just place your image in
media/catalog/product/placeholder
– Gopal Patel
Mar 6 '17 at 7:50
|
show 7 more comments
3 Answers
3
active
oldest
votes
here is working code you can try this
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(224); ?>" width="226" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'hover_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(224) ?>';" onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(224) ?>';" />
add a comment |
Load again
$product=Mage::getModel('catalog/product')->load($_product->getId());
Now try with new object
echo $this->helper('catalog/image')->init($_product, 'hover_image')->resize(500,659)
i've got an empty value
– mahmoudismail
Mar 6 '17 at 8:11
@mahmoudismail please find updated answer
– Gopal Patel
Mar 6 '17 at 8:32
sry it's not working
– mahmoudismail
Mar 6 '17 at 8:36
@mahmoudismail have you refer this? stackoverflow.com/a/9769386/7089203
– Gopal Patel
Mar 6 '17 at 8:53
add a comment |
Here is a complete working code you can use, please remember to upload placeholder
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
<?php $hoverImage = $this->helper('catalog/image')->init($_product, 'hover_image')->resize(300,470)->setQuality(100);
if (strpos($hoverImage, 'place-holder') == false) { ?>
<img id="product-collection-image-<?php echo $_product->getId(); ?>"
src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,470)->setQuality(100); ?>"
alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"
onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'hover_image')->resize(300,470)->setQuality(100) ?>';"
onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,470)->setQuality(100); ?>';"
/>
<?php } else { ?>
<img id="product-collection-image-<?php echo $_product->getId(); ?>"
src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,470)->setQuality(100); ?>"
alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"
/>
<?php } ?>
</a>
You can uplaod place holder via backend System > Configtration > Catlouge > product image placeholder
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%2f163000%2fmagento-product-image-on-hover-not-working%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
here is working code you can try this
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(224); ?>" width="226" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'hover_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(224) ?>';" onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(224) ?>';" />
add a comment |
here is working code you can try this
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(224); ?>" width="226" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'hover_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(224) ?>';" onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(224) ?>';" />
add a comment |
here is working code you can try this
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(224); ?>" width="226" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'hover_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(224) ?>';" onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(224) ?>';" />
here is working code you can try this
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(224); ?>" width="226" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'hover_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(224) ?>';" onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(224) ?>';" />
answered 2 days ago
rd007rd007
114
114
add a comment |
add a comment |
Load again
$product=Mage::getModel('catalog/product')->load($_product->getId());
Now try with new object
echo $this->helper('catalog/image')->init($_product, 'hover_image')->resize(500,659)
i've got an empty value
– mahmoudismail
Mar 6 '17 at 8:11
@mahmoudismail please find updated answer
– Gopal Patel
Mar 6 '17 at 8:32
sry it's not working
– mahmoudismail
Mar 6 '17 at 8:36
@mahmoudismail have you refer this? stackoverflow.com/a/9769386/7089203
– Gopal Patel
Mar 6 '17 at 8:53
add a comment |
Load again
$product=Mage::getModel('catalog/product')->load($_product->getId());
Now try with new object
echo $this->helper('catalog/image')->init($_product, 'hover_image')->resize(500,659)
i've got an empty value
– mahmoudismail
Mar 6 '17 at 8:11
@mahmoudismail please find updated answer
– Gopal Patel
Mar 6 '17 at 8:32
sry it's not working
– mahmoudismail
Mar 6 '17 at 8:36
@mahmoudismail have you refer this? stackoverflow.com/a/9769386/7089203
– Gopal Patel
Mar 6 '17 at 8:53
add a comment |
Load again
$product=Mage::getModel('catalog/product')->load($_product->getId());
Now try with new object
echo $this->helper('catalog/image')->init($_product, 'hover_image')->resize(500,659)
Load again
$product=Mage::getModel('catalog/product')->load($_product->getId());
Now try with new object
echo $this->helper('catalog/image')->init($_product, 'hover_image')->resize(500,659)
edited Mar 6 '17 at 8:31
answered Mar 6 '17 at 8:07
Gopal PatelGopal Patel
2,9912930
2,9912930
i've got an empty value
– mahmoudismail
Mar 6 '17 at 8:11
@mahmoudismail please find updated answer
– Gopal Patel
Mar 6 '17 at 8:32
sry it's not working
– mahmoudismail
Mar 6 '17 at 8:36
@mahmoudismail have you refer this? stackoverflow.com/a/9769386/7089203
– Gopal Patel
Mar 6 '17 at 8:53
add a comment |
i've got an empty value
– mahmoudismail
Mar 6 '17 at 8:11
@mahmoudismail please find updated answer
– Gopal Patel
Mar 6 '17 at 8:32
sry it's not working
– mahmoudismail
Mar 6 '17 at 8:36
@mahmoudismail have you refer this? stackoverflow.com/a/9769386/7089203
– Gopal Patel
Mar 6 '17 at 8:53
i've got an empty value
– mahmoudismail
Mar 6 '17 at 8:11
i've got an empty value
– mahmoudismail
Mar 6 '17 at 8:11
@mahmoudismail please find updated answer
– Gopal Patel
Mar 6 '17 at 8:32
@mahmoudismail please find updated answer
– Gopal Patel
Mar 6 '17 at 8:32
sry it's not working
– mahmoudismail
Mar 6 '17 at 8:36
sry it's not working
– mahmoudismail
Mar 6 '17 at 8:36
@mahmoudismail have you refer this? stackoverflow.com/a/9769386/7089203
– Gopal Patel
Mar 6 '17 at 8:53
@mahmoudismail have you refer this? stackoverflow.com/a/9769386/7089203
– Gopal Patel
Mar 6 '17 at 8:53
add a comment |
Here is a complete working code you can use, please remember to upload placeholder
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
<?php $hoverImage = $this->helper('catalog/image')->init($_product, 'hover_image')->resize(300,470)->setQuality(100);
if (strpos($hoverImage, 'place-holder') == false) { ?>
<img id="product-collection-image-<?php echo $_product->getId(); ?>"
src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,470)->setQuality(100); ?>"
alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"
onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'hover_image')->resize(300,470)->setQuality(100) ?>';"
onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,470)->setQuality(100); ?>';"
/>
<?php } else { ?>
<img id="product-collection-image-<?php echo $_product->getId(); ?>"
src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,470)->setQuality(100); ?>"
alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"
/>
<?php } ?>
</a>
You can uplaod place holder via backend System > Configtration > Catlouge > product image placeholder
add a comment |
Here is a complete working code you can use, please remember to upload placeholder
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
<?php $hoverImage = $this->helper('catalog/image')->init($_product, 'hover_image')->resize(300,470)->setQuality(100);
if (strpos($hoverImage, 'place-holder') == false) { ?>
<img id="product-collection-image-<?php echo $_product->getId(); ?>"
src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,470)->setQuality(100); ?>"
alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"
onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'hover_image')->resize(300,470)->setQuality(100) ?>';"
onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,470)->setQuality(100); ?>';"
/>
<?php } else { ?>
<img id="product-collection-image-<?php echo $_product->getId(); ?>"
src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,470)->setQuality(100); ?>"
alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"
/>
<?php } ?>
</a>
You can uplaod place holder via backend System > Configtration > Catlouge > product image placeholder
add a comment |
Here is a complete working code you can use, please remember to upload placeholder
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
<?php $hoverImage = $this->helper('catalog/image')->init($_product, 'hover_image')->resize(300,470)->setQuality(100);
if (strpos($hoverImage, 'place-holder') == false) { ?>
<img id="product-collection-image-<?php echo $_product->getId(); ?>"
src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,470)->setQuality(100); ?>"
alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"
onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'hover_image')->resize(300,470)->setQuality(100) ?>';"
onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,470)->setQuality(100); ?>';"
/>
<?php } else { ?>
<img id="product-collection-image-<?php echo $_product->getId(); ?>"
src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,470)->setQuality(100); ?>"
alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"
/>
<?php } ?>
</a>
You can uplaod place holder via backend System > Configtration > Catlouge > product image placeholder
Here is a complete working code you can use, please remember to upload placeholder
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
<?php $hoverImage = $this->helper('catalog/image')->init($_product, 'hover_image')->resize(300,470)->setQuality(100);
if (strpos($hoverImage, 'place-holder') == false) { ?>
<img id="product-collection-image-<?php echo $_product->getId(); ?>"
src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,470)->setQuality(100); ?>"
alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"
onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'hover_image')->resize(300,470)->setQuality(100) ?>';"
onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,470)->setQuality(100); ?>';"
/>
<?php } else { ?>
<img id="product-collection-image-<?php echo $_product->getId(); ?>"
src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(300,470)->setQuality(100); ?>"
alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"
/>
<?php } ?>
</a>
You can uplaod place holder via backend System > Configtration > Catlouge > product image placeholder
answered Mar 6 '17 at 11:49
Ahmed ElawadiAhmed Elawadi
1,442620
1,442620
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%2f163000%2fmagento-product-image-on-hover-not-working%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
put it in
media/catalog/product/placeholder
and provide what you are adding /storing in that attribute?– Gopal Patel
Mar 6 '17 at 7:38
but the
url value
is thepath
of thehover_image
inmedia folder
i want to get thehover_image
value selected for the product in the admin .– mahmoudismail
Mar 6 '17 at 7:41
sry but still not clear
– Gopal Patel
Mar 6 '17 at 7:44
i've update my question
– mahmoudismail
Mar 6 '17 at 7:46
just place your image in
media/catalog/product/placeholder
– Gopal Patel
Mar 6 '17 at 7:50