ProductService
Documentation for Merch's ProductService
The ProductService is used to manage products in the back office product catalog.
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
Name | Description |
---|---|
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
Name | Description |
---|---|
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 |
CreateProduct | Creates a Product without saving it to the database |
CreateProductWithKey | Creates and saves a IProduct to the database |
Delete(IProduct, Boolean) | Deletes a single IProduct |
Delete(IEnumerable(IProduct), Boolean) | Deletes a collection IProduct |
ExistsInCollection | Returns a value indicating whether or not a product exists in a colleciton |
GetAll | Gets all the products |
GetByDetachedContentType | Gets a collect of products by detached content type |
GetByKey | Gets a Product by its unique id - primary key |
GetByKeys | Gets a list of Product give a list of unique keys |
GetBySku | Gets 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. |
GetPage | Gets a page of IProduct |
GetProductVariantByKey | Gets a IProductVariant by it's key. |
GetProductVariantBySku | Get's a IProductVariant by it's unique SKU. |
GetProductVariantsByProductKey | Gets a collection of IProductVariant by product. |
ProductsCount | Obsolete. 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
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 |
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
Updated less than a minute ago