Question

I am trying to display the description for each product in the slide down panel. I am using a slider to display product images where I have a on hover buttons first one adds the product to basket and the second one triggers the slide down panel. It displays random products description not the one I click on.

<div id="owl-demo" class="owl-carousel">
 <?php  $categoryId = 4; // this is the category holding your products  
 $category = Mage::getModel('catalog/category')->load($categoryId);
 $products = Mage::getModel('catalog/product')
   ->getCollection()
   ->addCategoryFilter($category);
 $products->addAttributeToSelect(array(
                              'image',
                              'name',
                              'description',
                             'short_description',
     'sku',
     'asin'
              ))
              ->addFieldToFilter('visibility', array(
                             Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
                          Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
              )); 

 //$products->load();
 foreach ($products as $product)  { 
 ?>
 <div class="item">
 <img  class="lazyOwl" src="<?php echo $localHelper->getImageUrl($product); ?>" alt="img" />
<button type="button" title="<?php echo $this->__() ?>" 
 class="addp" onclick="setLocation
 ('<?php echo Mage::helper('checkout/cart')->getAddUrl($product) ?>')">
 <span><span><?php echo $this->__() ?></span></span></button>
   <button type="button" class="info" data-target='t1'>
   <?php

  $description = $product->getDescription();

  ?>
  </button>

 </div>  
 <?php
  }
 ?>
</div>

 <div class="toggles" data-target='t1'>
  <p> <?php echo $description; ?> </p>  
 </div>

I would like to get Description for each products I click on no the same one for all of them.

Was it helpful?

Solution

you have to echo description inside the loop. you are echo it outside the so it is showing last description.

     $description='';

         foreach ($products as $product)  { 
             ?>
             <div class="item">
             <img  class="lazyOwl" src="<?php echo $localHelper->getImageUrl($product); ?>" alt="img" />
            <button type="button" title="<?php echo $this->__() ?>" 
             class="addp" onclick="setLocation
             ('<?php echo Mage::helper('checkout/cart')->getAddUrl($product) ?>')">
             <span><span><?php echo $this->__() ?></span></span></button>
               <button type="button" class="info" data-target='t<?php echo $product->getId() ?>'>
               <?php

              $description .= $product->getDescription().'<br />';

              ?>
              </button>

             </div> 


         <?php
          }
         ?>
        </div>

   <?php  foreach ($products as $product)  { ?>
    <div class="toggles" data-target='t<?php echo $product->getid()?>'>
          <p> <?php echo  $product->getDescription(); ?> </p>

         </div> 
<?php } ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top