Guides

ProductService

Documentation for Merch's ProductService

The ProductService is used to manage products in the back office product catalog.

Instantiating

The ProductService is exposed through the MerchelloContext

var productService = MerchelloContext.Current.Services.ProductService;

Class

public class ProductService : PageCachedServiceBase<IProduct>, 
	IProductService, IStaticCollectionService<IProduct>, IPageCachedService<IProduct>, 
	IService

Constructors

NameDescription
ProductService()Initializes a new instance of the ProductService class
ProductService(ILogger)Initializes a new instance of the ProductService class
ProductService(RepositoryFactory, ILogger, IProductVariantService)Initializes a new instance of the ProductService class
ProductService(IDatabaseUnitOfWorkProvider, RepositoryFactory, ILogger, IProductVariantService)Initializes a new instance of the ProductService class
ProductService(IDatabaseUnitOfWorkProvider, RepositoryFactory, ILogger, IEventMessagesFactory, IProductVariantService)Initializes a new instance of the ProductService class

Public Methods

NameDescription
AddToCollection(Guid, Guid)Adds a product to a collection
AddToCollection(IProduct, IEntityCollection)Adds a product to a collection
AddToCollection(IProduct, Guid)Adds a product to a collection
CreateProductCreates a Product without saving it to the database
CreateProductWithKeyCreates and saves a IProduct to the database
Delete(IProduct, Boolean)Deletes a single IProduct
Delete(IEnumerable(IProduct), Boolean)Deletes a collection IProduct
ExistsInCollectionReturns a value indicating whether or not a product exists in a colleciton
GetAllGets all the products
GetByDetachedContentTypeGets a collect of products by detached content type
GetByKeyGets a Product by its unique id - primary key
GetByKeysGets a list of Product give a list of unique keys
GetBySkuGets an IProduct by it's unique SKU.
GetFromCollection(Guid, Int64, Int64, String, SortDirection)Gets products from a collection.
GetFromCollection(Guid, String, Int64, Int64, String, SortDirection)Gets products from a collection filtered by a search term.
GetPageGets a page of IProduct
GetProductVariantByKeyGets a IProductVariant by it's key.
GetProductVariantBySkuGet's a IProductVariant by it's unique SKU.
GetProductVariantsByProductKeyGets a collection of IProductVariant by product.
ProductsCountObsolete. Returns the count of all products
RemoveDetachedContent(IProduct, Guid, Boolean)Removes detached content from the collection of products
RemoveDetachedContent(IEnumerable(IProduct), Guid, Boolean)Removes detached content from the collection of products
RemoveFromCollection(Guid, Guid)Remove product from a collection
RemoveFromCollection(Guid, Guid)Remove product from a collection
RemoveFromCollection(IProduct, Guid)Remove product from a collection
Save(IProduct, Boolean)Saves a collection of IProduct
Save(IEnumerable(IProduct), Boolean)Saves a collection of IProduct

Events

NameDescription
CreatingOccurs before create
CreatedOccurs after create
DeletingOccurs before delete
DeletedOccurs after delete
SavingOccurs before save
SavedOccurs after save

Example of using the Saved event (Events must be added to the ApplicationStarting event)

ProductService.Saved += ProductServiceSaved;

Then the method

private static void ProductServiceSaved(IProductService sender, SaveEventArgs<IProduct> e)
        {
            foreach (var p in e.SavedEntities)
            {
                // do what you want
            }
        }

Interface on GitHub

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