CheckoutFieldExtension reference
This article provides reference material about CheckoutFieldExtension
class. All checkout field extensions
have to be inherited from the CheckoutFieldExtension
which, in turn, inherits from the core
Sana Commerce Cloud Extension
class.
This extension should be used to extend checkout process with additional field.
Note
Multiple CheckoutFieldExtension
extensions can be created in case multiple fields should be added to checkout.
Properties
FieldName
The name of the ERP document entity field.
Note
Sales documents entity fields should contain the field with provided name to store the field value within sales document on ERP side, otherwise ERP changes are required.
public override string FieldName => "AddressId";
Methods
Note
All code examples may contain nonexistent methods or properties. They are used as declarations only and should be created if they fit the designed extension or deleted if they do not.
GetFieldValue
Gets the checkout field value.
public override ErpFieldValue? GetFieldValue(in CheckoutFieldContext context)
{
var addressId = Api.CurrentUserData.Get<UserData>()?.SelectedAddressId;
if (string.IsNullOrEmpty(addressId))
return null;
return ErpFieldValue.FromString(addressId);
}
sealed class UserData
{
public string? SelectedAddressId { get; set; }
}
OnEditDocument
A handler that is invoked when a sales document is editing. This method can be used to initialize current field value with the value stored within sales document which is editing at the moment.
public override void OnEditDocument(in CheckoutFieldEditDocumentContext context)
{
var addressId = context.Value?.AsString();
Api.CurrentUserData.Save(new UserData { SelectedAddressId = string.IsNullOrEmpty(addressId) ? null : addressId });
}
sealed class UserData
{
public string? SelectedAddressId { get; set; }
}
OnReorderDocument
A handler that is invoked when a sales document is reordering. This method can be used to initialize current field value with the value stored within sales document which is reordering at the moment.
public override void OnReorderDocument(in CheckoutFieldReorderDocumentContext context)
{
var addressId = context.Value?.AsString();
Api.CurrentUserData.Save(new UserData { SelectedAddressId = string.IsNullOrEmpty(addressId) ? null : addressId });
}
sealed class UserData
{
public string? SelectedAddressId { get; set; }
}
OnPayOfflineDocument
A handler that is invoked when an off-line document is paying. This method can be used to initialize current field value with the value stored within off-line created document which is paying at the moment.
public override void OnPayOfflineDocument(in CheckoutFieldPayOfflineDocumentContext context)
{
var addressId = context.Value?.AsString();
Api.CurrentUserData.Save(new UserData { SelectedAddressId = string.IsNullOrEmpty(addressId) ? null : addressId });
}
sealed class UserData
{
public string? SelectedAddressId { get; set; }
}