Configuration parameter set in commerce parameter
If you want to get the value of the configuration parameter set in commerce parameter in commerce runtime, then below is the code you execute,
string parameterValue = string.Empty;
GetConfigurationParametersDataRequest getConfigurationParametersDataRequest = new GetConfigurationParametersDataRequest(requestContext.GetPrincipal().ChannelId);
var retailConfigurationParameters = await requestContext.ExecuteAsync<EntityDataServiceResponse<RetailConfigurationParameter>>(getConfigurationParametersDataRequest).ConfigureAwait(false);
RetailConfigurationParameter retailConfigurationParameter = retailConfigurationParameters.ToList<RetailConfigurationParameter>().SingleOrDefault<RetailConfigurationParameter>((RetailConfigurationParameter c) => c.Name.Equals("YOUR PARAMETER NAME", StringComparison.OrdinalIgnoreCase));
if (retailConfigurationParameter !=
null)
{
parameterValue =
retailConfigurationParameter.Value;
}
· In the first line,
we create an Out-of-Box (OOB) request GetConfigurationParametersDataRequest
that takes the channelId from the requestContext.
· In the second
line, we execute the request and obtain the response in
retailConfigurationParameters.
· In the third line,
we convert the retailConfigurationParameters into a list and filter for the
required parameter value using the LINQ SingleOrDefault method.
Comments