ProductService
Constructors
constructor
**new ProductService**(«destructured»)
Parameters
Properties
__configModule__
Record<string, unknown>__container__
anyRequired__moduleDeclaration__
Record<string, unknown>imageRepository_
Repository<Image> & { insertBulk: Method insertBulk ; upsertImages: Method upsertImages }Requiredmanager_
EntityManagerRequiredproductCategoryRepository_
TreeRepository<ProductCategory> & { addProducts: Method addProducts ; findOneWithDescendants: Method findOneWithDescendants ; getFreeTextSearchResultsAndCount: Method getFreeTextSearchResultsAndCount ; removeProducts: Method removeProducts }RequiredproductRepository_
Repository<Product> & { _applyCategoriesQuery: Method _applyCategoriesQuery ; _findWithRelations: Method _findWithRelations ; bulkAddToCollection: Method bulkAddToCollection ; bulkRemoveFromCollection: Method bulkRemoveFromCollection ; findOneWithRelations: Method findOneWithRelations ; findWithRelations: Method findWithRelations ; findWithRelationsAndCount: Method findWithRelationsAndCount ; getCategoryIdsFromInput: Method getCategoryIdsFromInput ; getCategoryIdsRecursively: Method getCategoryIdsRecursively ; getFreeTextSearchResultsAndCount: Method getFreeTextSearchResultsAndCount ; isProductInSalesChannels: Method isProductInSalesChannels ; queryProducts: Method queryProducts ; queryProductsWithIds: Method queryProductsWithIds }RequiredproductTagRepository_
Repository<ProductTag> & { findAndCountByDiscountConditionId: Method findAndCountByDiscountConditionId ; insertBulk: Method insertBulk ; listTagsByUsage: Method listTagsByUsage ; upsertTags: Method upsertTags }RequiredproductTypeRepository_
Repository<ProductType> & { findAndCountByDiscountConditionId: Method findAndCountByDiscountConditionId ; upsertType: Method upsertType }RequiredtransactionManager_
undefined | EntityManagerRequiredEvents
objectRequiredEvents.CREATED
stringRequiredDefault: "product.created"
Events.DELETED
stringRequiredDefault: "product.deleted"
Events.UPDATED
stringRequiredDefault: "product.updated"
IndexName
"products"RequiredAccessors
activeManager_
Protected get**activeManager_**(): EntityManager
Returns
EntityManager
EntityManager
EntityManagerRequiredMethods
addOption
**addOption**(productId, optionTitle): Promise<[Product](/references/services/classes/Product)>
Adds an option to a product. Options can, for example, be "Size", "Color", etc. Will update all the products variants with a dummy value for the newly created option. The same option cannot be added more than once.
Parameters
productId
stringRequiredoptionTitle
stringRequiredReturns
Promise<Product>
atomicPhase_
Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise<TResult>
Wraps some work within a transactional block. If the service already has a transaction manager attached this will be reused, otherwise a new transaction manager is created.
TResult
objectRequiredTError
objectRequiredParameters
work
(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandler
IsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail
(error: TError) => Promise<void | TResult>Returns
Promise<TResult>
Promise
Promise<TResult>Requiredcount
**count**(selector?): Promise<number>
Return the total number of documents in database
Parameters
Returns
Promise<number>
Promise
Promise<number>Requiredcreate
**create**(productObject): Promise<[Product](/references/services/classes/Product)>
Creates a product.
Parameters
Returns
Promise<Product>
delete
**delete**(productId): Promise<void>
Deletes a product from a given product id. The product's associated variants will also be deleted.
Parameters
productId
stringRequiredReturns
Promise<void>
Promise
Promise<void>RequireddeleteOption
**deleteOption**(productId, optionId): Promise<void \| [Product](/references/services/classes/Product)>
Delete an option from a product.
Parameters
productId
stringRequiredoptionId
stringRequiredReturns
Promise<void | Product>
filterProductsBySalesChannel
**filterProductsBySalesChannel**(productIds, salesChannelId, config?): Promise<[Product](/references/services/classes/Product)[]>
Parameters
Returns
Promise<Product[]>
isProductInSalesChannels
**isProductInSalesChannels**(id, salesChannelIds): Promise<boolean>
Check if the product is assigned to at least one of the provided sales channels.
Parameters
id
stringRequiredsalesChannelIds
string[]RequiredReturns
Promise<boolean>
Promise
Promise<boolean>Requiredlist
**list**(selector, config?): Promise<[Product](/references/services/classes/Product)[]>
Lists products based on the provided parameters.
Parameters
Returns
Promise<Product[]>
listAndCount
**listAndCount**(selector, config?): Promise<[[Product](/references/services/classes/Product)[], number]>
Lists products based on the provided parameters and includes the count of products that match the query.
Parameters
Returns
Promise<[Product[], number]>
listTagsByUsage
**listTagsByUsage**(take?): Promise<[ProductTag](/references/services/classes/ProductTag)[]>
Parameters
take
numberRequiredDefault: 10
Returns
Promise<ProductTag[]>
listTypes
**listTypes**(): Promise<[ProductType](/references/services/classes/ProductType)[]>
Returns
Promise<ProductType[]>
prepareListQuery_
Protected **prepareListQuery_**(selector, config): { q: string ; query: [FindWithoutRelationsOptions](/references/services/types/FindWithoutRelationsOptions-1) ; relations: keyof [Product](/references/services/classes/Product)[] }
Temporary method to be used in place we need custom query strategy to prevent typeorm bug
Parameters
Returns
object
object
objectreorderVariants
**reorderVariants**(productId, variantOrder): Promise<[Product](/references/services/classes/Product)>
Parameters
productId
stringRequiredvariantOrder
string[]RequiredReturns
Promise<Product>
retrieve
**retrieve**(productId, config?): Promise<[Product](/references/services/classes/Product)>
Gets a product by id. Throws in case of DB Error and if product was not found.
Parameters
productId
stringRequiredReturns
Promise<Product>