Developer forum

Forum » Development » How to get item loops from website in checkout

How to get item loops from website in checkout

Christian Hansen Nørgaard
Reply

Hi DW.

I want to show my customers the specific credit cards that we accept in our shop so I made an item relation list to add to my website. Unfortunately it doesn't seem to work when I try to retrieve it when I am using below code in my checkout flow. The same code has been used on my masterpage and works like a charm. It's only when I am trying to retrieve it from e.g. ShowCart.cshtml that it doesn't work.

This is my code:

@foreach (LoopItem item in GetLoop("Item.Area.CreditCards"))
{
     item.GetString("Item.Area.CreditCards.Name.Value");
}

Is there some sort of Global tag I need to add to the above?


Replies

 
Nicolai Pedersen
Reply

Hi Christian

Those tags are not available in the context of a cart template.

Since you are using Razor, you can get hold of the information using the API directly: PageView.Current.Area.Item.*

BR Nicolai

 
Christian Hansen Nørgaard
Reply

Hi Nicolai.

I haven't used the API that much so I am not exactly sure how you mean I could use it to retrieve a list of items. Could you provide an example?

Regards,

Christian

 
Vladimir
Reply

Hi Christian,

If I'm not missed something, the code should be:

                                @{
                                    var myListId = (int)Pageview.Area.Item["CreditCards"];
                                    var itemList = Dynamicweb.Content.Items.ItemList.GetItemListById(myListId);  
                                    <select>
                                    @foreach (var card in itemList.Relations.Cast<Dynamicweb.Content.Items.Item>())
                                    {
                                        <option>@card["Name"]</option>
                                    }
                                    </select>
                                }

 

(I supposed that CreditCards - Item relation list)

Best regards,

Vladimir

 
Christian Hansen Nørgaard
Reply

Hi Vladimir.

Great, thanks for providing an example. :) I will try it out.

Regards,

Christian

 

You must be logged in to post in the forum