Products module (custom module) filter by category
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
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
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
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
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
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());
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());
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
I also get the same second error if I change the GetValue lines in the DataProvider.cs.
- William
I am getting the same issue. The bug was just added to PITS: http://www.telerik.com/support/pits.aspx#/public/sitefinity/6330
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
I tried your suggestion but still get this error:
variable 'item' of type 'Sample.CustomContentItem' referenced from scope '', but it is not defined
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;
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;Regards,
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());
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());
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!
Hi Saeed,
In your expression specify the item you want to return - Master or Live.
Greetings,
Ivan Dimitrov
the Telerik team
Thanks Ivan, It was that!
Hi Saeed, I am working on an article module as well. I am wondering if you would be willing to share it.
Thanks