Magento Product image on Hover not working












0















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 ?










share|improve this question

























  • 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











  • 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
















0















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 ?










share|improve this question

























  • 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











  • 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














0












0








0








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 ?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 6 '17 at 8:02







mahmoudismail

















asked Mar 6 '17 at 7:36









mahmoudismailmahmoudismail

3631322




3631322













  • 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











  • 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



















  • 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











  • 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

















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










3 Answers
3






active

oldest

votes


















1














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) ?>';" />





share|improve this answer































    0














    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)





    share|improve this answer


























    • 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





















    0














    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



    enter image description here






    share|improve this answer























      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      1














      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) ?>';" />





      share|improve this answer




























        1














        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) ?>';" />





        share|improve this answer


























          1












          1








          1







          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) ?>';" />





          share|improve this answer













          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) ?>';" />






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 days ago









          rd007rd007

          114




          114

























              0














              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)





              share|improve this answer


























              • 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


















              0














              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)





              share|improve this answer


























              • 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
















              0












              0








              0







              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)





              share|improve this answer















              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)






              share|improve this answer














              share|improve this answer



              share|improve this answer








              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





















              • 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













              0














              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



              enter image description here






              share|improve this answer




























                0














                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



                enter image description here






                share|improve this answer


























                  0












                  0








                  0







                  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



                  enter image description here






                  share|improve this answer













                  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



                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 6 '17 at 11:49









                  Ahmed ElawadiAhmed Elawadi

                  1,442620




                  1,442620






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      1300-talet

                      1300-talet

                      Display a custom attribute below product name in the front-end Magento 1.9.3.8