OrderService
The Order service manages items that need to be shipped and fulfilled from a warehouse.
The OrderService is exposed through the
MerchelloContext
var orderService = MerchelloContext.Current.Services.OrderService;
Class
public class OrderService : PageCachedServiceBase<IOrder>,
IOrderService, IPageCachedService<IOrder>, IService
Constructors
Name | Description |
---|---|
OrderService() | Initializes a new instance of the OrderService class. |
OrderService(ILogger) | Initializes a new instance of the OrderService class. |
OrderService(RepositoryFactory, ILogger, IStoreSettingService, IShipmentService) | Initializes a new instance of the OrderService class. |
OrderService(IDatabaseUnitOfWorkProvider, RepositoryFactory, ILogger, IStoreSettingService, IShipmentService) | Initializes a new instance of the OrderService class. |
OrderService(IDatabaseUnitOfWorkProvider, RepositoryFactory, ILogger, IStoreSettingService, IShipmentService) | Initializes a new instance of the OrderService class. |
Public Methods
Name | Description |
---|---|
CreateOrder(Guid, Guid, Boolean) | Creates a IOrder without saving it to the database |
CreateOrder(Guid, Guid, Int32, Boolean) | Creates a IOrder without saving it to the database |
CreateOrderWithKey | Creates a IOrder and saves it to the database |
Delete(IOrder, Boolean) | Deletes a single IOrder |
Delete(IEnumerable(IOrder), Boolean) | Deletes a collection IOrder |
GetAllOrderStatuses | Returns a collection of all IOrderStatus |
GetByKey | Gets a IOrder given it's unique 'key' (GUID) |
GetByKeys | Gets list of IOrder objects given a list of Keys |
GetByOrderNumber | Gets a IOrder given it's unique 'OrderNumber' |
GetOrdersByInvoiceKey | Gets a collection of IOrder for a given IInvoice key |
GetOrderStatusByKey | Gets an IOrderStatus by it's key |
GetPage(Int64, Int64, String, SortDirection) | Gets a Page of IOrder |
Save(IOrder, Boolean) | Saves a single IOrder |
Save(IEnumerable(IOrder), Boolean) | Saves a collection of IOrder |
Events
You can hook into the events just like you can do with Umbraco events using the 'ApplicationEventHandler'.
Override the 'void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)' method and from here we can hook into any of the events below.
A common example would be the StatusChanged event, where people want to call third party services once an order is completed.
To listen for this event, in the ApplicationStarting method write the following
OrderService.StatusChanged += OrderServiceOnStatusChanged;
Now we need to create the OrderServiceOnStatusChanged method like so
private static void OrderServiceOnStatusChanged(IOrderService sender, StatusChangeEventArgs<IOrder> statusChangeEventArgs)
{
foreach (var order in statusChangeEventArgs.StatusChangedEntities)
{
// Do what you want here
}
}
Name | Description |
---|---|
Creating | Occurs before create |
Created | Occurs after create |
Deleting | Occurs before delete |
Deleted | Occurs after delete |
Saving | Occurs before save |
Saved | Occurs after save |
StatusChanging | Occurs before order status change |
StatusChanged | Occurs after order status change |
Interface on GitHub
Updated less than a minute ago