Copied to clipboard

Flag this post as spam?

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


  • Louis Ferreira 69 posts 265 karma points
    Nov 23, 2016 @ 16:35
    Louis Ferreira
    0

    Determine if a product belongs to a Collection / Sub Collection

    Hi Rusty,

    Is there a way to determine if a product belongs to a Collection or Sub Collection? I have a need to perform certain razor template logic if the user navigates to a product that belongs to a specific collection e.g. if a product belongs to a collection called 'Offers' which in a child of collections 'Category A' then the Url link (slug) for the product should be prepended with some value so that it goes to a landing page and not the actual product page. Hope this makes sense. The requirement is to have a category with generic properties that creates a landing page, and products can be added to that category allowing the end user to choose a product within this category.

    Or is there a better way to do this?

    The ideal scenario would be if a Merchello Collection could have the ability to attach extended document types to it like the product does... but that's a far cry I'm guessing.

    Hope you can help. (I'm using v2.3.6xxx)

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

    Hey Louis,

    There is an extension off IProductContent Collections() that returns IEnumerable<IProductCollection> ...

    I'm not following exactly what you mean here:

    The requirement is to have a category with generic properties that creates a landing page, and products can be added to that category allowing the end user to choose a product within this category.

    Does it not work to create an Umbraco content page for that category with whatever properties you need and add a Merchello Product List View to display the collection products in the collection?

    I'm missing something =)

  • Louis Ferreira 69 posts 265 karma points
    Nov 23, 2016 @ 18:03
    Louis Ferreira
    0

    Hi Rusty,

    It's kinda hard to explain how this works... so you're not missing anything.

    Let me try this way...

    The site I'm developing has a flyout menu listing all products in a category as links. Most of these product links goes straight to the product page using the slug, no problem there. However, some links are not really products, but rather a link to a landing page listing products in a sub category.

    Actually, I just realised a better way to do this...

    If I could retrieve all products AND (sub) collections from a specific collection, I could then create the relevant links based on whether the entity is a product or a collection, right?

    Is that possible?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 23, 2016 @ 19:14
    Rusty Swayne
    0

    Hi Louis,

    You may want to look at starting with IProductCollection rather than starting with the IProductContent.

    ProductCollections have a bunch of tree methods -> Children, Descendants, Ancestors ... as well as a GetProducts and GetProductsPaged

    https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.Web/ProductCollectionExtensions.cs

  • Louis Ferreira 69 posts 265 karma points
    Nov 24, 2016 @ 07:38
    Louis Ferreira
    0

    Hi Rusty,

    I pulled down the src for the proj and looked at the ProductCollectionExtensions.cs file and it seems there may be a long and convoluted way of doing this using multiple for-loops... just hoping that it will be performant :)

    Thanks for the response, much appreciated!

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 28, 2016 @ 18:13
    Rusty Swayne
    0

    Hey Louis,

    I'd be interested in seeing what you come up with and if you have any recommendations as to new additions to the API to make things easier.

Please Sign in or register to post replies

Write your reply to:

Draft