+1-888-365-2779
Try Now
More in this section

Forums / Sitefinity SDK / Products module (custom module) filter by category

Products module (custom module) filter by category

18 posts, 0 answered
  1. William
    William avatar
    108 posts
    Registered:
    15 Feb 2011
    15 Apr 2011
    Link to this post
    Okay, let's try this one :)

    Has anyone gotten "filter by category" or "fliter by tag" to show up on the backend landing page for the Products module?  My entries are tagged and categorized just fine, but I have no option to view by category or tag as might be suggested in the ProductsDefinitions.cs file.

    Is there something missing in the code?

    Thanks

    - William
  2. William
    William avatar
    108 posts
    Registered:
    15 Feb 2011
    15 Apr 2011
    Link to this post
    Update: Found this in the code - // TODO: get all taxonomies used by the productsItem type and create a command item for them and respective link.

    Plus several lines of code commented out.

    I'm assuming, then, this was never implemented (and uncommenting the lines of code breaks the module), so is there some small bit of code I can place in the module to see the command link?

    - William
  3. Nikolay Datchev
    Nikolay Datchev avatar
    87 posts
    Registered:
    02 Jun 2016
    20 Apr 2011
    Link to this post
    Hello William,

    These lines shown below are uncommented in the upcoming 4.1 SDK(next week) and they work,e.g. the filters are showing. Also we have enabled the Custom fields functionality for the Products Module.


                DefinitionsHelper.CreateTaxonomyLink(
                    TaxonomyManager.CategoriesTaxonomyId,
                    DefinitionsHelper.HideSectionsExceptCommandName,
    DefinitionsHelper.ConstructDisplaySectionsCommandArgument(categoryFilterSection.WrapperTagId),
                    sidebarSection);

                DefinitionsHelper.CreateTaxonomyLink(
                    TaxonomyManager.TagsTaxonomyId,
                    DefinitionsHelper.HideSectionsExceptCommandName,
    DefinitionsHelper.ConstructDisplaySectionsCommandArgument(tagFilterSection.WrapperTagId),
                    sidebarSection);

    the following line should be removed
    //DefinitionsHelper.CreateTaxonomyLinks(sidebarSection);


    Greetings,
    Nikolay Datchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  4. Anthony
    Anthony avatar
    17 posts
    Registered:
    21 May 2003
    29 May 2011
    Link to this post
    Hi,

    I have a bug in the products module when filtering by tag or category, i think this may be a problem with the sdk module rather than my installation. When trying to filter by an item i get the following popup error

    NonGeneric method 'object GetValue(string fieldName)' is not supported in LINQ queries. Use generic 'TValue GetValue<TValue>(string fieldName)' instead.

    Can you confirm if this is a problem with the module or just my installation

    Cheers
    Anthony
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    30 May 2011
    Link to this post
    Hi Anthony,

    You should use GetValue<T>. Somewhere in the code is used not the generic method. I am testing with Sitefinity build 1339 and there is no issues to filter products by tag.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  6. Anthony
    Anthony avatar
    17 posts
    Registered:
    21 May 2003
    30 May 2011
    Link to this post
    Hi Ivan,

    I am using 1395 and definitely have an issue, i tried to solve the code error myself and found this section in DynamicContentDataProvider.cs

    public override IEnumerable GetItemsByTaxon(Guid taxonId, bool isSingleTaxon, string propertyName, Type itemType, string filterExpression, string orderExpression, int skip, int take, ref int? totalCount)
           {
               if (itemType == typeof(DynamicContentItem))
               {
                   this.CurrentTaxonomyProperty = propertyName;
                   IQueryable<DynamicContentItem> query = (IQueryable<DynamicContentItem>)this.GetItems(itemType, filterExpression, string.Empty, skip, take, ref totalCount);
                   if (isSingleTaxon)
                   {
                       var query0 = from i in query
                                    where i.GetValue(this.CurrentTaxonomyProperty) == taxonId
                                    select i;
                       if (!string.IsNullOrEmpty(orderExpression))
                       {
                           return query0.OrderBy(orderExpression);
                       }
     
                       return query0;
                   }
                   else
                   {
                       var query1 = from i in query
                                    where ((IList)i.GetValue(this.CurrentTaxonomyProperty)).Contains(taxonId)
                                    select i;
                       if (!string.IsNullOrEmpty(orderExpression))
                       {
                           return query1.OrderBy(orderExpression);
                       }
     
                       return query1;
                   }
               }
     
               throw GetInvalidItemTypeException(itemType, this.GetKnownTypes());
           }

    i changed it to this code

    public override IEnumerable GetItemsByTaxon(Guid taxonId, bool isSingleTaxon, string propertyName, Type itemType, string filterExpression, string orderExpression, int skip, int take, ref int? totalCount)
           {
               if (itemType == typeof(DynamicContentItem))
               {
                   this.CurrentTaxonomyProperty = propertyName;
                   IQueryable<DynamicContentItem> query = (IQueryable<DynamicContentItem>)this.GetItems(itemType, filterExpression, string.Empty, skip, take, ref totalCount);
                   if (isSingleTaxon)
                   {
                       var query0 = from i in query
                                    where i.GetValue<Guid>(this.CurrentTaxonomyProperty) == taxonId
                                    select i;
                       if (!string.IsNullOrEmpty(orderExpression))
                       {
                           return query0.OrderBy(orderExpression);
                       }
     
                       return query0;
                   }
                   else
                   {
                       var query1 = from i in query
                                    where ((IList)i.GetValue<IList<Guid>>(this.CurrentTaxonomyProperty)).Contains(taxonId)
                                    select i;
                       if (!string.IsNullOrEmpty(orderExpression))
                       {
                           return query1.OrderBy(orderExpression);
                       }
     
                       return query1;
                   }
               }
     
               throw GetInvalidItemTypeException(itemType, this.GetKnownTypes());
           }

    and now i get this error (where DynamicContentItem is my class to replace ProductItem)

    variable 'item' of type 'AK.QDOS.DynamicContent.Model.DynamicContentItem' referenced from scope '', but it is not defined
  7. William
    William avatar
    108 posts
    Registered:
    15 Feb 2011
    31 May 2011
    Link to this post
    Anthony and Ivan,

    I can confirm I'm getting this error message as well now in my installed custom modules, but only on an SP1 build.  I'm currently building with 1405.  This error does not occur for me on my non-SP1 4.1 project build.

    Any advice?

    - William

  8. William
    William avatar
    108 posts
    Registered:
    15 Feb 2011
    31 May 2011
    Link to this post
    I also get the same second error if I change the GetValue lines in the DataProvider.cs.

    - William
  9. Basem
    Basem avatar
    131 posts
    Registered:
    22 Dec 2010
    01 Jun 2011
    Link to this post
    I am getting the same issue. The bug was just added to PITS: http://www.telerik.com/support/pits.aspx#/public/sitefinity/6330
  10. Nikolay Datchev
    Nikolay Datchev avatar
    87 posts
    Registered:
    02 Jun 2016
    03 Jun 2011
    Link to this post
    Hi Basem,

    Can you try to change the

    ((IList)i.GetValue<
    IList<Guid>>(this.CurrentTaxonomyProperty)).Contains(taxonId)

    with

    (i.GetValue<IList<Guid>>(this.CurrentTaxonomyProperty)).Any(t => t == taxonId))


    Greetings,
    Nikolay Datchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  11. Basem
    Basem avatar
    131 posts
    Registered:
    22 Dec 2010
    05 Jun 2011
    Link to this post
    I tried your suggestion but still get this error:

    variable 'item' of type 'Sample.CustomContentItem' referenced from scope '', but it is not defined
  12. Daniel Plomp
    Daniel Plomp avatar
    112 posts
    Registered:
    14 Jun 2012
    06 Jun 2011
    Link to this post
    Hi Nikolay,

    I tried to change

    ((IList)i.GetValue<IList<Guid>>(this.CurrentTaxonomyProperty)).Contains(taxonId)

    with

    (i.GetValue<IList<Guid>>(this.CurrentTaxonomyProperty)).Any(t => t == taxonId))

    But that doesn't work. Not a valid syntax. How is the exact syntax for this query1?

    Here the original code:
    var query1 = from i in query
                           where ((IList)i.GetValue<IList<Guid>>(this.CurrentTaxonomyProperty)).Contains(taxonId)
                           select i;
                        if (!string.IsNullOrEmpty(orderExpression))
                        {
                            return query1.OrderBy(orderExpression);
                        }
     
                        return query1;

    Regards,
    Daniel
  13. Nikolay Datchev
    Nikolay Datchev avatar
    87 posts
    Registered:
    02 Jun 2016
    10 Jun 2011
    Link to this post
    Hello Daniel ,

    This is the syntax is it possible that you omitted to declare the namespace of the extension method that we use.
    I am quoting again the latest products module DataProvider code( this will go into the next SDK) - please try to use exactly this syntax and method code just change your class names:

    Also are you using 4.1. Sp1?



    using System;
    using System.Collections;
    using System.Linq;
    using ProductCatalogSample.Model;
    using Telerik.Sitefinity.Configuration;
    using Telerik.Sitefinity.Data.Linq.Dynamic;
    using Telerik.Sitefinity.GenericContent.Model;
    using Telerik.Sitefinity.Model;
    using Telerik.Sitefinity.Modules.GenericContent;
    using Telerik.Sitefinity.Security;
    using Telerik.Sitefinity.Security.Configuration;
    using Telerik.Sitefinity.Security.Model;
    using System.Collections.Generic;
    public override IEnumerable GetItemsByTaxon(Guid taxonId, bool isSingleTaxon, string propertyName, Type itemType, string filterExpression, string orderExpression, int skip, int take, ref int? totalCount)
            {
                if (itemType == typeof(ProductItem))
                {
                    this.CurrentTaxonomyProperty = propertyName;

                    IQueryable<ProductItem> query = this.GetProducts().Where(filterExpression).OrderBy(orderExpression);
                    if (isSingleTaxon)
                    {
                        var query0 = from i in query
                                     where i.GetValue<Guid>(this.CurrentTaxonomyProperty) == taxonId
                                     select i;

                        query = query0;
                    }
                    else
                    {

                        var query1 = from i in query
                                     where (i.GetValue<IList<Guid>>(this.CurrentTaxonomyProperty)).Any(t => t == taxonId)
                                     select i;
                        query = query1;
                    }

                    if (totalCount.HasValue)
                    {
                        totalCount = query.Count();
                    }

                    if (skip > 0)
                        query = query.Skip(skip);
                    if (take > 0)
                        query = query.Take(take);
                    return query;
                }

                throw GetInvalidItemTypeException(itemType, this.GetKnownTypes());
            }
    Regards,
    Nikolay Datchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  14. Craig
    Craig avatar
    9 posts
    Registered:
    22 Feb 2011
    30 Jun 2011
    Link to this post
    For anyone who stumbles on this later:

    The code from Nikolay is missing an "else" after the first "if" statement, so it will ALWAYS throw the Exception.

    Here is the corrected code:
    using System;
    using System.Collections;
    using System.Linq;
    using ProductCatalogSample.Model;
    using Telerik.Sitefinity.Configuration;
    using Telerik.Sitefinity.Data.Linq.Dynamic;
    using Telerik.Sitefinity.GenericContent.Model;
    using Telerik.Sitefinity.Model;
    using Telerik.Sitefinity.Modules.GenericContent;
    using Telerik.Sitefinity.Security;
    using Telerik.Sitefinity.Security.Configuration;
    using Telerik.Sitefinity.Security.Model;
    using System.Collections.Generic;
     
    public override IEnumerable GetItemsByTaxon(Guid taxonId, bool isSingleTaxon, string propertyName, Type itemType, string filterExpression, string orderExpression, int skip, int take, ref int? totalCount)
            {
                if (itemType == typeof(ProductItem))
                {
                    this.CurrentTaxonomyProperty = propertyName;
     
                    IQueryable<ProductItem> query = this.GetProducts().Where(filterExpression).OrderBy(orderExpression);
                    if (isSingleTaxon)
                    {
                        var query0 = from i in query
                                     where i.GetValue<Guid>(this.CurrentTaxonomyProperty) == taxonId
                                     select i;
     
                        query = query0;
                    }
                    else
                    {
     
                        var query1 = from i in query
                                     where (i.GetValue<IList<Guid>>(this.CurrentTaxonomyProperty)).Any(t => t == taxonId)
                                     select i;
                        query = query1;
                    }
     
                    if (totalCount.HasValue)
                    {
                        totalCount = query.Count();
                    }
     
                    if (skip > 0)
                        query = query.Skip(skip);
                    if (take > 0)
                        query = query.Take(take);
                    return query;
                }
                else
                     throw GetInvalidItemTypeException(itemType, this.GetKnownTypes());
            }

  15. Saeed
    Saeed avatar
    14 posts
    Registered:
    21 Jun 2011
    05 Jul 2011
    Link to this post
    Hi There,

    I used the Product SDK to create an Articles module! but Currently I have a problem with Taxonomies, I used following code to get the Articles by category but It returns each Article two times!

            public IEnumerable<ArticleItem> GetArticlesByCategory(Guid categoryId)
            {
                this.CurrentTaxonomyProperty = "Category";
                return (from i in this.GetArticles()
                             where (i.GetValue<IList<Guid>>(this.CurrentTaxonomyProperty)).Any(t => t == categoryId)
                        select i);
            }

    The Strange thing is returned ArticleItems have different Ids but everything else is same!

    Thanks for your support,
    Saeed!
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    05 Jul 2011
    Link to this post
    Hi Saeed,

    In your expression specify the item you want to return - Master or Live.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  17. Saeed
    Saeed avatar
    14 posts
    Registered:
    21 Jun 2011
    05 Jul 2011
    Link to this post
    Thanks Ivan, It was that!
  18. Sonu Kapoor
    Sonu Kapoor avatar
    41 posts
    Registered:
    24 Apr 2006
    14 Jul 2011
    Link to this post
    Hi Saeed, I am working on an article module as well. I am wondering if you would be willing to share it.

    Thanks
18 posts, 0 answered