Tagging
This article describes in detail how to use the .NET API for tagging.
In Litium, there are two types of tags.
- System-defined tags which are prefixed identified by underscore at the beginning. These tags cannot be added or removed from the back office.
- tags added in backoffice does not start with underscores, and can be removed,
When a tag is added, an event will be fired indicating that a tag is added to that entity.
When a tag is removed, an event will be fired indicating that a tag is removed from that entity.
The tags can be translated using system text to be shown in the UI.
.NET API
- The following entities can be tagged:
Order
, Shipment
, Payment
, Transaction
- An order can be created with tags, by adding the tags to the cart; the tags are added before the order state transition begins. You may use the tags to control the process flow in state transition validation rules (conditional logic that controls whether an order can move from one state to another)
How to add a tag to an entity
To add/remove tags, use the TaggingService
// add
_taggingService.Add<SalesOrder>(createdSalesOrder.SystemId, "yellow");
// get all
var tags = _taggingService.GetAll<SalesOrder>(createdSalesOrder.SystemId);
// remove
_taggingService.Remove<SalesOrder>(entitySystemId, tagId);
Once the tag is added or removed, the corresponding events TagAdded
, TagRemoved
will be raised.
If the entity is removed, its tags are also removed.
How to add a tag to the cart
Use CartContext.SetTagAsync method to add tags to the order being created. These tags are added at the time of creating the order.
_cartContextAccessor.CartContext.SetTagsAsync(new HashSet<string> { OrderTaggingConstants.AwaitOrderApproval });