17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1982 Views |
-
Many-to-Many or Virtual Pages

13 December 2008 at 4:26am
I'm new to Silverstripe, but very impressed with the simplicity of creating a template and modifying the underlying CMS output. What I'm now considering is how best to implement a product hierarchy in the system. We have products that fit into multiple categories and for SEO reasons I would like the same product pages to appear under different categories in the navigation system. It seems that virtual pages might help solve some of this and a many-to-many relationship might as well, but I'm not sure the best way of approaching it.
Here's the idea:
I have category A and B and product C. Product C fits in both categories. I want a sidebar navigation that lists product C in both categories depending on which one is currently being viewed and I want the same page (different URL) to appear under both categories. I also need a summary page (think ProductHolder) for both categories that pulls some summary data for each product in the category.
Do virtual pages have any use in this scenario or is a many-to-many relationship between categories and products the way to go (or some combination)? Thanks for any help.
-
Re: Many-to-Many or Virtual Pages

13 December 2008 at 11:03am
Hey There,
I just recently finished a project with the exact same requirements. The way I set it up was to create a class "Product extends SiteTree" and "Product_Category extends SiteTree", and then I created a has_many/belongs_many_many relationship between the two.
You can then access this fairly simply in the template - if you have
class Product_Category extends SiteTree {
public static $has_many = array ('Products' => 'Product');
}
you can just do something like<% control ChildrenOf(ProductCategoryHolder) %>
<a href="$Link">$Title</a>
<% control Products %>
<!-- each product will appear here for each category -->
<% end_control %>
<% end_control %>For administering the categories in the backend, I would recommend using a ManyManyComplexTableField on the Product and/or Category admin pages.
| 1982 Views | ||
|
Page:
1
|
Go to Top |


