Hi, I have a products catalog page and am building the pages based on query strings. I need to build a tree of product collections. However, I have encountered some extremely strange behavior with the merchello product collections parent/child relationships.
the following is from an example sidebar I have on the catalog page where I am trying to build collection filters:
@using Merchello.Web
@using Merchello.Web.Models
@using Merchello.FastTrack.Ui
@{
// get the published catalog content node
IPublishedContent catalog = ExampleUiHelper.Content.GetCatalog();
// get the merchello collection selected in the merchello collection picker
IProductCollection collection = catalog.GetPropertyValue<IProductCollection>("categories");
// get the children of the catalog's collection
IEnumerable<IProductCollection> children = collection.Children();
//the name of the catalog collection (green text)
<div style="color: green;">@collection.Name</div>
// get the name of all child collections of the catalog collection (red text)
foreach (var child in children)
{
<ul class="list-unstyled">
<li style="text-indent: 5%;"><a style="color:red" href="[email protected]">@child.Name</a></li>
@*get the name of all grandchildren of catalog collection (blue text)*@
@foreach (var grandchild in child.Children())
{
<li style="text-indent: 10%;"><a style="color: blue" href="[email protected]">@grandchild.Name</a></li>
}
</ul>
}
}
Here is what I get as a result of this code (note how the children of the children are actually the children of the root).
What's even crazier to me, is that when I click one of these links, the child collections change to become the grandchildren! For example, here, I clicked on the Red "Necklaces" anchor and got the following back:
note that the catalog collection name has not changed, but somehow now the page thinks it's grandchildren are it's children. I am very confused.
I am building the page by route hijacking. Here is my controller for this:
public class ftCatalogController : BaseSurfaceController
{
public override ActionResult Index(RenderModel renderModel)
{
//try to get a merchello product collection from the query string
try
{
var collectionKey = new Guid(Request.QueryString["collection"]);
var merchello = new MerchelloHelper();
var collection = merchello.Collections.Product.GetByKey(collectionKey);
return base.Index(new ftCatalogModel(renderModel.Content)
{
CurrentCollection = collection,
});
}
//if query string invalid, default to the collection in the categories property of the doctype
catch(System.Exception e)
{
IProductCollection collection = renderModel.Content.GetPropertyValue<IProductCollection>("categories");
return base.Index(new ftCatalogModel(renderModel.Content)
{
CurrentCollection = collection,
});
}
}
}
public class ftCatalogModel : RenderModel
{
public ftCatalogModel(IPublishedContent content) : base(content){ }
public IProductCollection CurrentCollection { get; set; }
}
Product Collections are Children of themselves??
Hi, I have a products catalog page and am building the pages based on query strings. I need to build a tree of product collections. However, I have encountered some extremely strange behavior with the merchello product collections parent/child relationships.
the following is from an example sidebar I have on the catalog page where I am trying to build collection filters:
Here is what I get as a result of this code (note how the children of the children are actually the children of the root).
What's even crazier to me, is that when I click one of these links, the child collections change to become the grandchildren! For example, here, I clicked on the Red "Necklaces" anchor and got the following back:
note that the catalog collection name has not changed, but somehow now the page thinks it's grandchildren are it's children. I am very confused.
I am building the page by route hijacking. Here is my controller for this:
Hi
I was getting something like this as well.
It seems the Children() of the first collection are used as the Children() of all subsequent children - a bug I presume?
To get round it I retrieved the children in a slightly different way
When I did it this way the child collections were the ones I was expecting
Cheers J
is working on a reply...