Magento looks so great on the surface, but is unbearably difficult to customize given the lack of coherent documentation and the fact that no one seems to have straight answers. So I’m posting this question in a last ditch effort in the hopes that someone can actually help. PLEASE don’t point me to the designers guide as it’s too high-level a document to help with real customization I don’t need a programming philosophy lesson, I need answers.
I have created a new template based on the 3 column design found in template/page/3column.phtml and have successfully set up the store to point to that template and use it on the homepage. It has the same variable calls in it, so the page.xml layout file should still be viable. I’ve created two categories under the Default Category in the admin and added products with quantities greater than 0 to them. I’ve ensured that the default category is the root category in the “Manage Stores” section of the admin. Even with doing all of this, I can not get a single category to show up on the homepage. In addition, I’m completely confused as to why the callouts are even on the homepage - where do I define what to show in the columns on the homepage?
What I want is a list of categories showing up in the left column - a seemingly simple request made near impossible by the lack of resources explaining how to make this work. Please, please help - every search on Google and in these forums has produced either incomplete code that produces no results or more people asking the exact same questions with no answers. Every conversation on the chat board has been circular and gone nowhere. Please shed some light on this topic and help the community out.
I turned off the system cache, so changes show up fine. I figured out my question about the callouts (though I’m still unclear on how I could change that on a per-page or per-section basis - i.e. why do I need the left_col callout on every page - what if I want something different for the category main pages?). I changed the left column so that it points to catalog/navigation/left.phtml, but now it’s generating the PHP error “Call to a member function count() on a non-object in C:\working\magento\public_html\app\design\frontend\boardsnmore\default\template\catalog\navigation\left.phtml on line 29”. Looking at the code, this is being caused by a call to the method getCurrentChildCategories() on $this - I’m unclear, though, as to what $this represents. Given that left.phtml is essentially an include file, what object is being instantiated that I’m using $this to refer to it?
Now I get the PHP error: “Fatal error: Call to a member function getChildren() on a non-object in C:\working\magento\public_html\app\code\core\Mage\Catalog\Block\Navigation.php on line 77”
Looking at the code, the getChildren() method is being called on an apparent category objectinstantiated by the following two lines of code:
It looks like $category is the boolean false in this situation. What’s happening here? Why is the layer being called? What is its purpose? And why is it returning false for the getCurrentCategory() method? Shouldn’t it return a reference to the root category defined in store management?
Looking through the code to fix the prior errors, I saw there was a method that appears to be intended to grab all fot je categories for the current store. So, in Navigation.php, I put an if-then around the code instantiating the $category variable that was turning out to be false. Here’s the new code, starting at line 66 in app/code/core/Mage/Catalog/Blobk/Navigation.php:
public function getCurrentChildCategories() { $layer = Mage::getSingleton('catalog/layer'); //RDZ - Added to allow the display of categories on the homepage. if(($category = $layer->getCurrentCategory()) === false) { return $this->getStoreCategories(); }
This actually successfully displayed the second level categories (everything beneath default category) in my assigned root category on the homepage using template/catalog/navigation/left.phtml assigned to the left reference in cms.xml instead of the left_col callout.
And now I have a shiny new error. When I click on one oif the categories with an item assigned to it, I get the following PHP error:
Fatal error: Call to undefined method Mage_Catalog_Helper_Product::getPriceHtml() in C:\working\magento\public_html\app\design\frontend\boardsnmore\default\template\catalog\product\list.phtml on line 100
How in the world has anyone been able to get this system working?
Well, since no one’s rushed to my aid (or anyone else’s for that matter - c’mon folks, if you find a solution don’t leave it in PMs - this is supposed to be an open source community) I’ve been struggling with this myself. The only solution I’ve come up with involves directly changing the app code. Here’s hoping a new upgrade doesn’t overwrite these changes.
Recall my goal was to display the children from a specific category on the homepage. Why I want to do this is irrelevant - it’s a customization issue that should just exist - but I was able to fiond a solution.
First, I added a new method in the app/code/core/Mage/Block/Navigation.php:
This should display the children for numerical ID 3 as an unordered list in the left hand column of your page, assuming you set it up that way in your layouts. To get the catalog ID, log in as an admin, go to “Catalog->Manage Categories” and click on the category whose children you want to display. You MUST choose a category with children, or this just won’t work. The numeric ID appears in the URL like so:
/index.php/admin/catalog_category/edit/id/3/
see that “3” in the URL after id? That’s the numeric ID you’re looking for.
So, even with all this setup, the puzzle still didn;t work, and I’m still not clear as to why I had to do this following part. It looked like calling the specific category in the Navigation was doing the job - a call to getName() returned the correct name - but the call to getChildren returned an empty string. Looking through the code, the Category’s Tree class does get called, but it never gets loaded. So I modified the code in app/code/core/Mage/Catalog/Model/Category.php near line 101 in the method “getTreeModelInstance()”:
public function getTreeModelInstance() { if (is_null($this->_treeModel)) { $this->_treeModel = Mage::getResourceSingleton('catalog/category_tree'); //RZ - Not even sure why this isn't being called like it should be. Adding it. $this->_treeModel->load(); } return $this->_treeModel; }
That loaded the category tree structure so that the call to getChildren() finally produced something other than a blank string.
So, we have success on this front. I’m tossing some karma back into the community pool in the hopes that others may finally post answers to the deluge of questions and problems people are expressing on this board.
I managed to get that working on my site, i want to add though that i could only get it working by using the three column design
On an unrelated topic, does anyone know how to get products to show up on the front page, like Featured Products, New Products, stuff like that. There’s probably already a post somewhere, but i cant find any,
I specifically was trying to get the children of a category showing up on the homepage. I wanted to display our store as two separate views at the same time - a list of regular departments (i.e. Men’s Apparel, Women’s Apparel, Accessories, etc.) and a list of brands (O’Neill, Volcom, etc.). The only solution that made sense was to create two categories under the Default Category - “Shop By Brand” and “Shop By Department” - and pull the children only out of the relevant on (i.e. “Shop by Brand” has categories named “O’Neill”, “Volcom”, etc.). I just wanted the brand names as a list on the homepage. So my code above is a bit more advanced than the simple “Show categories on the homepage” a lot of folks had been asking for. But the solution posted for that ought to work - it did for me before I took the next step of figuring this subcat issue out.
Actually, Craig, adding your post to the wiki documentation may be better than using a sticky. I’m finding the support here frustrating given that, as you mentioned, tons of people ask for help on similar problems and no one seems eager to help.
I want to help with the request regarding featured and new items, but I’m still wrapping my head around that. Having said that, here’s a post I found in my research that may help, at least with the featured items:
Big thanks, dude. I was trying to get my subcategories to show up during product views, and I couldn’t figure out why $category->getChildren() wasn’t returning anything.
<?php if ($_product): ?> <?php // get last id in category path for current category $category = Mage::getModel('catalog/category')->load($_path[count($_path) - 1]); $children_ids = implode(',', Mage::getResourceSingleton('catalog/category_tree')->load()->getChildren($category->getId(), false));
2) Editing the Magento navigation http://www.getfido.net/blog/magento/editing-the-navigation.php
This 2nd one will show you how magento retrieves the categories and displays them (and sub categories) for the main navigation and the layered land hand navigation.
As for your original problem of categories not showing up, I assume you meant that no matter what settings you did, you couldn’t get the main navigation to appear?
Edit: After reading your posts more thoroughly, I can see that you probably don’t need to read my posts to help you as you’ve identified the files you need for your customization.
My only suggestion then is to move your changes out of the core code.
You can easily do this by duplicating the folder structure in your LOCAL folder and adding the files you edited.
So if you edit:
app/code/core/Mage/Catalog/Block/Product/View.php
you can save your edited version to override the original View.php here:
app/code/local/Mage/Catalog/Block/Product/View.php
The suggested way of doing this is to overwrite the Block via your own custom module. (There are many threads along this topic)
Wow, thank you so much for this!
Have been trying the entire day to make layered navigation turn up on the front page but without luck… Now at least I can have the Categories on the frontpage!
Does anyone have an idea how to make all attributes show up as well? (My goal is still to have a proper layered navigation on the frontpage without having to make a core hack)
Big thanks, dude. I was trying to get my subcategories to show up during product views, and I couldn’t figure out why $category->getChildren() wasn’t returning anything.
Now in my view I just do:
etc, case anybody is interested. Don’t even have to hack the core.
But in what file do you do it? There are several view.phtml and being quite new at this I can’t identify which one you are referring to…
Very curious at the output of this!