CheckoutItemLineCommentExtension reference
This article provides reference material about CheckoutItemLineCommentExtension
class. All checkout item line comment extensions
have to be inherited from the CheckoutItemLineCommentExtension
class which, in turn, inherits from the core Sana Commerce Cloud Extension
class.
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.
ValidateCommentAsync
Validates the provided checkout item line comment.
Sana calls this method and passes the instance of CheckoutItemLineCommentValidationContext and the method returns an instance of CheckoutItemLineCommentValidationResult that represents the result of the checkout item line comment validation operation.
Example:
public override Task<CheckoutItemLineCommentValidationResult> ValidateCommentAsync(
CheckoutItemLineCommentValidationContext context,
CancellationToken cancellationToken = default)
{
var result = ValidateComment(context);
if (result.IsValid)
return Task.FromResult(CheckoutItemLineCommentValidationResult.Succeeded());
var errorMessage = result.ErrorMessage;
return Task.FromResult(CheckoutItemLineCommentValidationResult.Failed(errorMessage));
}
CommentForcesRecalculationAsync
Checks whether comment change should force basket recalculation.
Sana calls this method and passes the instance of CheckoutItemLineCommentCalculationContext and the method returns a System.Boolean
which determines whether basket calculation should be forced.
Note
Method is never called in Optimize for large orders
processing strategy as comment will always be synced in this mode.
Example:
public override ValueTask<bool> CommentForcesRecalculationAsync(CheckoutItemLineCommentCalculationContext context, CancellationToken cancellationToken)
{
var sanaGroupAttribute = context.Product.Attributes.FirstOrDefault(a => a.Name == "SANA GROUP");
var result = sanaGroupAttribute?.Value.ToString() == "SYSTEM_PRODUCT";
return ValueTask.FromResult(result);
}
FormatValueForDisplayAsync
Formats comment value for display.
Sana calls this method and passes the instance of CheckoutItemLineCommentDisplayValueFormatContext and the method returns a value task which represents the formatted comment value.
This method will be used to format the comment for emails, as well as for the checkout and document pages when no client display component is available.
Example:
public override ValueTask<string?> FormatValueForDisplayAsync(CheckoutItemLineCommentDisplayValueFormatContext context, CancellationToken cancellationToken)
{
var comment = context.Line.Comment;
return ValueTask.FromResult<string?>("Addon comment from server: "
+ Api.GetSanaText(
key: comment.IsEmptyString() ? "CommentNotPresent" : "Comment_" + comment,
defaultText: comment.IsEmptyString() ? "Addon comment is not present" : comment));
}