Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Produtos Randômicos / Aleatórios em determinado template • 1.7.0.2
 
Hell Bandit
Jr. Member
 
Total Posts:  14
Joined:  2009-09-03
 

Bom pessoal, gostaria de tirar uma dúvida referente ao template que uso, mais especificamente um determinado arquivo ("home_product.phtml"), mas o nome não é importante, e sim que esse é o arquivo do layout dos “Novos Produtos” apresentados na Home do meu site em desenvolvimento (Conferir aqui o andamento: www.infotecbr.com/imports ).

Pra ser mais direto, gostaria de fazer com que os produtos pertencentes na área de “Novos Produtos” apareçam de forma randômica, pois para destacar alguns produtos já tenho outra solução em outro bloco na Home.

Lembrando que utilizo a versão 1.7.0.2

Conteúdo da Home Page:

<div class="banner_box">
<
div class="slider">
<
div class="flexslider">
<
ul class="slides">
<
li><a href="#"><img src="{{skin url=images/banner1.jpg}}" alt="" /></a></li>
<
li><a href="#"><img src="{{skin url=images/banner2.jpg}}" alt="" /></a></li>
<
li><a href="#"><img src="{{skin url=images/banner3.jpg}}" alt="" /></a></li>
<
li><a href="#"><img src="{{skin url=images/banner4.jpg}}" alt="" /></a></li>
</
ul>
</
div>
</
div>
</
div>
<
div>{{block type="catalog/product_list" template="catalog/product/promotional_block.phtml"}}</div>
<
div class="box-center">
<
div class="special">{{block type="catalog/product_list"template="catalog/product/home_list.phtml"}}</div>
</
div>
<
div class="new_products">{{block type="catalog/product_list" limit="4" column_count="4" category_id="3" template="catalog/product/home_product.phtml"}}</div>

Conteúdo integral do arquivo “home_product.phtml”:

/app/design/frontend/default/megashop/template/catalog/product

<div class="home_product sixteen columns">
<?php
$cObj 
Mage::getModel('catalog/category')->load(2);

$visibility = array(
         
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
         
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
     
);
$productObj $cObj->getProductCollection()->addAttributeToFilter('visibility'$visibility)->getData();
$_helper $this->helper('catalog/output');
?>
<?php 
if(count($productObj)<=0): ?>
<class="note-msg"><?php echo $this->__('There are no products matching the selection.'?></p>
<?php else: ?>
<h1 class="line_heading"><span><?php echo $this->__('Novos Produtos')?></span> <class="viewall" title="View All" href="<?php echo $cObj->getUrl() ?>">View all</a> </h1>
<
div class="category-products">
<
ul class="products-grid">
     
<?php $i=1;
$count=1;
foreach(
$productObj as $_productData): ?>
<?php $_product 
Mage::getModel('catalog/product')->load($_productData['entity_id']); ?>
         
<li class="item <?php if($count%4==0) echo 'last'; ?> <?php echo 'quick'.$_product->getId();?>">
         <
div class="outer_pan">    
             <
div class="image_rotate">
             <
div class="image_rotate_inner">
             <
a href="<?php echo $_product->getProductUrl() ?>" class="product-image">
             
<?php $_product Mage::getModel('catalog/product')->load($_product->getId()); ?>
<img class="firstImg" src="<?php echo Mage::helper('catalog/image')->init($_product, 'image')->constrainOnly(true)->keepFrame(true)->resize(245); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
             
<?php //if($_product->getData('flip_view')){echo $this->__('<img src="%s"/>',$this->helper('catalog/image')->init($_product, 'flip_view')->resize(201,201));}?>
             
<?php echo $this->__('<img src="%s"/>',$this->helper('catalog/image')->init($_product'flip_view')->keepFrame(true)->resize(245));?>
                 
</a>
                 </
div>
             </
div>
                 
<?php if($_product->getRatingSummary()): ?>
             <?php 
echo $this->getReviewsSummaryHtml($_product'short'?>
             <?php 
endif; ?>
         
<div class="badge">
         
<?php if($_product->getData('new')){echo '<span class="new">'$_product->getAttributeText('new').'</span>'}?>
         <?php 
if($_product->getData('sale')){echo '<span class="sale">'$_product->getAttributeText('sale').'</span>'}?>
         
</div>
            
            
             </
div>
             <
div class="outer_bottom">
            
             <
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 echo $this->getPriceHtml($_producttrue?>
            
             
<div class="product_icons">
            
            
                
                     
<?php if($_product->isSaleable()): ?>
                 <?php 
if ( !($_product->getTypeInstance(true)->hasRequiredOptions($_product) || $_product->isGrouped()) ) { ?>
                     
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocationAjax('<?php echo $this->getAddToCartUrl($_product) ?>','<?php echo $_product->getId()?>')"><span><span><?php echo $this->__('Add to Cart'?></span></span></button>
                     <
span class="cat_loader" id='ajax_loader<?php echo $_product->getId()?>' style='display:none'>
                     <
span class="cart_msg">
                     <
img alt="" src='<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>'/>
                     </
span>
                     </
span>
                    
                     
<?php } else { ?>
                     
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="showOptions('<?php echo $_product->getId()?>')"><span><span><?php echo $this->__('Add to Cart'?></span></span></button>
                    
                     
<?php } ?>
                 <?php 
else: ?>
                     
<class="availability out-of-stock"><span><?php echo $this->__('Out of stock'?></span></p>
                 
<?php endif; ?>
                
                     <?php 
if($_product->isSaleable()): ?>
                
                     
<a href='<?php echo $this->getUrl('ajax/index/options',array('product_id'=>$_product->getId()));?>' class='fancybox quick_view <?php echo 'quick_box'.$_product->getId();?>' id='fancybox<?php echo $_product->getId()?>'>quick view</a>
                    
                 
<?php else: ?>
                     
<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) ?>" title="Add to Wishlist" class="link-wishlist"><?php echo $this->__('Add to Wishlist'?></a></li>
                     
<?php endif; ?>
                     <?php 
if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                         
<li class="last"> <a href="<?php echo $_compareUrl ?>" title="Add to Compare" class="link-compare"><?php echo $this->__('Add to Compare'?></a></li>
                     
<?php endif; ?>
                 
</ul>
             </
div>
             </
div>
         </
li>
     
<?php
$count
=$count+1;
if(
$count==41)
break;
endforeach 
?>
     
</ul>
<?php endif; ?>
</div>
</
div>
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top