Developer forum

Forum » Dynamicweb 9.0 Upgrade issues » Making a product search, in prep for DW9

Making a product search, in prep for DW9

Thomas Jensen
Reply

This gives me some issus (using repository)

1: Getting info out of array
Alle i get out of @queryResultItem.GetValue("GroupNames") is the string "System.String[]"
GroupIDs | System.String[] | System.String[]
GetLoop dose not help either
How do i loop tru a System.String[] array or output the id's?

2: With mulitble sites/languages, i need to filter so i only get products that belong to current site/language
I can in the query set a value to do this, but then i need to make multible querys
I can do it with Querystring to ad "LANG1" "SHOP1" but that do not look clean
Can i give the repository query a variable from the Razor template?


Replies

 
Steffen Kruse Hansen Dynamicweb Employee
Steffen Kruse Hansen
Reply
This post has been marked as an answer

Hi Thomas,

1) The GetValue function of QueryResultItem returns the type System.Object, so if property you are looking at is an array, you have to cast it to the correct type. When you have casted it to an array, you should be able to iterate over it with a simple For-loop to get all the values

2) This can be done by using our macros. You can read more about that on our DocSite http://doc.dynamicweb.com/documentation-9/platform/indexing-search/indexing-search#sideNavTitle1-3-2-2

You should look at:

 - Dynamicweb.Ecommerce.Context.LanguageID

 - Dynamicweb.Ecommerce.Context.ShopID

 

I hope this answers your questions

 

Best regards,

Steffen

Votes for this answer: 1
 
Thomas Jensen
Reply

Hi Steffen

Yes thanks

example for looping tru GroupID:
@foreach (var result in GetLoop("QueryResultItem")){
    object anArray = result.GetValue("GroupIDs");
    IEnumerable<String> enumerable = anArray as IEnumerable<String>;
    if (enumerable != null){
        foreach(object element in enumerable){
                <p>@element</p>
        }
    }

 

You must be logged in to post in the forum