Copied to clipboard

Flag this post as spam?

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


  • Chris Foot 61 posts 93 karma points
    Oct 02, 2015 @ 09:59
    Chris Foot
    0

    Related Product Selector in 1.12.0

    Previously I was using a multiple content picker in order to allow my editors to specify a list of related products to show on a product page. With 1.12.0 I can obviously no longer use this as products are not in the umbraco tree any more.

    Is there a way to achieve similar functionality in 1.12.0? I have tried adding a merchello product selector to an archetype but it doesn't appear to work unfortunately. I have looked at the product list view but this seems to only work with collections which I think is a bit overkill for a related products selector.

    Thanks

    Chris

  • Chris Foot 61 posts 93 karma points
    Oct 21, 2015 @ 07:32
    Chris Foot
    0

    I case anyone is interested and stumbles across this in the future. I resorted to having a multiple text box and having the customer specify skus that they wanted to show in the end.

  • Paul 89 posts 167 karma points
    Nov 17, 2015 @ 10:18
    Paul
    0

    Hi Chris,

    Could you share your method please?

    I have the same issue where I need to create a related events/product picker. Tried using Nester Content document type, but can't get get it to work.

    Thanks,

    Paulius

  • Chris Foot 61 posts 93 karma points
    Nov 17, 2015 @ 10:29
    Chris Foot
    0

    Hi Konijus,

    It's nothing more than a standard umbraco multiple textbox which the customer adds the skus to. In the razor template I use the following in a repeater:

            @foreach (var relatedProduct in product.GetPropertyValue<string>("relatedProducts").Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                            .Where(x => x != product.Sku && Merchello.Query.Product.GetBySku(x).Available).Select(x => Merchello.TypedProductContent(Merchello.Query.Product.GetBySku(x).Key)) { Template Stuff Here }
    

    Chris

  • Paul 89 posts 167 karma points
    Nov 18, 2015 @ 17:02
    Paul
    100

    Hi Chris,

    Thanks for the answer.

    I managed to get it to work with Nested content. Code below:

    @inherits Merchello.Web.Mvc.MerchelloTemplatePage
    @using System;
    @using System.Web.Mvc.Html
    @using Newtonsoft.Json;
    @using Newtonsoft.Json.Linq;
    @using Merchello.Web
    @using Merchello.Bazaar
    @using Merchello.Bazaar.Models.ViewModels
    @using Merchello.Web.Models.VirtualContent
    @using Umbraco.Web
    
    @foreach( var item in relatedContent )
    {
        string docType = item.DocumentTypeAlias;
        switch(docType)
        {
            case "RelatedEvent":
                @RelatedEvent( item )
                break;
            case "RelatedProduct":
                @RelatedProduct( item )
                break;
            default:
                break;
        }
    }
    
    @helper RelatedProduct(IPublishedContent item)
    {
        var productObject = item.GetPropertyValue("product");
        JObject productJSON = JObject.Parse(Json.Encode(productObject).ToString());
        var helper = new MerchelloHelper();
        var key = new Guid((string)productJSON["Key"]);
        var product = helper.Query.Product.GetByKey(key);
    
        <p>@product.Name</p>
    }
    

    Not sure if you need all namespaces at the top. It's just something I got working.

    Related product uses Merchello Product Selector data type so you can use it to get list of products, search. Please find screen grab attached.

    enter image description here

  • Chris Foot 61 posts 93 karma points
    Dec 07, 2015 @ 13:43
    Chris Foot
    0

    Fantastic, thanks. I've never used the nested content plugin. Might be using it a bit more often from now on!! Took a few minutes to get my head around how it worked, the key part I was missing was creating the document type for a related product.

    The only thing I couldn't work out was what to put in the Name template field on the nested content data type form. I tried {{product}} (product being my product selector field) but that just gives me the merchello product key. Is there any way to get the actual product name that was selected?

    Thanks

    Chris

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Feb 03, 2016 @ 12:56
    Simon Dingley
    0

    I've not had any success as yet getting the product name into the item name template using Nested Content but using nested content to get multiple related items works quite well as a solution to this problem. Also, I have found that you can simply us GetPropertyValue<ProductDisplay>("Product") to get the selected product from the property on the doctype used in the NestedContent datatype, I assume this is through the power of ContentConvertors that might now be included in the package making this sort of ting possible:

    var relatedProducts = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("RelatedProductsProperty");
    
    @foreach (var relatedProduct in relatedProducts)
    {
        var product = relatedProduct.GetPropertyValue<ProductDisplay>("Product");
        var productContent = product.AsProductContent();
        var img = productContent.GetPropertyValue<IPublishedContent>("image");
    
        // Do your stuff here...
    }
    

    ... this saves having to mess around MerchelloHelper and querying products.

    Hopefully someone can solve the problem with the product title appearing as the nested content item title and this will be a perfect solution for me!

Please Sign in or register to post replies

Write your reply to:

Draft