Magento home page popular products - magento

Hi All I want to show 4 popular products on the home page of my magento 1.7.1 install. (The I can select by putting them into a category).
I've set this up by creating a hidden category called popularhome and added 4 products into it.
I've included this in a static block into my home page template by using:
{{block type="catalog/product_list" column_count="4" category_id="17" template="catalog/product/listhome.phtml"}}
My listhome.phtml template looks like this:
<div class="row popularproducts">
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<div class="alert fade in">
<a class="close" data-dismiss="alert">×</a>
<?php echo $this->__('There are no products matching the selection.') ?>
</div>
<?php else: ?>
<?php // List mode ?>
<?php if($this->getMode()!='grid'): ?>
<?php $_iterator = 0; ?>
<?php else: ?>
<?php // Grid Mode ?>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<?php endif ?>
<div class="c3">
<?php if(($i-1)%$_columnCount==0): ?><?php elseif($i%$_columnCount==0): ?><?php endif; ?>
<div class="thumbnail">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(225); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<div class="caption">
<h2 class="product-name"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h2>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?>
<?php echo $this->getPriceHtml($_product, true) ?>
</div>
</div>
</div>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
<?php endif ?>
<?php endforeach ?>
<?php endif; ?>
<?php endif; ?>
</div>
However this is only showing 2 of the 4 products yet I cannot figure out why? Does anyone see anything I am missing?
Thanks!

First you need to check ,the products that you want to be appear in category page,
Is they really belong to that categories.
After that make sure Backend > Manage Categories > Edit categories > Display settings >
is Anchor = yes Then re-index your catalog.
To verify you need to cross check catalog_category_product and catalog_category_product_index.
If the category id and product id is mapped properly in these tables you should be good to go.
hope this will sure help you!

Related

Magento pagination is not displaying on Catalog page

In my magento website it is not displying page numbers on the bottom....In this website I have around 6-7 categories and every category has around 50 products
Changes I have made to the Magento admin panels are:
under admin -> Catalog -> Catalog -> Frontend
And under admin -> General -> Design-> Pagination
I'hv only made changes in these
Still page number on the product page not showing on here
Any Ideas why its happening?
EDIT:
This is my frontend\mgstheme\luxury\template\catalog/category/view.phtml page
<?php
$_helper = $this->helper('catalog/output');
$_category = $this->getCurrentCategory();
$_imgHtml = '';
if ($_imgUrl = $_category->getImageUrl()) {
$_imgHtml = '<p class="category-image"><img class="img-responsive" src="' . $_imgUrl . '" alt="' . $this->escapeHtml($_category->getName()) . '" title="' . $this->escapeHtml($_category->getName()) . '" /></p>';
$_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
$settingDescPosition = 1;
$setting = Mage::getModel('mpanel/setting')->load($_category->getId());
if($setting){
if($setting->getRatio()!=''){
$settingDescPosition = $setting->getDescPosition();
}
}
?>
<div class="page-title category-title">
<?php if ($this->IsRssCatalogEnable() && $this->IsTopCategory()): ?>
<?php echo $this->__('Subscribe to RSS Feed') ?>
<?php endif; ?>
</div>
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<?php $helper = $this->helper('mpanel'); ?>
<div class="custom">
<div class="container">
<span><i class="fa fa-home"></i> / <span>Products</span> / <span><strong><?php echo $this->getCurrentCategory()->getName(); ?></strong></span></span>
</div>
</div>
<?php if ($this->isContentMode()): ?>
<?php echo $this->getCmsBlockHtml() ?>
<?php elseif ($this->isMixedMode()): ?>
<?php echo $this->getCmsBlockHtml() ?>
<div id="product-list-container">
<?php echo $this->getProductListHtml() ?>
</div>
<?php else: ?>
<div id="product-list-container">
<?php echo $this->getProductListHtml() ?>
</div>
<?php endif; ?>
<?php if ($helper->acceptToUsePanel()): ?>
<?php // description position below product list ?>
<?php if($settingDescPosition==2): ?>
<div class="builder-container inline-builder">
<?php if ($_description = $this->getCurrentCategory()->getDescription()): ?>
<div class="category-description std">
<?php echo $_helper->categoryAttribute($_category, $_description, 'description') ?>
</div>
<?php echo $helper->getEditCategoryDescription($_category->getId()) ?>
<?php else: ?>
<div class="category-description std">
<span class="placeholder">Add description for this category</span>
</div>
<?php echo $helper->getEditCategoryDescription($_category->getId()) ?>
<?php endif; ?>
</div>
<?php endif ?>
<?php else: ?>
<?php // description position below product list ?>
<?php if($settingDescPosition==2): ?>
<?php if ($_description = $this->getCurrentCategory()->getDescription()): ?>
<div class="category-description std">
<?php echo $_helper->categoryAttribute($_category, $_description, 'description') ?>
</div>
<?php endif; ?>
<?php endif ?>
<?php endif; ?>
Solved
Added this code to the view.phtml
<?php echo $this->getToolbarBlock()->setTemplate('catalog/product/list/bottom_toolbar.phtml')->toHtml(); ?>
Check in the catalog.xml whether you have called xml for pagination. The xml should be as below
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
As per your screenshot, you are using custom theme so please recheck all phtml files are in there folder related with pagination.
If still you are facing the same issue, so please see the below link that will help you :
https://support.webcto.eu/index.php/Knowledgebase/Article/View/43/8/paginating-not-shown-in-magento

How to display all categories in Magento not top level category?

I tried this link and displaying all the categories in home page but it is displaying only the top level categories. I want to display all the categories.
<div class=”block block-verticalmenu”>
<div class=”block-title”>
<strong><span><?php echo $this->__(‘Categories’) ?></span></strong>
</div><!–End block block-cart–>
<div class=”block-content”>
<ul id=”ma-accordion” class=”accordion”>
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php endforeach ?> </ul>
</div><!–End Of vertical-nav–>
<?php echo $this->getChildHtml(‘topLeftLinks’) ?>
</div><!–End Of vertical-nav-container box base-mini–>
You could try replacing the function call
echo $this->drawItem($_category)
by
echo $this->drawOpenCategoryItem($_category)
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<ul>
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>

Display specific category products on no results search page

When we search for a wrong keyword like "sdfsdf" in magento site, it displays that "your search returns no results". Here I want to display any category products like "similar products" category as we display "best sellers" on home page. I have tried by calling the block in the catalogsearch.xml. BUt catalogsearch.xml doent contain any block for no results. So how can I display any category products on no results page.
I have an idea like can we display a specific category products on .phtml page? If we can display specific category of products then we can call that category from "result.phtml". Any help?
my result.phtml
<?php if($this->getResultCount()): ?>
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<div class="page-title category-title">
<?php if ($this->helper('rss/catalog')->getTagFeedUrl()): ?>
<?php echo $this->__('Subscribe to Feed') ?>
<?php endif; ?>
<h1><?php echo ($this->getHeaderText() || $this->getHeaderText() === false) ? $this->getHeaderText() : $this->__("Search results for '%s'", $this->helper('catalogsearch')->getEscapedQueryText()) ?></h1>
</div>
<?php if ($messages = $this->getNoteMessages()):?>
<p class="note-msg">
<?php foreach ($messages as $message):?>
<?php echo $message?><br />
<?php endforeach;?>
</p>
<?php endif; ?>
<?php echo $this->getProductListHtml() ?>
<?php else: ?>
<div class="page-title category-title">
<h1><?php echo ($this->getHeaderText() || $this->getHeaderText() === false) ? $this->getHeaderText() : $this->__("Search results for '%s'", $this->helper('catalogsearch')->getEscapedQueryText()) ?></h1>
</div>
<p class="note-msg">
<?php echo ($this->getNoResultText()) ? $this->getNoResultText() : $this->__('Your search returns no results.') ?>
<?php if ($messages = $this->getNoteMessages()):?>
<?php foreach ($messages as $message):?>
<br /><?php echo $message?>
<?php endforeach;?>
<?php endif; ?>
</p>
<div class="search-noresults">
<h1>Meanwhile, You may go through our featured categories:</h1>
</div>
<?php echo $this->getLayout()->CreateBlock('catalog/product_list')->setCategoryId(18)->setTemplate('catalog/product/list.phtml')->toHtml();?>
<?php endif; ?>
A simple solution is within catalogsearch/result.phtml template you would need to setup what happens when there are no results
<?php if($this->getResultCount()): ?>
SHOW RESULTS
LEAVE DEFAULT
<?php else: ?>
NO RESULTS
<?php echo $this->getLayout()->createBlock('catalog/product_list')->setCategoryId(4)->setTemplate('catalog/product/list.phtml')->toHtml() ?>
<?php endif; ?>

Magento: getAttributeText('manufacturer') doesn't work

I would very much appreciate your help. I am new to Magento and exploring it's possibilities. I have this piece of code, which loads products from category and their attributes:
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
<?php // Grid Mode ?>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $_iterator = 0; ?>
<ul class="products-grid">
<?php $i=0; foreach ($_productCollection as $_product): ?>
<li class="item">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(252); ?>" width="252" height="252" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<h3 class="product-name"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h3>
<h4 class="product-name"><?php echo $_product->getAttributeText('manufacturer') ?></h4>
<?php echo $this->getPriceHtml($_product, true) ?>
</li>
<?php endforeach ?>
</ul>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
</div>
<?php endif; ?>
My question is: why "echo $_product->getAttributeText('manufacturer')" is not working here? I have tried countless variants with different code, but the manufacturer parameter just doesn't show up. Do you know why?
I have tried what Adam Moss has suggested and it worked:
'Show in Product Listing' needed to be set to yes in the attribute editor in admin. Then echo $_product->getAttributeText('manufacturer') worked without any problems.
so I got this working using #Shawn_Northrop suggestion;
<?php
echo $_product->getData('my_custom_attribute');
?>
Happy Coding...

how to write a custom panel displaying categories in magento

I have a category called "Top Products". I wish to display this in a panel on my home page. What is the best way to do this in magento.
** edit **
Thanks sdek, i now have the following. In Home Page / Design.
<block type="catalog/product_list" category_id="13" template="catalog/product/featured.phtml"/>
And it is displaying products. However i have the following issues.
- it's not displaying products from category_id 13, It seems like this value is not being passed thru
- it's only display 2 products. I wish to display all.
featured.phtml
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<h2>Featured Products </h2>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="product-grid">
<?php endif ?>
<li class="<?php if(($i-1)%$_columnCount==0): ?> first<?php else: ?> last<?php endif; ?>">
<a class="product-image" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" >
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(85); ?>" class="product-img" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" style="padding-bottom:20px; margin-bottom:20px;" />
</a>
<p><strong><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></strong>
<?php echo $_product->getShortDescription(); ?></p>
<?php echo $this->getPriceHtml($_product, true) ?>
More details
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
<?php endif; ?
I wouldn't even use a category but this extension instead:
Featured Products
The Featured Products extension mentioned by clockworkgeek is a good idea. But if you don't like that option the easiest thing to do is to add this in your home page cms
{{block type="catalog/product_list" category_id="YOUR_CAT_ID" template="catalog/product/YOUR_MODIFIED_COPY_OF_LIST.phtml"}}
And then make a copy of app/design/frontend///template/catalog/product/list.phtml (I refered to it above as YOUR_MODIFIED_COPY_OF_LIST.phtml) and remove the two lines that say
<?php echo $this->getToolbarHtml() ?>
and remove the entire if-block that outputs the "list mode"... basically the if statement
<?php // List mode ?>
<?php if($this->getMode()!='grid'): ?>
and you should only have the "grid mode" code in there.

Resources