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)
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 functiongetCurrentCategory() { $_currentCategory=Mage::registry('current_category');//START EDIT if (isset($_currentCategory)){ returnMage::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);
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
Posted: October 2 2007
| top
bobh
Total Posts: 32 Joined: 2007-08-31
Ignore user
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
Posted: October 2 2007
| top | # 1
Dan Orsborne
Total Posts: 71 Joined: 2007-09-20
Ignore user
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
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
Posted: October 2 2007
| top | # 2
bobh
Total Posts: 32 Joined: 2007-08-31
Ignore user
Thx for the reply bud..
Posted: October 2 2007
| top | # 3
bobh
Total Posts: 32 Joined: 2007-08-31
Ignore user
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 ?
Posted: October 2 2007
| top | # 4
Dan Orsborne
Total Posts: 71 Joined: 2007-09-20
Ignore user
To get products to appear you need to add the following block into the default.xml file
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:
<?if(!$_productCollection->getSize()):?> <divclass="note-msg"> <?=__('There are no products matching the selection.')?> </div> <?else:?> <ul> <?foreach($_productCollectionas$_product):?> <li><a href="<?=$_product->getProductUrl()?>"title="<?=$this->htmlEscape($_product->getName())?>"><?=$_product->getName()?></a></li> <?endforeach;?> </ul> <?endif;?>
Posted: October 3 2007
| top | # 5
mikeg
Total Posts: 3 Joined: 2007-10-03
Ignore user
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.
Posted: October 3 2007
| top | # 6
Dan Orsborne
Total Posts: 71 Joined: 2007-09-20
Ignore user
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
Posted: October 3 2007
| top | # 7
mikeg
Total Posts: 3 Joined: 2007-10-03
Ignore user
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 if you got time anyways
Posted: October 5 2007
| top | # 8
bobh
Total Posts: 32 Joined: 2007-08-31
Ignore user
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.
Posted: October 5 2007
| top | # 9
bobh
Total Posts: 32 Joined: 2007-08-31
Ignore user
Anyone got this figured out yet ?
Posted: October 7 2007
| top | # 10
Dan Orsborne
Total Posts: 71 Joined: 2007-09-20
Ignore user
Here are the files… http://ocbutcher.igentics.com/download/
Posted: October 8 2007
| top | # 11
spider
Total Posts: 19 Joined: 2007-10-12
Ignore user
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.
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.
Posted: October 12 2007
| top | # 12
Dan Orsborne
Total Posts: 71 Joined: 2007-09-20
Ignore user
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
Posted: October 12 2007
| top | # 13
Capitaine Commerce
Total Posts: 67 Joined: 2007-09-01 Lille, France
Ignore user
@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.
Posted: October 29 2007
| top | # 14
Mark_Kimsal
Total Posts: 186 Joined: 2007-09-12 Michigan, USA
Ignore user
The code to get the current root category ID changed to this:
0 Response to "app design frontend yourthemepackage default layout catalog.xml"
Post a Comment