1
votes

I have created a Content Type called "Products" which has a few fields, 2 of which are Taxonomy Fields (Product Type and Material)

Product Types: Cable cleats, Cable clamps, Pole cleats, Cable core Material: Stainless steel, Aluminium, Galvanised steel

I have a product listing and would like to filter it using the query string, over both taxonomies for example

List all products with product type of Cable cleats and material of Stainless steel ~/products?product-type[]=Cable cleats&material[]=Stainless steel

List all products with product type of Cable cleats or Pole cleats and material of Stainless steel ~/products?product-type[]=Cable cleats&product-type[]=Pole cleats&material[]=Stainless steel

(guessing it will be IDs used not the full text string for all queries)

Is there a way in Orchard to do this? or would it need a custom Module?

Any help would be much appreciated

Many thanks Anto

2

2 Answers

0
votes

Many projection filters have parameters where you can use tokens. To use the query string, you would use the QueryString token, like this: {QueryString:product-type}. Unfortunately, the taxonomy term filter does not currently work with tokens. It shouldn't be too hard to add that possibility however. Most of the code is already there.

0
votes

Quite an old question, but because it was referenced here, i give here a copy of my answer...

Note: Tried with a recent Orchard dev branch.

Here, for testing, i've done some changes directly in TermsFilter.cs and TermsFilterForms.cs, but based on this example, you will be able to write your own IFilterProvider and IFormProvider...

So, in TermsFilterForms.cs, in the Describe() method where the form is defined, try to add this:

                    ...
                    ),
                    _ProductType: Shape.TextBox(
                        Id: "product-type", Name: "ProductType",
                        Title: T("Product Type"),
                        Classes: new[] { "text medium", "tokenized" },
                        Description: T("Enter the product type.")
                        )
                    );
                    ...

Then, when editing your filter, you will see a new input field that can be tokenized and where e.g you can put:

    {Request.QueryString:product-type}

Then, in TermsFilter.cs, you can inject a tokenizer:

    ...
    private readonly ITokenizer _tokenizer;

    public TermsFilter(ITaxonomyService taxonomyService, ITokenizer tokenizer) {
        _taxonomyService = taxonomyService;
        T = NullLocalizer.Instance;
        _tokenizer = tokenizer;
    }
    ...

Then in the ApplyFilter(dynamic contex) method, you can tokenize your product-type field like this:

        var termName = _tokenizer.Replace((string)context.State.ProductType, null);

Here, for testing, in the query string product-type parameter, i expect only one value (not an array) that is a term name (not an id). But you can change the code according to your needs...

Then, by using the taxonomy service, you can do things like that:

        var taxoPart = _taxonomyService.GetTaxonomyByName("Product Type");
        var termPart = _taxonomyService.GetTermByName(taxoPart.Id, termName);

And then you can use e.g the termPart.Id to update the context.Query (see in the code)...

Best