Developer forum

Forum » Development » Access website settings field in C#

Access website settings field in C#

Ronnie Poulsen
Ronnie Poulsen
Reply

Hi,

I am working on a custom PriceProvider to enable price uplifting on certain countries solutions. This PriceProvider should be activated/deactivated from website settings, and then later on have a value set either on a product or product group level.

I have added a new field (checkbox) on the Website app in the Ecommerce area. How do I access this field (as well as fields on products or product groups) in my PriceProvider code? Maybe I am blind, but I cannot find any tutorials or guides on how to do this. I have looked at https://doc.dynamicweb.com/training/t3-platform-developer/t3-platform-developer/3-4-items#5967 but this is for use in templates - correct me if I am wrong.

Thanks in advance.

/Ronnie


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Ronnie,

The Website Settings are normally intended for use in the templates. It's is possible to get the values from a PriceProvider though. I assume this PriceProvider is intended for the frontend and not a web service or similar. There are different concerns to consider if that's the case.

First, you need to get the current PageView by calling the method Dynamicweb.Frontend.PageView.Current(). Once you have a valid PageView object, you can get the Area (the object that a website is based on) from the PageView.Area. The area instance has an Item attached which you can get from Area.Item. This Item is the Item that is edited from Website Settings and you will be able to get your setting from there. Item relations on the Item instance itself are represented by IDs, so you'll have to create the relevant instances manually by using the Item service (Dynamicweb.Services.Items.GetItem(itemType, itemId))

With regard to product groups, you'll have to either find the group from the context by looking for GroupID in the querystring or getting a group instance from the product instance that is given in the FindPrice method. If you find a group id in the querystring, you can use Dynamicweb.Ecommerce.Services.ProductGroups.GetGroup(groupId) to the the instance.

- Jeppe

 
Ronnie Poulsen
Ronnie Poulsen
Reply

Hi Jeppe,

Thank you very much for your quick reply (once again) :)

I will look into this.

/Ronnie

 
Søren Jakobsen
Reply

Hi,

I'm trying to get the value of a custom website setting in a custom dashboard view (ListWidget).

The following codesnippet will get me the website setting in a PriceProvider but how do I get the value in a dashboard?

 

var enableUplift = Dynamicweb.Frontend.PageView.Current().Area.Item["EnablePriceUplift"];

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

Hi Søren,

There is no concept of "Current Website" in the backend.

You need to specify which website you want the setting value from. You can then replace Dynamicweb.Frontend.PageView.Current().Area with Dynamicweb.Services.Areas.GetArea([YOUR_ID]).

- Jeppe

Votes for this answer: 1
 
Søren Jakobsen
Reply

Cool thanks,

ended up with this

var areaList = Dynamicweb.Services.Areas.GetAreas();
foreach (var area in areaList)
{
     var enableUplift = Dynamicweb.Services.Areas.GetArea(area.ID).Item["EnablePriceUplift"];

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Søren,

Glad to hear you found a solution.

One small note though. It's redundant retrieving the area from the service, when you already have the instance -- GetAreas gives you a list of Area instances. I'd recommend that you change your Dynamicweb.Services.Areas.GetArea(area.ID) to simply area.Item as it's equivalent.

- Jeppe

 

You must be logged in to post in the forum