Your shopping cart is empty. Browse our Store

Magento

Open Source eCommerce Evolved

Magento Forum

   
Put Product and Category info on homepage of shop
 
Dan Orsborne
Member
 
Total Posts:  71
Joined:  2007-09-20
 

I couldn’t see a way to put products on the front of the site because as soon as you added

<block type="catalog/category_view" name="category.products">
 <
action method="setTemplate"><template>catalog/category/homepage_view.phtml</template></action>
</
block>

catalog/category/homepage_view.phtml contains: (this is my template for how I want the category to display on the homepage. I also have a view.phtml that is used for all sub categories)

<div id="leftcontent">
        <
h2><?=$this->getCurrentCategory()->getName()?></h2>
        
<?if($_description=$this->getCurrentCategory()->getDescription()):?>
            
<p><?=$_description?></p>
        
<?endif;?>
    
</div>
    <
div id="centercontent">
        
<?if($_imageUrl=$this->getCurrentCategory()->getImageUrl()):?>
            
<img src="<?=$_imageUrl?>" alt="<?=$this->getCurrentCategory()->getName()?>" />
        
<?endif;?>
    
</div>

If you were to simply add the first block to the default.xml page you got an error (something like it didn’t know what category was) This error also stops you displaying the category title, image and description onto the front page of the site (which means you would have to us CMS blocks of the CONTENT section on the page editor; neither of which are very nice!)

The error appears to originate from the getCurrentCategory() function in app\code\core\Mage\Catalog\Block\Category\View.php folder.  It doesn’t seem to get the category object when it is at root level. At all other levels it appeared to work fine.  So I added a check to see if the cateogry object was blank and then get the category object from the root category ID.

public function getCurrentCategory()
    
{
        $_currentCategory 
Mage::registry('current_category');
        
        
//START  EDIT
        
if (isset($_currentCategory)){
            
return Mage::registry('current_category');
        
else 
            $categoryId 
Mage::getSingleton('core/store')->getConfig('catalog/category/root_id');
            
$category Mage::getModel('catalog/category')->load($categoryId);
            
Mage::register('current_category'$category);
            
            return 
Mage::registry('current_category');
        
}
        
//END EDIT
    
}

This allows you to put category details and products onto the homepage.... I know it’s not an ideal solution to bestselling but it’s better than having to modify the HTML in a text area!!!

Comments/Suggestions/Questions welcome

Thanks

 Signature 

http://www.igentics.com

Igentics are Internet Engineers, we like to look at things from a different angle. The end result being a fully integrated system encompassing the whole supply chain from supplier to end user, incorporating all legacy systems and data. This increases profits and reduces cost.

Magento test site http://ocbutcher.igentics.com

 
Magento Community Magento Community
Magento Community
Magento Community
 
bobh
Member
 
Total Posts:  32
Joined:  2007-08-31
 

So this would change what shows on home page ? or am i not reading it right. If so what files should i change and remove what out of them ?

I am just trying myself to add content to my home page without having to manually ass stuff each time i want to change it. Would like it to auto pull stuff from my catalog. So is that code something i have to add to my home page? sorry i am new to most of it but have been trying hard to learn

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dan Orsborne
Member
 
Total Posts:  71
Joined:  2007-09-20
 

Yes, this change allows you to add a block to the homepage that will show the home category details as well as allowing you to show the products included in that category. Using this method you have much simpler control over displaying products on the front page than with the included example (which uses hardcoded data stored in the database as discussed in other topics)

If you add products to the root cateogry they don’t show in the shop, this is because there is no catalog/category or product block on the front page; it gets added as you drill down by the app\design\frontend\OC\default\layout\catalog\category\default.xml page (again substitute OC with your template or default). You can’t just add the block to the front page as it causes an error. The steps below show how to add the block to the template and then make the change to allow the functionality to work.

To make this change you need to do the following:
1) Open \app\design\frontend\OC\default\layout\core\default.xml (change OC to your template name or default)
2) Under the line : <block type="core/text_list" name="content" as="content"/> add

<block type="catalog/category_view" name="category.products">
<
action method="setTemplate"><template>catalog/category/view.phtml</template></action>
</
block>
This will use the same view.phtml layout as you get when you drill down into the categories… if you want a custom template for the homepage you need to copy this file and change the filename above to match the new file. (Open this file and have a look at how it displays data and modify it as required)
3) Make the change to getCurrentCategory() so that the category object is avaliable on the front of the site
4) Go to admin, add a title, description and image to the root category as required. Add products to root category and they will appear on the home page.

Thanks

 Signature 

http://www.igentics.com

Igentics are Internet Engineers, we like to look at things from a different angle. The end result being a fully integrated system encompassing the whole supply chain from supplier to end user, incorporating all legacy systems and data. This increases profits and reduces cost.

Magento test site http://ocbutcher.igentics.com

 
Magento Community Magento Community
Magento Community
Magento Community
 
bobh
Member
 
Total Posts:  32
Joined:  2007-08-31
 

Thx for the reply bud..

 
Magento Community Magento Community
Magento Community
Magento Community
 
bobh
Member
 
Total Posts:  32
Joined:  2007-08-31
 

Ok i added
<block type="catalog/category_view" name="category.products">
<action method="setTemplate"><template>catalog/category/view.phtml</template></action>
</block>
to the \app\design\frontend\default\default\layout\core\default.xml
and added if (isset($_currentCategory)){
return Mage::registry(’current_category’);
} else {
$categoryId = Mage::getSingleton(’core/store’)->getConfig(’catalog/category/root_id’);
$category = Mage::getModel(’catalog/category’)->load($categoryId);
Mage::register(’current_category’, $category);

return Mage::registry(’current_category’);
}
to the app\code\core\Mage\Catalog\Block\Category\View.php
and finally got it to go with no error’s and then added a title, description and image to the root category then added products to the root catalog but nothing shows up on the homepage.. Did i miss something ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dan Orsborne
Member
 
Total Posts:  71
Joined:  2007-09-20
 

To get products to appear you need to add the following block into the default.xml file

<block type="catalog/product_list" name="category.productlist">
            <
action method="setTemplate"><template>catalog/product/list.phtml</template></action>
        </
block>

and then add something like this into your template file

<div id="bestsellers">
        <
h4>Bestsellers</h4>
        <
p>Duis eget erat eu nulla interdum sagittis.</p>
           <!-- 
[start] content -->
            
<?=$this->getChildHtml('category.productlist')?>
        
<!-- [end] content -->
    </
div>

Once again you can change this file catalog/product/list.phtml to a custom version for the homepage and change the name of the file you use here.  This list.phtml displays product images etc and I decided I only wanted product names so I made the following file:

<?$_productCollection=$this->getLoadedProductCollection()?>
<?if
(!$_productCollection->getSize()):?>
<div class="note-msg">
    
<?=__('There are no products matching the selection.')?>
</div>
<?else:?>
    
<ul>
    
<?foreach ($_productCollection as $_product):?>
        
<li><a href="<?=$_product->getProductUrl()?>" title="<?=$this->htmlEscape($_product->getName())?>"><?=$_product->getName()?></a></li>
    
<?endforeach;?>
    
</ul>
<?endif;?>
 Signature 

http://www.igentics.com

Igentics are Internet Engineers, we like to look at things from a different angle. The end result being a fully integrated system encompassing the whole supply chain from supplier to end user, incorporating all legacy systems and data. This increases profits and reduces cost.

Magento test site http://ocbutcher.igentics.com

 
Magento Community Magento Community
Magento Community
Magento Community
 
mikeg
Jr. Member
 
Total Posts:  3
Joined:  2007-10-03
 

Thanks for the tip dan but i also could not get it to work.
I put
<block type="catalog/product_list" name="category.productlist">
<action method="setTemplate"><template>catalog/product/list.phtml</template></action>
</block>
that into default.xml
and
<div id="bestsellers">
<h4>Bestsellers</h4>
<p>Duis eget erat eu nulla interdum sagittis.</p>
<!-- [start] content -->
<?=$this->getChildHtml('category.productlist')?>
<!-- [end] content -->
</div>
into teplate which i hope you meant cms/manage pages then edit the home page and paste that in there (which i was just going to use the default list.phtml
was there a line there i was supposed to change in the code also somewhere as of right now it just shows on my homepage
Bestsellers
Duis eget erat eu nulla interdum sagittis.

getChildHtml(’category.productlist’)?>
thx for your help on site also i have learned alot from your posts.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dan Orsborne
Member
 
Total Posts:  71
Joined:  2007-09-20
 

Mmmm..... I’ve downloaded the new version today and the templating has changed quite a bit.... I’ve move my site from the old version to the new today and got all the functionality I added working again.  I will post a URL tomorrow to show how it works and perhaps the complete source from my machine.

Sorry that the example didn’t work exactly but perhaps it’ll point you in the right direction of what to change.

Thanks

 Signature 

http://www.igentics.com

Igentics are Internet Engineers, we like to look at things from a different angle. The end result being a fully integrated system encompassing the whole supply chain from supplier to end user, incorporating all legacy systems and data. This increases profits and reduces cost.

Magento test site http://ocbutcher.igentics.com

 
Magento Community Magento Community
Magento Community
Magento Community
 
mikeg
Jr. Member
 
Total Posts:  3
Joined:  2007-10-03
 

Hey dan have you redon this part yet.. would be nice to just add products to the root and have them show up on main page smile if you got time anyways

 
Magento Community Magento Community
Magento Community
Magento Community
 
bobh
Member
 
Total Posts:  32
Joined:  2007-08-31
 

will they implement that as part of it later ? it would just be nice to goto the product page and click the box for root and have it show there. would make it easy to change the front page with new products.

 
Magento Community Magento Community
Magento Community
Magento Community
 
bobh
Member
 
Total Posts:  32
Joined:  2007-08-31
 

Anyone got this figured out yet ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dan Orsborne
Member
 
Total Posts:  71
Joined:  2007-09-20
 

Here are the files…
http://ocbutcher.igentics.com/download/

 Signature 

http://www.igentics.com

Igentics are Internet Engineers, we like to look at things from a different angle. The end result being a fully integrated system encompassing the whole supply chain from supplier to end user, incorporating all legacy systems and data. This increases profits and reduces cost.

Magento test site http://ocbutcher.igentics.com

 
Magento Community Magento Community
Magento Community
Magento Community
 
spider
Jr. Member
 
Avatar
Total Posts:  19
Joined:  2007-10-12
 

hello.

I dont understand few things. First of all is how to put this piece of code (and how this code should look like?) into file (witch file?) to show on homepage output of script php.

Where can I put this code?

<block type="catalog/category_view" name="category.products">
 <
action method="setTemplate"><template>catalog/category/homepage_view.phtml</template></action>
</
block>

and how can I refer from template to this block ?
What is this: “category_view” ? - i dont have this one in my magento folder structure.
I gues above code tells what template must be used.

Help.
Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dan Orsborne
Member
 
Total Posts:  71
Joined:  2007-09-20
 

Look at theis forum and download the complete site from the link provided. You should be able to look through the code and see what I’ve done.
http://www.magentocommerce.com/boards/viewthread/837/

Thanks

 Signature 

http://www.igentics.com

Igentics are Internet Engineers, we like to look at things from a different angle. The end result being a fully integrated system encompassing the whole supply chain from supplier to end user, incorporating all legacy systems and data. This increases profits and reduces cost.

Magento test site http://ocbutcher.igentics.com

 
Magento Community Magento Community
Magento Community
Magento Community
 
Capitaine Commerce
Member
 
Avatar
Total Posts:  67
Joined:  2007-09-01
Lille, France
 

@Dan

Does one have to change the list.phtml file or not ?
I can get the default category name and description on the homepage, but I can see no products, though I put to in the root category of the store.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mark_Kimsal
Sr. Member
 
Total Posts:  186
Joined:  2007-09-12
Michigan, USA
 

The code to get the current root category ID changed to this:

$categoryId = (int)Mage::app()->getStore()->getWebsite()->getDefaultGroup()->getData('root_category_id');
 Signature 

There’s info on lots of custom modules in my Magento Group
http://www.magentocommerce.com/group/view/174
Need Upgrade help from 0.6, 0.7, and 0.8 available?  P.M. me for details on CMS integration.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
 
Sales: Call 877.832.5289 (North America) 310.295.4144 (International) to request a call-back.
© Copyright 2008 Varien. Magento is a trademark of Irubin Consulting Inc. DBA Varien    Privacy Policy|Terms of Service