Load all gallery images in category on hover (Ajax) The Next CEO of Stack OverflowHow do i call a controller function in ajax?Code to enable downloadable product?Trying to run an AJAX script from the admin area in magentoDynamic content - how to realize?CSV import not working - Need AssistanceMagento 2 get product gallery images on product listpage without load model in loopMagento How to add configurable product while placing order programatically?Magento 2 get gallery imagesGet all gallery imagesAdd Fullscreen Gallery to custom gallery Images - Magento 2Magento 2 Gallery Images HTML

Is there a way to save my career from absolute disaster?

What's the best way to handle refactoring a big file?

Which kind of appliances can one connect to electric sockets located in an airplane's toilet?

If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?

How does the mv command work with external drives?

Why do professional authors make "consistency" mistakes? And how to avoid them?

Why am I allowed to create multiple unique pointers from a single object?

What exact does MIB represent in SNMP? How is it different from OID?

Why does standard notation not preserve intervals (visually)

Preparing Indesign booklet with .psd graphics for print

How to safely derail a train during transit?

What can we do to stop prior company from asking us questions?

If/When UK leaves the EU, can a future goverment conduct a referendum to join the EU?

What does convergence in distribution "in the Gromov–Hausdorff" sense mean?

Is there a difference between "Fahrstuhl" and "Aufzug"

Bold, vivid family

In the bitcoin scripting language, how can I access other outputs of the transaction? Or how else can I limit how the coins may be spent?

Can we say or write : "No, it'sn't"?

What was the first Unix version to run on a microcomputer?

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Won the lottery - how do I keep the money?

"In the right combination" vs "with the right combination"?

How do scammers retract money, while you can’t?

How to avoid supervisors with prejudiced views?



Load all gallery images in category on hover (Ajax)



The Next CEO of Stack OverflowHow do i call a controller function in ajax?Code to enable downloadable product?Trying to run an AJAX script from the admin area in magentoDynamic content - how to realize?CSV import not working - Need AssistanceMagento 2 get product gallery images on product listpage without load model in loopMagento How to add configurable product while placing order programatically?Magento 2 get gallery imagesGet all gallery imagesAdd Fullscreen Gallery to custom gallery Images - Magento 2Magento 2 Gallery Images HTML










0















I have a code to load all the gallery images of a product in category, it will work but the problem is that will load ALL gallery images for products in the category (list.phtml) so will increase server load.



<?php $_images = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages(); ?>
<?php if($_images)?>
<?php $getimagegalleryresize=0; foreach($_images as $_image) $getimagegalleryresize++; if($getimagegalleryresize>=2 && $getimagegalleryresize<=5): ?>

<a class="link" href="<?php echo $_product->getProductUrl(); ?>"> <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->adaptiveResize(275,394); ?>" data-src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->adaptiveResize(275,394); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel());?>" title="<?php $this->htmlEscape($_image->getLabel());?>" /><?php endif; ?> </a>
<?php ?>


I have this code on hover-div so together with jquery-cycle plugin will loop the gallery images from 0-5.
The problem is that all images will be loaded on page so if i have 30 products multiple by 5 images each the server will need to load 150 images to prepare them for execute on hover.



What i need is that the category will load 30 products normally with main image and only when user hovers and keep mouseon at the product main_image it will start loading the rest of gallery images.
Should i do this through Jquery.load or Ajax and if so , i cannot understand what the load-page.php should include.
Anyone can help on this?i am trying so hard but i am not so good in PHP,Ajax and i want to learn.



EDIT:Based on Pankaj and other infos i believe that i should write a module for the ajaxcall instead of trying to load just a loadpage.php. I have created the module and tested url , also test on hover and is working ok. However the controller is empty, just console log "received data ok" so how to make it load the rest of the gallery images?



Here is IndexController.php



 Package_Module_IndexController extends Mage_Core_Controller_Front_Action 
public function getdataAction()
if($data = $this->getRequest()->getPost("key"))

//here starts my tests trying to load product somehow?
$_product = Mage::getResourceModel('catalog/product_collection')->toOptionArray();
$product_id = $this->getRequest()->getParam('id');
$_product = Mage::getModel('catalog/product')->load($product_id);
echo Mage::helper('catalog/image')->init($_product, 'small_image');

else
echo "unable to receive data !";






And here is my jquery ajax function on hover on list.phtml:



 <span class="hover-image">
<script>
jQuery.ajax(
url: "http://works/www.devet3est.com/testing/index/getdata",
type: "POST",
data: key: 'value',
success: function(response)
console.log(response);
return response;
result = response;
jQuery('.hover-image').html(response);


);
</script>


</span>


EDIT2 reason: cannot getdata of product from controller



I am not sure if the problem is the data type i use for jquery.ajax script (taken from another topic here) or the indexcontroller.php.
I am pasting the full experimental indexcontroller.php with lot of garbage but i am trying at least to get some real data from product, even name/price etc then i will continue with gallery images.



<?php class Package_Module_IndexController extends Mage_Core_Controller_Front_Action 
public function _prepareLayout()

return parent::_prepareLayout();


public function getCurrentCategory()

return $this->_registry->registry('current_category');


public function getCurrentProduct()

return $this->_registry->registry('current_product');

public function getdataAction()
if($data = $this->getRequest()->getPost("key"))
$post = $this->getRequest()->getPost();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($post));

$_product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId());
$_product = $_product->load(Mage::app()->getRequest()->getParam('pid'));

Mage::register('current_product', $_product );
Mage::register('product', $_product);




$productId = (int) $this->getRequest()->getParam('id');
$productName = (int) $this->getRequest()->getParam('name');

$_product = Mage::getModel('catalog/product')->getId();
$product_name= Mage::getModel('catalog/product')->getName();
$_product = Mage::getModel('catalog/product');
$productAttrs = Mage::getResourceModel('catalog/product_attribute_collection');

$images = [];
$_product = Mage::getModel('catalog/product')->load(5545);
foreach ($_product->getMediaGalleryImages() as $image):

$images[] = Mage::helper('catalog/image')->init($_product, 'image', $image->getFile())->resize(100, 100);

endforeach;
echo 'testing at least to check if controller is connected OK gives DATA';
return $product_name;
return $images;
$post = $this->getRequest()->getPost();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($post));
$response = $wrap->renderView();
$this->getResponse()->setBody($response);
$result = "success";
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
exit;
else
echo "unable to receive data !";













share|improve this question




























    0















    I have a code to load all the gallery images of a product in category, it will work but the problem is that will load ALL gallery images for products in the category (list.phtml) so will increase server load.



    <?php $_images = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages(); ?>
    <?php if($_images)?>
    <?php $getimagegalleryresize=0; foreach($_images as $_image) $getimagegalleryresize++; if($getimagegalleryresize>=2 && $getimagegalleryresize<=5): ?>

    <a class="link" href="<?php echo $_product->getProductUrl(); ?>"> <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->adaptiveResize(275,394); ?>" data-src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->adaptiveResize(275,394); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel());?>" title="<?php $this->htmlEscape($_image->getLabel());?>" /><?php endif; ?> </a>
    <?php ?>


    I have this code on hover-div so together with jquery-cycle plugin will loop the gallery images from 0-5.
    The problem is that all images will be loaded on page so if i have 30 products multiple by 5 images each the server will need to load 150 images to prepare them for execute on hover.



    What i need is that the category will load 30 products normally with main image and only when user hovers and keep mouseon at the product main_image it will start loading the rest of gallery images.
    Should i do this through Jquery.load or Ajax and if so , i cannot understand what the load-page.php should include.
    Anyone can help on this?i am trying so hard but i am not so good in PHP,Ajax and i want to learn.



    EDIT:Based on Pankaj and other infos i believe that i should write a module for the ajaxcall instead of trying to load just a loadpage.php. I have created the module and tested url , also test on hover and is working ok. However the controller is empty, just console log "received data ok" so how to make it load the rest of the gallery images?



    Here is IndexController.php



     Package_Module_IndexController extends Mage_Core_Controller_Front_Action 
    public function getdataAction()
    if($data = $this->getRequest()->getPost("key"))

    //here starts my tests trying to load product somehow?
    $_product = Mage::getResourceModel('catalog/product_collection')->toOptionArray();
    $product_id = $this->getRequest()->getParam('id');
    $_product = Mage::getModel('catalog/product')->load($product_id);
    echo Mage::helper('catalog/image')->init($_product, 'small_image');

    else
    echo "unable to receive data !";






    And here is my jquery ajax function on hover on list.phtml:



     <span class="hover-image">
    <script>
    jQuery.ajax(
    url: "http://works/www.devet3est.com/testing/index/getdata",
    type: "POST",
    data: key: 'value',
    success: function(response)
    console.log(response);
    return response;
    result = response;
    jQuery('.hover-image').html(response);


    );
    </script>


    </span>


    EDIT2 reason: cannot getdata of product from controller



    I am not sure if the problem is the data type i use for jquery.ajax script (taken from another topic here) or the indexcontroller.php.
    I am pasting the full experimental indexcontroller.php with lot of garbage but i am trying at least to get some real data from product, even name/price etc then i will continue with gallery images.



    <?php class Package_Module_IndexController extends Mage_Core_Controller_Front_Action 
    public function _prepareLayout()

    return parent::_prepareLayout();


    public function getCurrentCategory()

    return $this->_registry->registry('current_category');


    public function getCurrentProduct()

    return $this->_registry->registry('current_product');

    public function getdataAction()
    if($data = $this->getRequest()->getPost("key"))
    $post = $this->getRequest()->getPost();
    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($post));

    $_product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId());
    $_product = $_product->load(Mage::app()->getRequest()->getParam('pid'));

    Mage::register('current_product', $_product );
    Mage::register('product', $_product);




    $productId = (int) $this->getRequest()->getParam('id');
    $productName = (int) $this->getRequest()->getParam('name');

    $_product = Mage::getModel('catalog/product')->getId();
    $product_name= Mage::getModel('catalog/product')->getName();
    $_product = Mage::getModel('catalog/product');
    $productAttrs = Mage::getResourceModel('catalog/product_attribute_collection');

    $images = [];
    $_product = Mage::getModel('catalog/product')->load(5545);
    foreach ($_product->getMediaGalleryImages() as $image):

    $images[] = Mage::helper('catalog/image')->init($_product, 'image', $image->getFile())->resize(100, 100);

    endforeach;
    echo 'testing at least to check if controller is connected OK gives DATA';
    return $product_name;
    return $images;
    $post = $this->getRequest()->getPost();
    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($post));
    $response = $wrap->renderView();
    $this->getResponse()->setBody($response);
    $result = "success";
    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    exit;
    else
    echo "unable to receive data !";













    share|improve this question


























      0












      0








      0


      1






      I have a code to load all the gallery images of a product in category, it will work but the problem is that will load ALL gallery images for products in the category (list.phtml) so will increase server load.



      <?php $_images = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages(); ?>
      <?php if($_images)?>
      <?php $getimagegalleryresize=0; foreach($_images as $_image) $getimagegalleryresize++; if($getimagegalleryresize>=2 && $getimagegalleryresize<=5): ?>

      <a class="link" href="<?php echo $_product->getProductUrl(); ?>"> <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->adaptiveResize(275,394); ?>" data-src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->adaptiveResize(275,394); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel());?>" title="<?php $this->htmlEscape($_image->getLabel());?>" /><?php endif; ?> </a>
      <?php ?>


      I have this code on hover-div so together with jquery-cycle plugin will loop the gallery images from 0-5.
      The problem is that all images will be loaded on page so if i have 30 products multiple by 5 images each the server will need to load 150 images to prepare them for execute on hover.



      What i need is that the category will load 30 products normally with main image and only when user hovers and keep mouseon at the product main_image it will start loading the rest of gallery images.
      Should i do this through Jquery.load or Ajax and if so , i cannot understand what the load-page.php should include.
      Anyone can help on this?i am trying so hard but i am not so good in PHP,Ajax and i want to learn.



      EDIT:Based on Pankaj and other infos i believe that i should write a module for the ajaxcall instead of trying to load just a loadpage.php. I have created the module and tested url , also test on hover and is working ok. However the controller is empty, just console log "received data ok" so how to make it load the rest of the gallery images?



      Here is IndexController.php



       Package_Module_IndexController extends Mage_Core_Controller_Front_Action 
      public function getdataAction()
      if($data = $this->getRequest()->getPost("key"))

      //here starts my tests trying to load product somehow?
      $_product = Mage::getResourceModel('catalog/product_collection')->toOptionArray();
      $product_id = $this->getRequest()->getParam('id');
      $_product = Mage::getModel('catalog/product')->load($product_id);
      echo Mage::helper('catalog/image')->init($_product, 'small_image');

      else
      echo "unable to receive data !";






      And here is my jquery ajax function on hover on list.phtml:



       <span class="hover-image">
      <script>
      jQuery.ajax(
      url: "http://works/www.devet3est.com/testing/index/getdata",
      type: "POST",
      data: key: 'value',
      success: function(response)
      console.log(response);
      return response;
      result = response;
      jQuery('.hover-image').html(response);


      );
      </script>


      </span>


      EDIT2 reason: cannot getdata of product from controller



      I am not sure if the problem is the data type i use for jquery.ajax script (taken from another topic here) or the indexcontroller.php.
      I am pasting the full experimental indexcontroller.php with lot of garbage but i am trying at least to get some real data from product, even name/price etc then i will continue with gallery images.



      <?php class Package_Module_IndexController extends Mage_Core_Controller_Front_Action 
      public function _prepareLayout()

      return parent::_prepareLayout();


      public function getCurrentCategory()

      return $this->_registry->registry('current_category');


      public function getCurrentProduct()

      return $this->_registry->registry('current_product');

      public function getdataAction()
      if($data = $this->getRequest()->getPost("key"))
      $post = $this->getRequest()->getPost();
      $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($post));

      $_product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId());
      $_product = $_product->load(Mage::app()->getRequest()->getParam('pid'));

      Mage::register('current_product', $_product );
      Mage::register('product', $_product);




      $productId = (int) $this->getRequest()->getParam('id');
      $productName = (int) $this->getRequest()->getParam('name');

      $_product = Mage::getModel('catalog/product')->getId();
      $product_name= Mage::getModel('catalog/product')->getName();
      $_product = Mage::getModel('catalog/product');
      $productAttrs = Mage::getResourceModel('catalog/product_attribute_collection');

      $images = [];
      $_product = Mage::getModel('catalog/product')->load(5545);
      foreach ($_product->getMediaGalleryImages() as $image):

      $images[] = Mage::helper('catalog/image')->init($_product, 'image', $image->getFile())->resize(100, 100);

      endforeach;
      echo 'testing at least to check if controller is connected OK gives DATA';
      return $product_name;
      return $images;
      $post = $this->getRequest()->getPost();
      $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($post));
      $response = $wrap->renderView();
      $this->getResponse()->setBody($response);
      $result = "success";
      $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
      exit;
      else
      echo "unable to receive data !";













      share|improve this question
















      I have a code to load all the gallery images of a product in category, it will work but the problem is that will load ALL gallery images for products in the category (list.phtml) so will increase server load.



      <?php $_images = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages(); ?>
      <?php if($_images)?>
      <?php $getimagegalleryresize=0; foreach($_images as $_image) $getimagegalleryresize++; if($getimagegalleryresize>=2 && $getimagegalleryresize<=5): ?>

      <a class="link" href="<?php echo $_product->getProductUrl(); ?>"> <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->adaptiveResize(275,394); ?>" data-src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->adaptiveResize(275,394); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel());?>" title="<?php $this->htmlEscape($_image->getLabel());?>" /><?php endif; ?> </a>
      <?php ?>


      I have this code on hover-div so together with jquery-cycle plugin will loop the gallery images from 0-5.
      The problem is that all images will be loaded on page so if i have 30 products multiple by 5 images each the server will need to load 150 images to prepare them for execute on hover.



      What i need is that the category will load 30 products normally with main image and only when user hovers and keep mouseon at the product main_image it will start loading the rest of gallery images.
      Should i do this through Jquery.load or Ajax and if so , i cannot understand what the load-page.php should include.
      Anyone can help on this?i am trying so hard but i am not so good in PHP,Ajax and i want to learn.



      EDIT:Based on Pankaj and other infos i believe that i should write a module for the ajaxcall instead of trying to load just a loadpage.php. I have created the module and tested url , also test on hover and is working ok. However the controller is empty, just console log "received data ok" so how to make it load the rest of the gallery images?



      Here is IndexController.php



       Package_Module_IndexController extends Mage_Core_Controller_Front_Action 
      public function getdataAction()
      if($data = $this->getRequest()->getPost("key"))

      //here starts my tests trying to load product somehow?
      $_product = Mage::getResourceModel('catalog/product_collection')->toOptionArray();
      $product_id = $this->getRequest()->getParam('id');
      $_product = Mage::getModel('catalog/product')->load($product_id);
      echo Mage::helper('catalog/image')->init($_product, 'small_image');

      else
      echo "unable to receive data !";






      And here is my jquery ajax function on hover on list.phtml:



       <span class="hover-image">
      <script>
      jQuery.ajax(
      url: "http://works/www.devet3est.com/testing/index/getdata",
      type: "POST",
      data: key: 'value',
      success: function(response)
      console.log(response);
      return response;
      result = response;
      jQuery('.hover-image').html(response);


      );
      </script>


      </span>


      EDIT2 reason: cannot getdata of product from controller



      I am not sure if the problem is the data type i use for jquery.ajax script (taken from another topic here) or the indexcontroller.php.
      I am pasting the full experimental indexcontroller.php with lot of garbage but i am trying at least to get some real data from product, even name/price etc then i will continue with gallery images.



      <?php class Package_Module_IndexController extends Mage_Core_Controller_Front_Action 
      public function _prepareLayout()

      return parent::_prepareLayout();


      public function getCurrentCategory()

      return $this->_registry->registry('current_category');


      public function getCurrentProduct()

      return $this->_registry->registry('current_product');

      public function getdataAction()
      if($data = $this->getRequest()->getPost("key"))
      $post = $this->getRequest()->getPost();
      $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($post));

      $_product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId());
      $_product = $_product->load(Mage::app()->getRequest()->getParam('pid'));

      Mage::register('current_product', $_product );
      Mage::register('product', $_product);




      $productId = (int) $this->getRequest()->getParam('id');
      $productName = (int) $this->getRequest()->getParam('name');

      $_product = Mage::getModel('catalog/product')->getId();
      $product_name= Mage::getModel('catalog/product')->getName();
      $_product = Mage::getModel('catalog/product');
      $productAttrs = Mage::getResourceModel('catalog/product_attribute_collection');

      $images = [];
      $_product = Mage::getModel('catalog/product')->load(5545);
      foreach ($_product->getMediaGalleryImages() as $image):

      $images[] = Mage::helper('catalog/image')->init($_product, 'image', $image->getFile())->resize(100, 100);

      endforeach;
      echo 'testing at least to check if controller is connected OK gives DATA';
      return $product_name;
      return $images;
      $post = $this->getRequest()->getPost();
      $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($post));
      $response = $wrap->renderView();
      $this->getResponse()->setBody($response);
      $result = "success";
      $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
      exit;
      else
      echo "unable to receive data !";










      magento-1 ajax product-list gallery-image






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 29 mins ago









      Teja Bhagavan Kollepara

      3,01241949




      3,01241949










      asked Feb 22 '18 at 14:25









      laxanorizolaxanorizo

      63




      63




















          1 Answer
          1






          active

          oldest

          votes


















          1














          To optimize the speed, You can perform the following steps:



          • Create one JS function to call on hover on product Inage and Pass Product SKU as argument.

          • Create Ajax call to one Ajax Controller Action

          • In Ajax action Load Product and Fetch all the product images and pass response as HTML from action.

          • Insert the Response HTML in Gallery images div with unique ID as "gallery_image_SKU"

          • Apply check in JS function if images are there don't make Ajax call again.

          Below linnks give you more understaing about ajax call:



          How do i call a controller function in ajax?



          https://stackoverflow.com/questions/19383188/module-and-ajax-call



          http://javascriptsolution.com/call-magento-controller-using-ajax/



          Hope this help!!



          Updated: You can Load Images Like below. $images will contain complete image galleries path.



           $images = [];
          $product = Mage::getModel('catalog/product')->load(2);
          foreach ($product->getMediaGalleryImages() as $image):

          $images[] = Mage::helper('catalog/image')->init($product, 'image', $image->getFile())->resize(100, 100);

          endforeach;


          Here you can also create Img tag in php and pass that Html code in response.






          share|improve this answer

























          • thank you, from what i understand i need to create module so i have started. I have created the module configl and controller and call it via jquery ajax inside my list.phtml but i do not understand what i should write inside IndexController.php to get all the gallery images once the ajax is called. Can you give example to start?i will update my question to add IndexController.php contents, module works ok so no need to add config.xml etc.

            – laxanorizo
            Feb 22 '18 at 16:29











          • I have updated my answer.

            – Pankaj Pareek
            Feb 22 '18 at 17:19











          • issue is that indexcontroller.php will always display nothing for image,price,name etc.if i try even to echo product_name it will not give any result. If i write something like echo 'test'; then it will display it iso they are connected with the controller. What do you think?Kindly have a look on my indexcontroller.php on the part "//here starts my tests trying to load product somehow?" How to make it understand that same product loads this controller and needs to send back gallery images through Ajax?must be doing something wrong..

            – laxanorizo
            Feb 22 '18 at 17:33











          • Don't echo anything. add code like return $images; exit; then you will get data in ajax

            – Pankaj Pareek
            Feb 22 '18 at 18:00











          • you are right about the return $value i am still learning. But no matter what i do it will not load data from the product that i trigger the Ajax call.On list.phtml i have a hover on the main image and inside that div i paste the jQuery.ajax. Controller connects ok cause if i write something dummy inside the indexcontroller.php will display on hover inside main image.But no way to get product's data, i want at least to get _name to make sure it returns data. Does it need a special method to load the product inside the controller and then call the data?I

            – laxanorizo
            Feb 23 '18 at 9:45











          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%2f214650%2fload-all-gallery-images-in-category-on-hover-ajax%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          To optimize the speed, You can perform the following steps:



          • Create one JS function to call on hover on product Inage and Pass Product SKU as argument.

          • Create Ajax call to one Ajax Controller Action

          • In Ajax action Load Product and Fetch all the product images and pass response as HTML from action.

          • Insert the Response HTML in Gallery images div with unique ID as "gallery_image_SKU"

          • Apply check in JS function if images are there don't make Ajax call again.

          Below linnks give you more understaing about ajax call:



          How do i call a controller function in ajax?



          https://stackoverflow.com/questions/19383188/module-and-ajax-call



          http://javascriptsolution.com/call-magento-controller-using-ajax/



          Hope this help!!



          Updated: You can Load Images Like below. $images will contain complete image galleries path.



           $images = [];
          $product = Mage::getModel('catalog/product')->load(2);
          foreach ($product->getMediaGalleryImages() as $image):

          $images[] = Mage::helper('catalog/image')->init($product, 'image', $image->getFile())->resize(100, 100);

          endforeach;


          Here you can also create Img tag in php and pass that Html code in response.






          share|improve this answer

























          • thank you, from what i understand i need to create module so i have started. I have created the module configl and controller and call it via jquery ajax inside my list.phtml but i do not understand what i should write inside IndexController.php to get all the gallery images once the ajax is called. Can you give example to start?i will update my question to add IndexController.php contents, module works ok so no need to add config.xml etc.

            – laxanorizo
            Feb 22 '18 at 16:29











          • I have updated my answer.

            – Pankaj Pareek
            Feb 22 '18 at 17:19











          • issue is that indexcontroller.php will always display nothing for image,price,name etc.if i try even to echo product_name it will not give any result. If i write something like echo 'test'; then it will display it iso they are connected with the controller. What do you think?Kindly have a look on my indexcontroller.php on the part "//here starts my tests trying to load product somehow?" How to make it understand that same product loads this controller and needs to send back gallery images through Ajax?must be doing something wrong..

            – laxanorizo
            Feb 22 '18 at 17:33











          • Don't echo anything. add code like return $images; exit; then you will get data in ajax

            – Pankaj Pareek
            Feb 22 '18 at 18:00











          • you are right about the return $value i am still learning. But no matter what i do it will not load data from the product that i trigger the Ajax call.On list.phtml i have a hover on the main image and inside that div i paste the jQuery.ajax. Controller connects ok cause if i write something dummy inside the indexcontroller.php will display on hover inside main image.But no way to get product's data, i want at least to get _name to make sure it returns data. Does it need a special method to load the product inside the controller and then call the data?I

            – laxanorizo
            Feb 23 '18 at 9:45















          1














          To optimize the speed, You can perform the following steps:



          • Create one JS function to call on hover on product Inage and Pass Product SKU as argument.

          • Create Ajax call to one Ajax Controller Action

          • In Ajax action Load Product and Fetch all the product images and pass response as HTML from action.

          • Insert the Response HTML in Gallery images div with unique ID as "gallery_image_SKU"

          • Apply check in JS function if images are there don't make Ajax call again.

          Below linnks give you more understaing about ajax call:



          How do i call a controller function in ajax?



          https://stackoverflow.com/questions/19383188/module-and-ajax-call



          http://javascriptsolution.com/call-magento-controller-using-ajax/



          Hope this help!!



          Updated: You can Load Images Like below. $images will contain complete image galleries path.



           $images = [];
          $product = Mage::getModel('catalog/product')->load(2);
          foreach ($product->getMediaGalleryImages() as $image):

          $images[] = Mage::helper('catalog/image')->init($product, 'image', $image->getFile())->resize(100, 100);

          endforeach;


          Here you can also create Img tag in php and pass that Html code in response.






          share|improve this answer

























          • thank you, from what i understand i need to create module so i have started. I have created the module configl and controller and call it via jquery ajax inside my list.phtml but i do not understand what i should write inside IndexController.php to get all the gallery images once the ajax is called. Can you give example to start?i will update my question to add IndexController.php contents, module works ok so no need to add config.xml etc.

            – laxanorizo
            Feb 22 '18 at 16:29











          • I have updated my answer.

            – Pankaj Pareek
            Feb 22 '18 at 17:19











          • issue is that indexcontroller.php will always display nothing for image,price,name etc.if i try even to echo product_name it will not give any result. If i write something like echo 'test'; then it will display it iso they are connected with the controller. What do you think?Kindly have a look on my indexcontroller.php on the part "//here starts my tests trying to load product somehow?" How to make it understand that same product loads this controller and needs to send back gallery images through Ajax?must be doing something wrong..

            – laxanorizo
            Feb 22 '18 at 17:33











          • Don't echo anything. add code like return $images; exit; then you will get data in ajax

            – Pankaj Pareek
            Feb 22 '18 at 18:00











          • you are right about the return $value i am still learning. But no matter what i do it will not load data from the product that i trigger the Ajax call.On list.phtml i have a hover on the main image and inside that div i paste the jQuery.ajax. Controller connects ok cause if i write something dummy inside the indexcontroller.php will display on hover inside main image.But no way to get product's data, i want at least to get _name to make sure it returns data. Does it need a special method to load the product inside the controller and then call the data?I

            – laxanorizo
            Feb 23 '18 at 9:45













          1












          1








          1







          To optimize the speed, You can perform the following steps:



          • Create one JS function to call on hover on product Inage and Pass Product SKU as argument.

          • Create Ajax call to one Ajax Controller Action

          • In Ajax action Load Product and Fetch all the product images and pass response as HTML from action.

          • Insert the Response HTML in Gallery images div with unique ID as "gallery_image_SKU"

          • Apply check in JS function if images are there don't make Ajax call again.

          Below linnks give you more understaing about ajax call:



          How do i call a controller function in ajax?



          https://stackoverflow.com/questions/19383188/module-and-ajax-call



          http://javascriptsolution.com/call-magento-controller-using-ajax/



          Hope this help!!



          Updated: You can Load Images Like below. $images will contain complete image galleries path.



           $images = [];
          $product = Mage::getModel('catalog/product')->load(2);
          foreach ($product->getMediaGalleryImages() as $image):

          $images[] = Mage::helper('catalog/image')->init($product, 'image', $image->getFile())->resize(100, 100);

          endforeach;


          Here you can also create Img tag in php and pass that Html code in response.






          share|improve this answer















          To optimize the speed, You can perform the following steps:



          • Create one JS function to call on hover on product Inage and Pass Product SKU as argument.

          • Create Ajax call to one Ajax Controller Action

          • In Ajax action Load Product and Fetch all the product images and pass response as HTML from action.

          • Insert the Response HTML in Gallery images div with unique ID as "gallery_image_SKU"

          • Apply check in JS function if images are there don't make Ajax call again.

          Below linnks give you more understaing about ajax call:



          How do i call a controller function in ajax?



          https://stackoverflow.com/questions/19383188/module-and-ajax-call



          http://javascriptsolution.com/call-magento-controller-using-ajax/



          Hope this help!!



          Updated: You can Load Images Like below. $images will contain complete image galleries path.



           $images = [];
          $product = Mage::getModel('catalog/product')->load(2);
          foreach ($product->getMediaGalleryImages() as $image):

          $images[] = Mage::helper('catalog/image')->init($product, 'image', $image->getFile())->resize(100, 100);

          endforeach;


          Here you can also create Img tag in php and pass that Html code in response.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 22 '18 at 17:19

























          answered Feb 22 '18 at 14:47









          Pankaj PareekPankaj Pareek

          2,48411338




          2,48411338












          • thank you, from what i understand i need to create module so i have started. I have created the module configl and controller and call it via jquery ajax inside my list.phtml but i do not understand what i should write inside IndexController.php to get all the gallery images once the ajax is called. Can you give example to start?i will update my question to add IndexController.php contents, module works ok so no need to add config.xml etc.

            – laxanorizo
            Feb 22 '18 at 16:29











          • I have updated my answer.

            – Pankaj Pareek
            Feb 22 '18 at 17:19











          • issue is that indexcontroller.php will always display nothing for image,price,name etc.if i try even to echo product_name it will not give any result. If i write something like echo 'test'; then it will display it iso they are connected with the controller. What do you think?Kindly have a look on my indexcontroller.php on the part "//here starts my tests trying to load product somehow?" How to make it understand that same product loads this controller and needs to send back gallery images through Ajax?must be doing something wrong..

            – laxanorizo
            Feb 22 '18 at 17:33











          • Don't echo anything. add code like return $images; exit; then you will get data in ajax

            – Pankaj Pareek
            Feb 22 '18 at 18:00











          • you are right about the return $value i am still learning. But no matter what i do it will not load data from the product that i trigger the Ajax call.On list.phtml i have a hover on the main image and inside that div i paste the jQuery.ajax. Controller connects ok cause if i write something dummy inside the indexcontroller.php will display on hover inside main image.But no way to get product's data, i want at least to get _name to make sure it returns data. Does it need a special method to load the product inside the controller and then call the data?I

            – laxanorizo
            Feb 23 '18 at 9:45

















          • thank you, from what i understand i need to create module so i have started. I have created the module configl and controller and call it via jquery ajax inside my list.phtml but i do not understand what i should write inside IndexController.php to get all the gallery images once the ajax is called. Can you give example to start?i will update my question to add IndexController.php contents, module works ok so no need to add config.xml etc.

            – laxanorizo
            Feb 22 '18 at 16:29











          • I have updated my answer.

            – Pankaj Pareek
            Feb 22 '18 at 17:19











          • issue is that indexcontroller.php will always display nothing for image,price,name etc.if i try even to echo product_name it will not give any result. If i write something like echo 'test'; then it will display it iso they are connected with the controller. What do you think?Kindly have a look on my indexcontroller.php on the part "//here starts my tests trying to load product somehow?" How to make it understand that same product loads this controller and needs to send back gallery images through Ajax?must be doing something wrong..

            – laxanorizo
            Feb 22 '18 at 17:33











          • Don't echo anything. add code like return $images; exit; then you will get data in ajax

            – Pankaj Pareek
            Feb 22 '18 at 18:00











          • you are right about the return $value i am still learning. But no matter what i do it will not load data from the product that i trigger the Ajax call.On list.phtml i have a hover on the main image and inside that div i paste the jQuery.ajax. Controller connects ok cause if i write something dummy inside the indexcontroller.php will display on hover inside main image.But no way to get product's data, i want at least to get _name to make sure it returns data. Does it need a special method to load the product inside the controller and then call the data?I

            – laxanorizo
            Feb 23 '18 at 9:45
















          thank you, from what i understand i need to create module so i have started. I have created the module configl and controller and call it via jquery ajax inside my list.phtml but i do not understand what i should write inside IndexController.php to get all the gallery images once the ajax is called. Can you give example to start?i will update my question to add IndexController.php contents, module works ok so no need to add config.xml etc.

          – laxanorizo
          Feb 22 '18 at 16:29





          thank you, from what i understand i need to create module so i have started. I have created the module configl and controller and call it via jquery ajax inside my list.phtml but i do not understand what i should write inside IndexController.php to get all the gallery images once the ajax is called. Can you give example to start?i will update my question to add IndexController.php contents, module works ok so no need to add config.xml etc.

          – laxanorizo
          Feb 22 '18 at 16:29













          I have updated my answer.

          – Pankaj Pareek
          Feb 22 '18 at 17:19





          I have updated my answer.

          – Pankaj Pareek
          Feb 22 '18 at 17:19













          issue is that indexcontroller.php will always display nothing for image,price,name etc.if i try even to echo product_name it will not give any result. If i write something like echo 'test'; then it will display it iso they are connected with the controller. What do you think?Kindly have a look on my indexcontroller.php on the part "//here starts my tests trying to load product somehow?" How to make it understand that same product loads this controller and needs to send back gallery images through Ajax?must be doing something wrong..

          – laxanorizo
          Feb 22 '18 at 17:33





          issue is that indexcontroller.php will always display nothing for image,price,name etc.if i try even to echo product_name it will not give any result. If i write something like echo 'test'; then it will display it iso they are connected with the controller. What do you think?Kindly have a look on my indexcontroller.php on the part "//here starts my tests trying to load product somehow?" How to make it understand that same product loads this controller and needs to send back gallery images through Ajax?must be doing something wrong..

          – laxanorizo
          Feb 22 '18 at 17:33













          Don't echo anything. add code like return $images; exit; then you will get data in ajax

          – Pankaj Pareek
          Feb 22 '18 at 18:00





          Don't echo anything. add code like return $images; exit; then you will get data in ajax

          – Pankaj Pareek
          Feb 22 '18 at 18:00













          you are right about the return $value i am still learning. But no matter what i do it will not load data from the product that i trigger the Ajax call.On list.phtml i have a hover on the main image and inside that div i paste the jQuery.ajax. Controller connects ok cause if i write something dummy inside the indexcontroller.php will display on hover inside main image.But no way to get product's data, i want at least to get _name to make sure it returns data. Does it need a special method to load the product inside the controller and then call the data?I

          – laxanorizo
          Feb 23 '18 at 9:45





          you are right about the return $value i am still learning. But no matter what i do it will not load data from the product that i trigger the Ajax call.On list.phtml i have a hover on the main image and inside that div i paste the jQuery.ajax. Controller connects ok cause if i write something dummy inside the indexcontroller.php will display on hover inside main image.But no way to get product's data, i want at least to get _name to make sure it returns data. Does it need a special method to load the product inside the controller and then call the data?I

          – laxanorizo
          Feb 23 '18 at 9:45

















          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%2f214650%2fload-all-gallery-images-in-category-on-hover-ajax%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

          Magento 2 duplicate PHPSESSID cookie when using session_start() in custom php scriptMagento 2: User cant logged in into to account page, no error showing!Magento duplicate on subdomainGrabbing storeview from cookie (after using language selector)How do I run php custom script on magento2Magento 2: Include PHP script in headerSession lock after using Cm_RedisSessionscript php to update stockMagento set cookie popupMagento 2 session id cookie - where to find it?How to import Configurable product from csv with custom attributes using php scriptMagento 2 run custom PHP script

          Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

          How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2