Guides

OrderService

The Order service manages items that need to be shipped and fulfilled from a warehouse.

Instantiating

The OrderService is exposed through the MerchelloContext

var orderService = MerchelloContext.Current.Services.OrderService;

Class

public class OrderService : PageCachedServiceBase<IOrder>, 
    IOrderService, IPageCachedService<IOrder>, IService

Constructors

NameDescription
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

NameDescription
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
CreateOrderWithKeyCreates a IOrder and saves it to the database
Delete(IOrder, Boolean)Deletes a single IOrder
Delete(IEnumerable(IOrder), Boolean)Deletes a collection IOrder
GetAllOrderStatusesReturns a collection of all IOrderStatus
GetByKeyGets a IOrder given it's unique 'key' (GUID)
GetByKeysGets list of IOrder objects given a list of Keys
GetByOrderNumberGets a IOrder given it's unique 'OrderNumber'
GetOrdersByInvoiceKeyGets a collection of IOrder for a given IInvoice key
GetOrderStatusByKeyGets 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
       }
}
NameDescription
CreatingOccurs before create
CreatedOccurs after create
DeletingOccurs before delete
DeletedOccurs after delete
SavingOccurs before save
SavedOccurs after save
StatusChangingOccurs before order status change
StatusChangedOccurs after order status change

Interface on GitHub

https://github.com/Merchello/Merchello/blob/master/src/Merchello.Core/Services/Interfaces/IOrderService.cs