Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jeroen Oostwouder 100 posts 296 karma points
    Mar 31, 2016 @ 07:19
    Jeroen Oostwouder
    0

    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.

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Apr 01, 2016 @ 15:42
    Rusty Swayne
    1

    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?

  • Jeroen Oostwouder 100 posts 296 karma points
    Apr 04, 2016 @ 06:45
    Jeroen Oostwouder
    1

    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)

  • Jeroen Oostwouder 100 posts 296 karma points
    Apr 06, 2016 @ 09:36
    Jeroen Oostwouder
    0

    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

    var value = content.GetPropertyValue(propertyAlias);
    

    in the second extension method?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Apr 07, 2016 @ 15:00
    Rusty Swayne
    1

    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:

        public static object GetDataValue(this IPublishedContent content, string propertyAlias)
        {
            if (!content.WillWork(propertyAlias)) return null;
    
            var property = content.Properties.First(x => x.PropertyTypeAlias == propertyAlias);
    
            return property.DataValue;
        }
    
  • Jeroen Oostwouder 100 posts 296 karma points
    Apr 08, 2016 @ 09:53
    Jeroen Oostwouder
    0

    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.

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Apr 08, 2016 @ 17:45
    Rusty Swayne
    0

    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.

  • Jeroen Oostwouder 100 posts 296 karma points
    Apr 11, 2016 @ 06:57
    Jeroen Oostwouder
    0

    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.

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Apr 11, 2016 @ 16:26
    Rusty Swayne
    0

    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.

  • Brendan Rice 538 posts 1099 karma points
    Mar 12, 2017 @ 16:01
    Brendan Rice
    0

    Rusty,

    thanks for Merchello it is awesome.

    We have a requirement for the following:

    1. Products should have URLs that match - /category/subcategory/product
    2. Product page breadcrumb trails should match the URL

    We are not sure how best to go about this.

    Any help would be really appreciated.

    Thanks,

    Brendan

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Mar 13, 2017 @ 15:52
    Rusty Swayne
    1

    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/

  • Brendan Rice 538 posts 1099 karma points
    Mar 13, 2017 @ 16:00
    Brendan Rice
    0

    Thanks, that is exactly what I done to get this working.

    It works really well.

Please Sign in or register to post replies

Write your reply to:

Draft