I'm having the following site-structure:
"webshop-page" > "category-page"
and on the category-page there are links to the products within the category.
So far, so good.
But now I'm stumbling on the following problem. On my "Category-page" I set a header image for that section. The products in that section need to have that same header image. But when I'm on a product-page, I'm not in my sitestructure anymore. How do I resolve the IPublishedContent page I was on? In this case, the Category-page?
edit: come to think of it... displaying the breadcrumbs from the current product seems even impossible.
You're right that it is not as easy to do as it should be ... and I've actually been working on a better solution. However, it can be done:
What I've done in the past is to create an extension method off of IProductContent
public static IEnumerable<IEntityCollection> GetCollectionsContaining(this IProductContent product)
{
// note: you have to cast the service as we have not exposed this method on the interface
return ((EntityCollectionService)MerchelloContext.Current.Services.EntityCollectionService)
.GetEntityCollectionsByProductKey(product.Key);
}
This will give you a list of all collections containing the product. The Key property is the Guid that is stored in the Umbraco content and is used by the PropertyValueResolver to get the list of IProductContent to render. In this case, you don't want to render the list ... you actually want the Guid so you can look at your category content pages for properties that match the value.
In my builds, also have an extension method for IPublishedContent which allows me to get around the value converter and just get the Guid:
public static Guid GetDataValueAsGuid(this IPublishedContent content, string propertyAlias)
{
var value = content.GetDataValue(propertyAlias);
if (value == null) return Guid.Empty;
Guid converted;
return Guid.TryParse(value.ToString(), out converted) ? converted : Guid.Empty;
}
Assuming you do not have loads of categories ... say under a few hundred, you can use a Linq query to find the "Categories" that contain the product. If your product is in a single category it makes the breadcrumb easier ... if you have it in multiple categories, you will need to further keep track of where the customer came from and store that value in a cookie or whatever ... make sense?
I've downloaded the Core code, and made GetEntityCollectionsByProductKey public.
The WillWork method is also internal. So I couldn't get that to work, but I skipped that line for testing purposes.
But I get the collections containing my selected product.
So now I need to work out a way to find the right contentnode.
It seems like a bit of overhead. But then again, you wouldn't want all products in your contenttree I guess.
Drilling down (if I understand you correctly) isn't the problem.
I can show a list of categories (content types, with Merchello list), and I can show a list of the products in the list on the category-detail-view.
But when I'm on a product-detail page, I would like to show the main-category the product belongs to. Because I might want to show a seperate header-image per category, or make a menu item active.
This seems kind of trivial to me, but I can't seem to get it to work. Except getting all product-groups my product is in, and search for a category-content item with the same name.
Your right - it does "seem" trivial, but in fact there are quite a few complexities. In multi-lingual implementations for example, you may have the same product in the same categories, but the category pages themselves are in completely different website roots with different host names for example.
From a product perspective, you want to be selling the same product no matter which language your are presenting so that inventory counts, pricing, shipping are the same. In this respect, the complexity you are encountering is more of an issue that stems from the fact that Umbraco itself is so flexible and we are trying to create a solution that is viable in any Umbraco install.
As I mentioned, I have been trying to come up with a generic solution (a set of extension methods), but again, it seems everyone wants something slightly different - products in multiple categories, categories that exist in some but not all languages, short URLs for SEO - URLs that include the category name ... literally different depending on who you talk to.
So far, the generic approaches I have played with are all pretty slow (poor performance) and thus I have not started moving them into the core with the thought a better solution will be to publicize some of the internals and provide better documentation so that implementation specific solutions are easier to address.
In this sense, this conversation is very useful and has been providing some excellent feedback. I'd love to hear your suggestions as to how this could be made easier.
Get umbraco content on a product-page
Hi there,
I'm having the following site-structure: "webshop-page" > "category-page"
and on the category-page there are links to the products within the category.
So far, so good.
But now I'm stumbling on the following problem. On my "Category-page" I set a header image for that section. The products in that section need to have that same header image. But when I'm on a product-page, I'm not in my sitestructure anymore. How do I resolve the IPublishedContent page I was on? In this case, the Category-page?
edit: come to think of it... displaying the breadcrumbs from the current product seems even impossible.
You're right that it is not as easy to do as it should be ... and I've actually been working on a better solution. However, it can be done:
What I've done in the past is to create an extension method off of
IProductContent
This will give you a list of all collections containing the product. The
Key
property is the Guid that is stored in the Umbraco content and is used by the PropertyValueResolver to get the list of IProductContent to render. In this case, you don't want to render the list ... you actually want the Guid so you can look at your category content pages for properties that match the value.In my builds, also have an extension method for IPublishedContent which allows me to get around the value converter and just get the Guid:
Assuming you do not have loads of categories ... say under a few hundred, you can use a Linq query to find the "Categories" that contain the product. If your product is in a single category it makes the breadcrumb easier ... if you have it in multiple categories, you will need to further keep track of where the customer came from and store that value in a cookie or whatever ... make sense?
Thank you.
So, I was kind of on the right track. This will help me a lot I think. I will try this. (and mark as solution if it works)
I've tried to implement this, but it doesn't run.
The EntityCollectionService doesn't have a
GetEntityCollectionsByProductKey
method. (edit: it does, but it's internal, so I can't reach it)And did you mean
in the second extension method?
Ah sorry, I'll look at making that public so you can get to it.
I forgot to include the second extension method I have - which is what confused you:
I've downloaded the Core code, and made GetEntityCollectionsByProductKey public.
The WillWork method is also internal. So I couldn't get that to work, but I skipped that line for testing purposes.
But I get the collections containing my selected product. So now I need to work out a way to find the right contentnode. It seems like a bit of overhead. But then again, you wouldn't want all products in your contenttree I guess.
Do you have a 'Category' content type which you are putting Merchello's list view on to?
If you took that approach, you can just get the lists initially from the datatype and then drill down as per the discussion above.
Drilling down (if I understand you correctly) isn't the problem.
I can show a list of categories (content types, with Merchello list), and I can show a list of the products in the list on the category-detail-view.
But when I'm on a product-detail page, I would like to show the main-category the product belongs to. Because I might want to show a seperate header-image per category, or make a menu item active.
This seems kind of trivial to me, but I can't seem to get it to work. Except getting all product-groups my product is in, and search for a category-content item with the same name.
Jeroen,
Your right - it does "seem" trivial, but in fact there are quite a few complexities. In multi-lingual implementations for example, you may have the same product in the same categories, but the category pages themselves are in completely different website roots with different host names for example.
From a product perspective, you want to be selling the same product no matter which language your are presenting so that inventory counts, pricing, shipping are the same. In this respect, the complexity you are encountering is more of an issue that stems from the fact that Umbraco itself is so flexible and we are trying to create a solution that is viable in any Umbraco install.
As I mentioned, I have been trying to come up with a generic solution (a set of extension methods), but again, it seems everyone wants something slightly different - products in multiple categories, categories that exist in some but not all languages, short URLs for SEO - URLs that include the category name ... literally different depending on who you talk to.
So far, the generic approaches I have played with are all pretty slow (poor performance) and thus I have not started moving them into the core with the thought a better solution will be to publicize some of the internals and provide better documentation so that implementation specific solutions are easier to address.
In this sense, this conversation is very useful and has been providing some excellent feedback. I'd love to hear your suggestions as to how this could be made easier.
Rusty,
thanks for Merchello it is awesome.
We have a requirement for the following:
We are not sure how best to go about this.
Any help would be really appreciated.
Thanks,
Brendan
The easiest way is to use an Umbraco content finder.
See Umbraco docs here: https://our.umbraco.org/Documentation/Reference/Routing/Request-Pipeline/IContentFinder
You would insert the new content finder BEFORE Merchello's
ContentFinderProductBySlug
(code here: https://github.com/Merchello/Merchello/blob/merchello- dev/src/Merchello.Web/Routing/ContentFinderProductBySlug.cs)You might check out Jeroen Breuer's blog post on 24 days as well - http://24days.in/umbraco-cms/2014/urlprovider-and-contentfinder/
Thanks, that is exactly what I done to get this working.
It works really well.
is working on a reply...