Extension.Api.CurrentUserData reference
Every extension in Sana has access to data retrieval functionality via its Api.CurrentUserData
property. This property holds an instance of DataManager
type which serves as an entry
point to save or retrieve any generic data that the extension needs to store in Sana.
The data is persisted in SQL database and can be accessible throughout multiple requests and on all server instances in multi-server setup.
Data isolation
The data is isolated per extension and per customer ID. This means that the data you save will be accessible only when the same customer browses the web store and in scope of the same extension.
Important
Anonymous users share the same customer ID - the customer which is configured in ERP as template for anonymous users. This means that for all anonymous users the same data will be accessible.
Methods
Save
Saves data in SQL database for current user. This data is saved permanently and will be
available on each request. The data which is saved can be any primitive or complex type
— internally SanaObjectSerializer
is used to serialize the data before saving it.
// saving primitive type data
string data = "some data";
Api.CurrentUserData.Save(data);
// saving complex type data
var data = new Dictionary<string, string>
{
{ "key 1", "value 1" },
{ "key 2", "value 2" }
};
Api.CurrentUserData.Save(data);
Get
Gets data previously saved per current user from SQL database.
// generic type parameter is used to cast the resulting data object to
var data = Api.CurrentUserData.Get<string>();