Developer forum

Forum » Templates » Get eCom group values within Dynamicweb.Frontend.PageViewModel?

Get eCom group values within Dynamicweb.Frontend.PageViewModel?

Jacob Storgaard Jensen
Reply

Hi guys, sorry for this question, but I'm trying to catch up on a few years of Dynamicweb coding break.

I have a page template which starts like this (I have to do changes to a already built site):

@using Dynamicweb.Ecommerce.Products
@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel>

On this page I would like to check if there has been set a boolean value on a custom ecom group field, and then output the navigation using another navigation template... Earlier on I would have figured it out, but now I don't know how to get values outside of the PageViewModel... (I don't have any Intellisence)

Any help to help me get my lightbulb turned on again would be greatly appreciated!

 


Replies

 
Nicolai Pedersen
Reply

Something like this:

var groupid = HttpContext.Current.Request.QueryString.Get("GroupID");
            if (!string.IsNullOrEmpty(groupid))
            {
                var group = Dynamicweb.Ecommerce.Products.Group.GetGroupById(groupid);
                var customFieldValue = (string)group.ProductGroupFieldValues.GetProductGroupFieldValue("SystemName").Value;
                if(customFieldValue == "Nicolai"){
                    //Do magic
                }
            }

 
Jacob Storgaard Jensen
Reply

Thanks - but when I do this I get this error:

Line 2360: } expected
Line 2360: } expected

The whole block of code looks like this:

@{
    var image = Model.Item.GetFile("PageImage");
    var ImageHeight = Model.Item.GetString("ImageHeight");
    var PageText = Model.Item.GetString("Text");
    var PageType = Model.Item.GetString("PageType");
    // If Password is enabled on page PageType is empty so set it to default
    if (string.IsNullOrEmpty(PageType))
    {
        PageType = "default";
    }

    var ecomquery = @System.Web.HttpContext.Current.Request.QueryString["ecomQuery"];
    var prodid = @System.Web.HttpContext.Current.Request.QueryString["productid"];
    var groupid = @System.Web.HttpContext.Current.Request.QueryString["groupid"];
    
    if (!string.IsNullOrEmpty(groupid))
            {
                var group = Dynamicweb.Ecommerce.Products.Group.GetGroupById(groupid);
                var customFieldValue = (string)group.ProductGroupFieldValues.GetProductGroupFieldValue("GroupLeftNavIsolation").Value;
                if(customFieldValue == "true"){
                    //Do something
                }
            }

}
 
Nicolai Pedersen
Reply

Jep, then you better start debugging...

And get your hands on Visual Studio :-)

 
Jacob Storgaard Jensen
Reply

Argh, hate taking ower stuff from others angry I'll get at the debugging.

Yes I know about Visual Studio - have to talk to you 5 minutes sometime.

 
Jacob Storgaard Jensen
Reply

To anyone as stupid as myself - here's what fixed it for me - Green is added, red is deleted

@{
    var image = Model.Item.GetFile("PageImage");
    var ImageHeight = Model.Item.GetString("ImageHeight");
    var PageText = Model.Item.GetString("Text");
    var PageType = Model.Item.GetString("PageType");
    // If Password is enabled on page PageType is empty so set it to default
    if (string.IsNullOrEmpty(PageType))
    {
        PageType = "default";
    }

    var ecomquery = @System.Web.HttpContext.Current.Request.QueryString["ecomQuery"];
    var prodid = @System.Web.HttpContext.Current.Request.QueryString["productid"];
    var groupid = @System.Web.HttpContext.Current.Request.QueryString["groupid"];

    string customFieldValue = "";
    if (!string.IsNullOrEmpty(groupid))
    {
       var group = Dynamicweb.Ecommerce.Products.Group.GetGroupById(groupid);
       customFieldValue = Dynamicweb.Core.Converter.ToString(group.ProductGroupFieldValues.GetProductGroupFieldValue("SystemName").Value); 
       if(customFieldValue == "true"){
            //Do magic
        }
    }
}

 

You must be logged in to post in the forum