tags:

views:

514

answers:

3

I want to assign custom parameters to CMS pages in Magento (i.e. 'about', 'customer service', etc), so they can be grouped.

The end goal is to use the parameters for each page to show (or hide) them in a nav menu. Writing a quick method in the page/html block to retrieve the pages (active only) for the menu was easy, but I can't figure out how to group them so that 'testimonials', 'history', and 'contact' are associated with 'about', and 'return policy', 'shipping', and 'contact' are associated with 'customer service'.

Any help to point me in the right direction would be greatly appreciated.

Thanks!

A: 

Unfortunately the cms pages are not entities and custom attributes are not supported.

My suggestion will be to overload Mage_Cms_Model_Page, create an associated table with your data, and in the new class constructor assign a new property to your_page object.

Elzo Valugi
Elzo:Thanks. I thought that's the direction I needed to go in. However, it still doesn't really fit the bill (in terms of what the client wanted / needed). As a result I decided to go in a different direction (see my own answer).
Toby H
A: 

I decided to go in a different direction with this. Here is what I did.

In admin interface:

  1. Created static blocks for each page (i.e. 'Page: About')
  2. Created a product category called CMS (URL Key: content), set Is Active to 'no'
  3. Created child categories for each content category (i.e. 'about'). Set Is Active to 'yes' and Display Mode to 'Static block only' and selected corresponding static block.
  4. Created child categories for each content category as above.

In code:

  1. Created two new methods in (local copy of) Catalog/Block/Navigation.php to get the current parent category and its children:

    public function getNavCategory($category)
    

    {

    if($category->getLevel() == 3){

        return $category;
    
    
    } else {
    
    
    
    $parentCategory = Mage::getModel('catalog/category')->load($category->getParentId());
    
    
    return $parentCategory;
    
    }

    }

    public function getNavChildCategories($category)
    

    {

$layer = Mage::getSingleton('catalog/layer');

    /* @var $category Mage_Catalog_Model_Category */
    $categories = $category->getChildrenCategories();
    $productCollection = Mage::getResourceModel('catalog/product_collection');
    $layer->prepareProductCollection($productCollection);
    $productCollection->addCountToCategories($categories);
    return $categories;
}
  1. Created a modified version of app/design/frontend/MYINTERFACE/MYTHEME/template/catalog/navigation/left.phtml to iterate through categories and child categories. Working example at: http://67.228.100.26/content/about
Toby H
A: 

Perhaps just use URL key field in admin as your category denominator? E.g:

CMS page 1 URL key: about/testimonials CMS page 2 URL key: about/history CMS page 3 URL key: about/contact CMS page 4 URL key: customer-service/return-policy ...

Then just loop through them in your template or have a method in a custom block class to group them together using regex based on the first part before slash.

Juraj
Yes, this is what I ended up doing in the end. Using method (w/ regex) in custom block to create nav hierarchy and loop through active results. Seems to work quite well, especially when CMS pages are added to search results. Not 100% ideal for the client, but certainly workable. Thanks!
Toby H