Showing posts with label New arrivals in magento. Show all posts
Showing posts with label New arrivals in magento. Show all posts

Friday, 21 August 2015

Display first five products of all category magento


Display first five products of all category magento

Here i have created New Arrivals page. In this page all the functionality are included like products by category id, Products by specific category, Latest five products of category, New Arrivals page/category.

You can use this code as per your need.

First Go to CMS page and create a new CMS page named New Arrivals then copy and paste below code in content area.

{{block type="catalog/product_list" name=”newarrivals”  template="catalog/product/newarrivals.phtml"}}

Make newarrivals.phtml in catalog/product/ of your theme and paste below code.

<?php
    $subcategoryCollection = Mage::getModel('catalog/category')->getCollection()->addAttributeToFilter('parent_id', 2)->addAttributeToSort('position');
    foreach($subcategoryCollection as $_subcategoryCollection)
     {
        $categoryId = $_subcategoryCollection->getEntityId();
        $categoryName = Mage::getModel('catalog/category')->load($categoryId);
        if($categoryName->getIsActive() == 1){
?>
  <div class="col-sm-12">
              <div class="row">
                  <div class="queried-for">
                     <h1 class="q"><a href="<?php echo $categoryName->getUrl(); ?>"><?php echo $categoryName->getName(); ?></a></h1>
                  </div>
                  <a class="pull-right btn-md btn-link m-t-xs" href="<?php echo $categoryName->getUrl(); ?>">View All</a>
              </div>
           </div>  

<?php
            $_productCollection = Mage::getModel('catalog/category')->load($categoryId)
                ->getProductCollection()
                ->addAttributeToSelect('*')
                ->addAttributeToFilter('status', 1)
                ->addAttributeToFilter('visibility', 4)
                ->addAttributeToSort('entity_id', 'desc');
            $_productCollection->getSelect()->limit(5);
            ?>
 
            <div class="category-products row new-arrivals">
                <div class="product-grid products-grid">
                    <?php foreach ($_productCollection as $_product): ?>
                        <div class="product-item col-md-3 col-sm-3 col-sms-4 col-xs-6">
                            <div class="product-img">
                                <a class="product-image" href="<?php echo $_product->getProductUrl() ?>">
                                    <img class="img-full" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->keepFrame(false)->resize(180,270); ?>" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />
                                </a>
                                <div class="actions">
                                    <a href="<?php echo $_product->getProductUrl() ?>" class="btn btn-actions"><i class="fa fa-shopping-cart"></i>Buy</a>
                                    <a href="<?php echo $this->getUrl('banner/listpopup/index/') ?>?id=<?php echo $_product->getId();?>" class="btn btn-actions" data-target="#listModel_<?php echo $_product->getId();?>" data-toggle="modal"><i class="fa fa-eye"></i>Quick View </a>
                                    <button onclick="setLocation('<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>')" class="btn btn-actions"><i class="fa fa-star-o"></i>wishlist</button>
                                </div>
                                <div class="modal fade listModel" id="listModel_<?php echo $_product->getId();?>" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
                                    <div class="modal-dialog modal-lg">
                                        <div class="modal-content">
                                            <div class="proloader text-center"><img src="<?php echo $this->getSkinUrl('images/preloader.gif'); ?>" /></div>
                                        </div>
                                    </div>
                                </div>
 
                            </div>
                            <?php
                                $price = $_product->getPrice();
                                $specialprice = $_product->getFinalPrice();
                                $save = $price - $specialprice;
                                $totalPercent = (($price - $specialprice) / $price)*100;
                            ?>
 
                            <div class="product-info">
                                <div class="product"><?php echo substr($_product->getName(),0,50); ?></div>
                                <?php if($totalPercent > 0): ?>
                                    <div class="price"><span class="strike"><?php echo Mage::helper('core')->currency($price); ?></span><?php echo Mage::helper('core')->currency($specialprice); ?><span class="discount"><?php echo round($totalPercent); ?>% OFF</span></div>
                                <?php else: ?>
                                    <div class="price"><?php echo Mage::helper('core')->currency($specialprice); ?></div>
                                <?php endif; ?>  
                            </div>
                        </div>
             
                        <?php
                        // Note: Exit after first product.
                            //break;
                        ?>
                    <?php endforeach ?>
                </div>  
            </div>
  <?php } ?>    
<?php } ?>