php echo $this->getPriceHtml($_product, true) ?>
<div class=“actions”>
<?php if($_product->isSaleable()): ?>
<button type=“button” title=”<?php echo $this->(‘Add to Cart’) ?>” class=“button btn-cart” onclick=“setLocation(’<?php echo $this->getAddToCartUrl($_product) ?>’)”><span><span><?php echo $this->(‘Add to Cart’) ?></span></span></button>
<?php else: ?>
<p class=“availability out-of-stock”><span><?php echo $this->(‘Out of stock’) ?></span></p>
<?php endif; ?>
<ul class=“add-to-links”>
<?php if ($this->helper(‘wishlist’)->isAllow()) : ?>
<li><a href=”<?php echo $this->helper(‘wishlist’)->getAddUrl($_product) ?>” class=“link-wishlist”><?php echo $this->(‘Add to Wishlist’) ?></a></li>
<?php endif; ?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
<li><span class=“separator”>|</span> <a href=”<?php echo $_compareUrl ?>” class=“link-compare”><?php echo $this->__(‘Add to Compare’) ?></a></li>
<?php endif; ?>
</ul>
</div>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php else: ?>
<?php $imgprd[]=$_product ?>
<?php endif; ?>
<?php endforeach ?>
<?php foreach ($imgprd as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
<h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?>
<?php echo $this->getPriceHtml($_product, true) ?>
<div class="actions">
<?php if($_product->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<ul class="add-to-links">
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
<?php endif; ?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
<li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
<?php endif; ?>
</ul>
</div>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
<?php endif; ?>
<div class=“toolbar-bottom”>
<?php echo $this->getToolbarHtml() ?>
</div>
The code provided appears to be a section of a Magento template file, specifically dealing with the rendering of product items in a grid layout. Let me break down what’s happening:
- The initial foreach loop iterates through each product item in the collection.
- Inside this loop, it checks if the current iteration is divisible by
$_columnCountor if it’s the last element. If either condition is true, it closes the current<ul>tag and starts a new one. - For each product item, it generates an HTML list item (
<li>) with several elements:- A hyperlink to the product page, displaying the product name using the
getProductUrlandproductAttributemethods. - An image of the product using the
helper('catalog/image')method to resize the small image. - The product’s rating summary if available.
- The price of the product rendered by
getPriceHtml($_product, true). - A “actions” div containing:
- An “Add to Cart” button for saleable products or an “Out of stock” message for non-saleable ones.
- A wishlist link if allowed by Magento.
- A comparison link if available.
- A hyperlink to the product page, displaying the product name using the
- After the main foreach loop, it checks if there’s any product item left in
$imgprd. If so, it processes them using a second foreach loop (which seems redundant). - The script then decorates the generated grid with CSS classes and adds a toolbar at the bottom rendered by
getToolbarHtml().
Overall, this code snippet is responsible for generating HTML to display products in a grid layout on a Magento site, showcasing product images, names, prices, and interactive elements like “Add to Cart”, “Wishlist”, and “Comparison”.