I have a requirements to search on products based on their custom properties. The search will be similar to sites such as ASOS.com with a side bar allowing you to select from drop-downs and checkboxes to filter your products.
I have got some way of performing this as follows:
@{var q = from product in Product.All() where product.ProductProperties.Where(property => (property.ProductDefinitionField.Name == "Size" && property.Value == Request["size"])).Count() == 1 && product.ParentProductId == null select product; }
@{var products = q.ToList();}
@foreach (var product in products)
However, the areas I am struggling with are as follows:
1) I am still in the process of learning LINQ so I am not sure how you perform a query based on multiple custom properties of the same type (e.g. The user selects three different types of style which are passed in the query as style=Style1,Style2,Style3)
2) How do you build up a query based on what the user has selected. E.g. the user has selected a size from a dropdown, and a style and a price. I tried the following but it's not quite right as it assumes the custom property will always exist.
Managed to solve this myself, so for the benefit of others out there, this is how I performed the filtering of products based on the passed in query string via AJAX.
Performing product based searches
I have a requirements to search on products based on their custom properties. The search will be similar to sites such as ASOS.com with a side bar allowing you to select from drop-downs and checkboxes to filter your products.
I have got some way of performing this as follows:
However, the areas I am struggling with are as follows:
1) I am still in the process of learning LINQ so I am not sure how you perform a query based on multiple custom properties of the same type (e.g. The user selects three different types of style which are passed in the query as style=Style1,Style2,Style3)
2) How do you build up a query based on what the user has selected. E.g. the user has selected a size from a dropdown, and a style and a price. I tried the following but it's not quite right as it assumes the custom property will always exist.
Any help on this, or pointing me in the right direction would be great.
Managed to solve this myself, so for the benefit of others out there, this is how I performed the filtering of products based on the passed in query string via AJAX.
Nicely done. Thanks for sharing.
is working on a reply...