if someone can tell me (already did it) how place layered navigation at home page?
I updated XML layout via CMS > Manage Pages > Homepage > Layout Update XML box:
but when I reloaded home page an error occurred:
exception ‘Mage_Core_Exception’ with message ‘Cannot retrieve current category object’.
I tried to modify a core method getCurrentCategory() in core/Mage/Catalog/Model/Layer.php (I know that’s a bad idea, but I need a quick solution even if this prevent me from next release update), but I failed, because I didn’t know how to set up a root category as a current category.
Later, in test case, I set a current category to one under root (in this case category with id 31, in bold is my modification):
public function getCurrentCategory() { $category = $this->getData('current_category');
if ($category = Mage::registry('current_category')) { $this->setData('current_category', $category); } else { Mage::throwException(Mage::helper('catalog')->__('Cannot retrieve current category object')); } } return $category; }
and now, layered navigation was successfully loaded at home page (exactly the same if I choose category with id 31 from top menu).
But when I hovered on generated links in navigation I saw strange thing,
link to category XXX was:
/cms/index/index/cat/4/
when correct link to the same category in normal flow (not at home page) is:
/catalog/category/view/cat/4/id/31/.
When I clicked in this short link (/cms/index/index/cat/4/) layered navigation correctly updated,
but not content of the page (should be list of products in current selected category, but system
load content of home page).
Someone knows what cause this behavior and how do I correct place and configure layered navigation at home page?
I just tried it and it works, but it seems to only filter products within that category.The links work fine, but what I’d like to have happen is for those items to filter all the products in the store and just use that page to ‘promote products to the front page’. I tried to make another hidden category with all the products, but was unable to get this result. Otherwise filtering works well, however, it only works within that category. I guess I can try to put random products and just have all products show as part of that category but only a certain number to populate the front page, each time randomly, unless someone has some better ideas?
I realized I had to change the function to this to work with the layout update on the first page:
public function getCurrentCategory() { $category = $this->getData('current_category'); if (is_null($category)) { if ($category = Mage::registry('current_category')) { $this->setData('current_category', $category); } else { $category = false; $this->setData('current_category', $category); } }
//added to make this work for front page: if(is_null($category) || $category == false) { $home_category = Mage::getModel('catalog/category')->load(8); //number must correspond to 'all products page' category $this->setData('current_category', $home_category); $category = $this->getData('current_category'); //return $category; } //end addition
But when I hovered on generated links in navigation I saw strange thing,
link to category XXX was:
/cms/index/index/cat/4/
when correct link to the same category in normal flow (not at home page) is:
/catalog/category/view/cat/4/id/31/.
When I clicked in this short link (/cms/index/index/cat/4/) layered navigation correctly updated,
but not content of the page (should be list of products in current selected category, but system
load content of home page).
First, go to /app/design/frontend/default/default/template/catalog/layer and make a copy of file view.phtml named for example homeview.phtml. In this new file replace:
where ALLTHINGSCATEGORY is a url key of category you want to have on homepage.
Thank’s to above things, links on homepage in layered navigation will be good.
Next, update XML layout via CMS > Manage Pages > Homepage > Layout Update XML box:
And last important thing is to modify file /app/code/core/Mage/Cms/controllers/IndexController.php. On begining of method indexAction() add these lines (replace category id with yours ALLTHINGSCATEGORY id):
$categoryId = 27; // ID OF CATEGORY YOU WANT ON HOMEPAGE
Thanks a ton for your hard work lubiluk. I’ve been looking for a good solution for this also and had planned a solution like your ALLTHINGSCATEGORY. You’ve saved me a lot of time. I’m going to try this out right away.
One thing that bothers me (although I may be naive here) is that making a new template type might cause problems when upgrading or changing themes. Is there no way to overwrite the template that is currently in use (I think it’s “.../template/cms/default/home.phtml") on the front page by putting a modified copy somewhere in our non-default template folder?
Edit: technically the core mod and template change should be worked into a module...... I’m not sure if it’s possible to change the layout xml directoly from the module so that would still be manual, but oh well…
uhm yes, upgrading is problematic. In version 1.1.5 it stopped to work. After upgrade I had to modify /app/code/core/Mage/Cms/controllers/IndexController.php file because it was owerwritten. And line
I’m using the first method in this thread and it works except once you narrow it, it stays on the main page instead of going to the products it’s narrowed it down to - does anyone know why this might be happening and how to fix it?
I’m using the first method in this thread and it works except once you narrow it, it stays on the main page instead of going to the products it’s narrowed it down to - does anyone know why this might be happening and how to fix it?
Try to use the last update specified above. I’m running 1.1.6 and i got it working so it links perfectly from fronpage to a category.
The only thing i’m stuck at, is that the top menu is created of al the categories in the root category. Since i made an layer in between the root category and the actual categories, that category in between (to reference to with the layerd navigation) is the only thing showing up in de menu…
$pageId = Mage::getStoreConfig('web/default/cms_home_page'); if (!Mage::helper('cms/page')->renderPage($this, $pageId)) { $this->_forward('defaultIndex'); } }
Then I get a blank front page. If I leave that code out I get no errors but when you select an option from the layered nav it gets a bad url. http://www.minervapromotions.com/techusa
i used the methods described by lukas.w and the FIRST post by lubiluk in v 1.1.6 and i had a layered navigation on the first page that narrowed down but no products were visible in the middle...the center area stayed at the home page. i tried it again in v 1.1.4 and i just got a blank home page. I also would like to know if anyone has figured out how to get a functioning layered navigation
I have that method working, but i have the links problem to. Anyone know how to solve that link problem??
The links are like this: /index.php/ROOTCATEGORY?categoria=94
ROOTCATEGORY is the URL key from my ALLTHINGSCATEGORY
EDIT: One thing that bothers me, is that this method doesn’t work with a root category, it only works with a subcategory. That isn’t a problem if the “Root Subcategory” doesn’t appear in the menu bar.
Is there a way to put this working with a Root Category or to make the Root Subcategory disapear from the menu bar??