Friday, June 2, 2017

Display specific products on homepage magento

Hello

Now i explain you how to display any specific products on homepage of magento. In admin side, you have to give product ids with coma, and it will display that products.

1st step : Create custom-list1.phtml file in this path : app/design/frontend/[yourthemename]/default/template/catalog/product/

Code:
Start code
<?php
$data=$this->getData('product_id');
    $productIds = explode(',',$data);

    $products = Mage::getModel('catalog/product')->getCollection()
            ->addAttributeToSelect('*')
                ->addAttributeToFilter('entity_id', array('in' => $productIds));
       
    $products->getSelect()->order("find_in_set(entity_id,'".implode(',',$productIds)."')");

    $_helper = $this->helper('catalog/output');
    ?>
  
    <div class="category-products">
   
        <ul class="products-grid row">
<?php foreach($products as $_product){  ?>
            <li class="item col-xs-12 col-sm-3" style="margin-left:0 !important;" >
                <div class="wrapper-hover">
                    <a href="<?php echo $_product->getUrlInStore(array('_ignore_category' => true)); ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" class="product-image"><img  src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->keepFrame(true)->resize(255,344)->keepAspectRatio(true); ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a>
                    <div class="product-shop">
                        <?php $productBlock = $this->getLayout()->createBlock('catalog/product_price');
                            echo $productBlock->getPriceHtml($_product); ?>
                            <?php $ab = $_product->getTierPrice(); if($ab){ ?>
                            <?php $_groupedProductChildPrices=array();

// get child products of grouped product
//
$_childProductIds = $_product->getTypeInstance()->getChildrenIds($_product->getId());

foreach ($_childProductIds as $_ids) {

    foreach ($_ids as $_id) {

        $_childProduct = Mage::getModel('catalog/product')->load($_id);

        // get all associated group product pricing, including tier prices
        $_groupedProductChildPrices[] = $_childProduct['price'];

            if($_childProduct->getTierPrice() != NULL) {
                foreach($_childProduct->getTierPrice() as $tier){
                    $_groupedProductChildPrices[]= $tier['price'];
                }
            }

    }
}?>
<div class="price-box">
<a href="<?php echo $_product->getProductUrl(); ?>" class="minimal-price-link">
<span class="label"><?php echo $this->__('As low as:') ?></span>
        <span class="price" id="product-minimal-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
               <?php echo '$'.$_lowestGroupProductPrice=round(min($_groupedProductChildPrices),2); ?>
            </span>
                            </a></div><?php } //endif $ab ?>
                        <h3 class="product-name">
                            <a href="<?php echo $_product->getUrlInStore(array('_ignore_category' => true)); ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
                                <?php $small_getName = strip_tags($this->htmlEscape($_product->getName()));
                                 if (strlen($small_getName) < 20) echo($small_getName);
                                 else { echo mb_substr($small_getName, 0, 50,'UTF-8').'...';} ?>
                            </a>
                        </h3> 
                       <div class="wrapper-hover-hiden">
                           <div class="desc_grid"><?php $small_getDescription = strip_tags($_product->getShortDescription());
                                 if (strlen($small_getDescription) < 101) echo($small_getDescription);
                                 else { echo mb_substr($small_getDescription, 0, 85,'UTF-8').'...';} ?></div>
                            <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                            <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 $_product->getUrlInStore(array('_ignore_category' => true)); ?>')"><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; ?>
                               
                            </div>
                       </div>
                       <div class="viewproduct">
                           <button type="button" title="<?php echo $this->__('View This Product') ?>" class="button btn-cart" onclick="setLocation('<?php echo $_product->getUrlInStore(array('_ignore_category' => true)); ?>')"><span><span><?php echo $this->__('Shop Now') ?></span></span></button>
                       </div>
                    </div>
                    <?php $_product = Mage::getModel('catalog/product')->load($_product->getId()); ?>
                    <div class="label-product">       
                        <?php if (date("Y-m-d") >= substr($_product->getNewsFromDate(), 0, 10) && date("Y-m-d") <= substr($_product->getNewsToDate(), 0, 10)) {echo '<span class="new">'.$this->__('New').'</span>'; } ?>
                        <?php if($_product->getData('new')){echo '<span class="new">'.$this->__('New').'</span>';  }?>
                        <?php if($_product->getData('sale')){echo '<span class="sale">'.$this->__('Sale').'</span>';  }?>
                    </div>
                    <div class="clear"></div>
                </div>
            </li>
        <?php } ?>
        </ul>
</div>
End code

2nd step : Go to your homepage cms page and put this code :

<div class="row">
<div class="page-title col-xs-12 category-title1">
<h2>Picked by admin:</h2>
</div>
</div>
<div class="home_block">{{block type="catalog/product_list" column_count="3" product_id="519,513,511,506" template="catalog/product/custom-list1.phtml"}}</div>

3rd Step :  Now do these :
  1. Navigate to System->Permissions->Blocks.
  2. Click on the Add new block button.
  3. Specify your Block Name, which is: catalog/product_list.
  4. And allow the Block using the YES/No Dropdown list:
4th Step : Clean your all catch

Now you can hard refresh your home page.

Reference : https://www.templatemonster.com/help/magento-how-to-display-products-of-specific-category-on-home-page.html

No comments:

Post a Comment