Documentation for the MerchelloContext

The MerchelloContext is a singleton instantiated during the application startup.

In some ways the MerchelloContext is analogous to Umbraco's ApplicationContext but with respect to the Merchello package.

It provides access to Merchello Services, Gateways and Cache.



Merchello's cache is Umbraco's cache: `ApplicationContext.Current.ApplicationCache'. The association is stored within the MerchelloContext mainly for control during testing.


The current instance of the MerchelloContext can be accessed through static Current property.

var merchelloContext = MerchelloContext.Current;


Public services accessible via the ServiceContext

var services = MerchelloContext.Current.Services;

// example for the customer service

var customerService = MerchelloContext.Current.Services.CustomerService;

ServiceContext Properties

AuditLogServiceThe AuditLogService is intended to be used to log Merchello related informational records that would not otherwise be normally recorded in an application's generic logging system.
CustomerServiceThe CustomerService is used to manage Merchello customers
EntityCollectionServiceThis service is used to manage entity collections. Both Static and Dynamic Collections are managed with the EntityCollectionService .
GatewayProviderServiceThe GatewayProviderService allows you to get to the gateways in Merchello. Gateways.
InvoiceServiceThe InvoiceService allows you to manage invoices.
ItemCacheServiceThe ItemCacheService is used to manage ItemCache collections such as those in the Basket , Wishlist and SalePreparation objects.
OrderServiceThe OrderService manages items that need to be shipped and fulfilled from a warehouse.
PaymentServiceThe PaymentService is used manage payments.
StoreSettingServiceThe StoreSettingService manage global store settings, currency, currency formats, country and regional settings.
ProductServiceThe ProductService is used to manage products in the back office product catalog.
ShipmentServiceThe ShipmentService is used to manage shipments in Merch.


var gatewayContext = MerchelloContext.Current.Gateways;



The NotificationContext is responsible for passing notification message to any NotificationGatewayProviders configured in the back office.

var notificationContext = MerchelloContext.Current.Gateways.Notification;


GetNotificationMessagesByMonitorKey(Guid monitorKey)Gets a collection of INotificationMessage s by a Monitor Key (Guid)
Send(INotificationMessage message)Sends a INotificationMessage
Send(INotificationMessage message, IFormatter formatter);Sends a INotificationMessage with a designated formatter



The PaymentContent is responsible for managing payment methods across multiple PaymentGatewayProvider(s) configured in the back office.

var paymentContext = MerchelloContext.Current.Gateways.Payment;


GetPaymentGatewayMethods()Gets a list of all possible Payment Methods
GetPaymentGatewayMethodByKey(Guid paymentMethodKey)Gets a IPaymentGatewayMethod by its unique key



The ShippingContext is responsible for getting shipment (freight) rate quotes across all qualifying ShippingGatewayProvider methods for a given shipping destination - determined by shipping destination country.

var shippingContext = MerchelloContext.Current.Gateways.Shipping;


GetShipRateQuotesForShipment(IShipment shipment, bool tryGetCached = true)Returns a collection of all IShipmentRateQuote that are available for the IShipment
GetAllowedShipmentDestinationCountries()Returns a list of all countries that can be assigned to a shipment
GetGatewayProvidersByShipCountry(IShipCountry shipCountry)Gets a collection of ShippingGatewayProviders for a particular ship country



The TaxationContext is responsible for providing taxation calculation for either an invoice or product based taxation.

var taxationContext = MerchelloContext.Current.Gateways.Taxation;


ProductPricingEnabledReturns a value indicating whether the product based tax pricing is enabled. (Set in the back office)
TaxationApplicationReturns an enum value - Invoice or Product


CalculateTaxesForInvoice(IInvoice invoice, bool quoteOnly = false)Calculates taxes for an invoice.
CalculateTaxesForInvoice(IInvoice invoice, IAddress taxAddress, bool quoteOnly = false)Calculates taxes for an invoice.
CalculateTaxesForProduct(IProductVariantDataModifierData product)Calculate taxes for a product when product based taxation is enabled.
GetTaxMethodForTaxAddress(IAddress taxAddress)Gets the tax method for a given tax address
GetTaxMethodForCountryCode(string countryCode)Gets the tax method for country code.