2016-05-24 16 views
0

私がホームページに追加した最後の8製品を表示します。どうやってやるの?Magento:最近追加された製品のホームページを表示

+1

「Magento:最近追加された製品のホームページを表示する」と検索すると、多くの結果が得られます。常に最初に検索することを忘れないでください。 –

+0

はい、このような例が多数見つかりましたが、機能しません。 {{block type = "catalog/product_new" column_count = "1" products_count = "8" name = "home.catalog.product.new" alias = " product_homepage "template =" catalog/product/new.phtml "}} – Badslayer

答えて

0

ブロックファイル前の回答が得られますフォームのため、このコードスニペットを使用して次の理由により、より構造化されたコレクションです。

  • (設定の簡単な製品(「個別に見えない」デフォルトである)このコレクションには表示されません)可視性によって
  • フィルタ製品を有効状態によるフィルタ製品

$_productCollection = Mage::getModel("catalog/product") ->getCollection() ->addAttributeToSelect('*') ->addAttributeToFilter('visibility', 4) ->addAttributeToFilter( 'status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED) );

0
<b> To show recently added products,</b> 
     1. Create Block file and template file (phtml) 
     2. To show in homepage go to admin panel. Click on CMS->Pages->Homepage(Homepage will be set based on your theme). Inside that Click on Design tab and add the below code: 

    <reference name="content"> 
     <block type="rileytheme/recentproducts" name="recentproducts_recentproducts" template="recentproducts/recentproducts.phtml"></block> 
     <block type="cms/block" name="myelement"><action method="setBlockId"<block_id>homepage_block</block_id></action></block> 
    </reference> 

ブロックファイル:

 //class Namespace_Module_Block_Filename 
     class MGS_Rileytheme_Block_Recentproducts extends Mage_Core_Block_Template { 
     public function getRecentProducts() { <br/> 
      $products = Mage::getModel("catalog/product") 
         ->getCollection() 
         ->addAttributeToSelect('*') 
         ->setOrder('entity_id', 'DESC') 
         ->setPageSize(5); //set page size as your wish 
      return $products; 
      } 

表示ファイル(PHTML):

<?php $products = $this->getRecentProducts(); ?> 
<?php shuffle($products); ?> 
<div class="container"> 
<div class="box recently" style="padding-left:15px; padding-right:15px;"> 
    <h1 class="text-center fw400 text-red"><?php echo $this->__('Recent Products') ?></h3> 
    <div class="listing-type-grid catalog-listing"> 
    <?php $_collectionSize = count($products) ?> 
     <?php $i=0; foreach ($products as $_res): ?> 
     <?php $_product = Mage::getModel('catalog/product')->load($_res->getId()); ?> 
      <?php if ($i++%3==0): ?><tr><?php endif ?> 
       <div class="col-xs-12 col-sm-6 col-md-3 prod-list"> 
        <div class="grid_list"> 
         <div class="product"> 
          <div class="image-container"> 
         <?php if($_product->getProductLabel()): ?> 
          <a href="<?php echo $_product->getProductUrl() ?>"> 
           <span class="onsale <?php echo strtolower($_product->getAttributeText('product_label')) ?>"><?php echo $_product->getAttributeText('product_label') ?></span> 
          </a> 
         <?php endif ?> 

          <img alt="" class="img-responsive" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(800,800); ?>"> 
          <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->__('View detail')?>" class="icon-left icon-top "> 
           <i class="fa fa-eye"></i> 
          </a> 
          <a href="<?php echo $_product->getProductUrl()?>" title="<?php echo $this->__('Add to Cart')?>" class="icon-right icon-top"> 
           <i class="fa fa-shopping-cart"></i> 
          </a> 
          <?php if($this->helper('wishlist')->isAllow()): ?> 
           <!--<a class="icon-left ves-boxcolor icon-bottom" href="<?php echo $this->helper('wishlist')->getAddUrl($_product)?>" title="<?php echo $this->__('Add to wishlist')?>"> 
            <i class="fa fa-heart"></i> 
           </a>--> 
          <?php endif;?> 
          <?php if($this->getAddToCompareUrl($_product)): ?> 
          <!--<a class="icon-right boxcolor icon-bottom" href="<?php echo $this->getAddToCompareUrl($_product)?>" title="<?php echo $this->__('Add to compare')?>"> 
           <i class="fa fa-retweet"></i> 
          </a>--> 
          <?php endif;?> 
        </div> 
           <!--<div class="media-productlist"> 
            <a href="<?php // echo $_product->getProductUrl() ?>" title="<?php // echo $this->htmlEscape($_product->getName()) ?>"> 
            <img class="product-image" src="<?php // echo $this->helper('catalog/image')->init($_product, 'small_image');?>" alt="<?php // echo $this->htmlEscape($_product->getName()) ?>" /> 
            </a> 
           </div>--> 
          <div class="product-list-data"> 
           <a class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a> 
            <div class="product-list-data-inner"> 
            <div class="cart-item-price"> 
             <?php $_product->getPrice();?> 
             <span class="price"><?php echo $_formattedActualPrice = Mage::helper('core')->currency($_product->getPrice(),true,false);?></span> 
            </div> 
            <div class="cart-item-stars"> 
            <div class="rating-shop-item"> 
             <?php if($_product->getRatingSummary()): ?> 
              <?php echo $this->getReviewsSummaryHtml($_product) ?> 
             <?php else:?> 
              <span class="star"></span> 
              <span class="star"></span> 
              <span class="star"></span> 
              <span class="star"></span> 
              <span class="star"></span> 
             <?php endif; ?> 
            </div> 

            <div class="space10"></div> 
            </div> 
        <div class="book-now-btn"> 
         <button onclick="setLocation('<?php echo $_product->getProductUrl() ?>')" title="<?php echo $this->__('Book Now') ?>" type="button" class="btn btn-primary btn-sm"><?php echo $this->__('Book Now') ?></button> 
        </div> 
           </div> 
          </div> 
         </div> 
        </div> 
       </div> 
       <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?> 
       <?php if ($i%3==0 && $i!=$_collectionSize): ?></tr><?php endif ?> 
     <?php endforeach ?> 
     <?php for($i;$i%3!=0;$i++): ?> 
      <td class="empty-product">&nbsp;</td> 
     <?php endfor ?> 
     <?php if ($i%3==0): ?>&nbsp;<?php endif ?> 
    </div> 
</div> 
</div> 
関連する問題