Copied to clipboard

Flag this post as spam?

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


  • Edgar Rasquin 326 posts 925 karma points
    Mar 25, 2021 @ 13:50
    Edgar Rasquin
    0

    Filter by Multinode Treepicker value

    Hi there,

    I have a pool of products. Each product has categories assigned (multi node tree picker).

    How do I filter when loading a category page? My approach so far wich does not work:

    var shop = Umbraco.Content(2724);
    var currentkategorie = Model.Id.ToString();
    
    var allproducts = shop.Children<Product>().Where(x => x.IsVisible()).Where(x => x.Value<IEnumerable<IPublishedContent>>("kategorien").ToString().Contains(currentkategorie));
    
  • Alex Skrypnyk 6168 posts 24148 karma points MVP 8x admin c-trib
    Mar 25, 2021 @ 15:58
    Alex Skrypnyk
    0

    Hi Edgar,

    Try this code:

    var shop = Umbraco.Content(2724);
        var currentkategorie = Model.Id;
    
        var allproducts = shop.Children().Where(x => x.IsVisible()).Where(x => x.Value<IEnumerable<IPublishedContent>>("kategorien").Select(y => y.Id).Contains(currentkategorie));
    

    You are trying to get products by Category.Id, but in multi-node tree picker value stores as List of Udi

    Thanks,

    Alex

  • Edgar Rasquin 326 posts 925 karma points
    Mar 25, 2021 @ 16:10
    Edgar Rasquin
    0

    Hi Alex,

    thanks a lot for your answer.

    I guess it would work.

    But unfortunately I have products without a category assigned. Therefore I get an System.ArgumentNullException:

    System.ArgumentNullException: "The value must not be NULL. Parameter name: source"
    

    Is it possible to check for NULL within the query?

    EDIT:

    I have put an extra Where statement with HasValue in it:

    .Where(z => z.HasValue("kategorien"))
    
  • Alex Skrypnyk 6168 posts 24148 karma points MVP 8x admin c-trib
    Mar 25, 2021 @ 16:17
    Alex Skrypnyk
    0

    Yes, of course, juse add a check - x.HasValue("kategorien")

    var allproducts = shop.Children().Where(x => x.IsVisible()).Where(x => x.HasValue("kategorien") && x.Value<IEnumerable<IPublishedContent>>("kategorien").Select(y => y.Id).Contains(currentkategorie));
    
  • Edgar Rasquin 326 posts 925 karma points
    Mar 25, 2021 @ 16:20
    Edgar Rasquin
    0

    Now I get the following error:

    System.FormatException: "String "[{"name":"LEHRMITTEL"" is not a valid udi."
    

    LEHRMITTEL is one of my categories.

  • Edgar Rasquin 326 posts 925 karma points
    Mar 25, 2021 @ 19:31
    Edgar Rasquin
    0

    Stupid coincidence. Before I used the multinode-treepicker for my categories, I used a multi Url Picker wich was not the best idea...

    Since I than changed the datatype I guess the value from the multi Url Picker is still stored in that field. That is probably causing the conflict.

    Any ideas how I can delete this content?

    I tried to select a category but the site is not responding when I'm trying to save.

    Do I have do clear the false value directly in MS SQL db?

  • Alex Skrypnyk 6168 posts 24148 karma points MVP 8x admin c-trib
    Mar 25, 2021 @ 19:33
    Alex Skrypnyk
    1

    Yes, you are right, it stores old values, and that's why you are not able to retrieve the data.

    So you have to resave products

  • Edgar Rasquin 326 posts 925 karma points
    Mar 25, 2021 @ 19:53
    Edgar Rasquin
    1

    Alex,

    thank you very much for your help.

    I really appreciate it!

    Have a nice evening.

  • Alex Skrypnyk 6168 posts 24148 karma points MVP 8x admin c-trib
    Mar 25, 2021 @ 20:02
    Alex Skrypnyk
    0

    You are always welcome and have a nice evening too!!!

  • Alex Skrypnyk 6168 posts 24148 karma points MVP 8x admin c-trib
    Mar 25, 2021 @ 16:30
    Alex Skrypnyk
    0

    Edgar, does a multinode tree picker contain one and many categories for different products?

  • Edgar Rasquin 326 posts 925 karma points
    Mar 25, 2021 @ 16:34
    Edgar Rasquin
    0

    One product can be assigned to multiple categories:

    enter image description here

    But can as well be assigned only to one category.

    Hope that answers your question.

Please Sign in or register to post replies

Write your reply to:

Draft