ProductService
internal.internal.ProductService
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 | EntityManagerRequiredEventsobjectRequiredEvents.CREATEDstringRequiredEvents.DELETEDstringRequiredEvents.UPDATEDstringRequiredIndexName"products"RequiredDefault: `"products"`
Accessors
activeManager_
Protected get activeManager_(): EntityManager
Returns
EntityManager
EntityManagerEntityManagerRequiredInherited from
TransactionBaseService.activeManager_
Methods
addOption
addOption(productId, optionTitle): Promise<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
productIdstringRequiredoptionTitlestringRequiredReturns
Promise<Product>
the result of the model update operation
atomicPhase_
Protected atomicPhase_<TResult, 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.
TResultobjectRequiredTErrorobjectRequiredParameters
work(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>Returns
Promise<TResult>
PromisePromise<TResult>RequiredInherited from
TransactionBaseService.atomicPhase_
count
count(selector?): Promise<number>
Return the total number of documents in database
Parameters
Returns
Promise<number>
PromisePromise<number>Requiredthe result of the count operation
PromisePromise<number>Requiredcreate
create(productObject): Promise<Product>
Creates a product.
Parameters
Returns
Promise<Product>
resolves to the creation result.
delete
delete(productId): Promise<void>
Deletes a product from a given product id. The product's associated variants will also be deleted.
Parameters
productIdstringRequiredReturns
Promise<void>
PromisePromise<void>RequireddeleteOption
deleteOption(productId, optionId): Promise<void | Product>
Delete an option from a product.
Parameters
productIdstringRequiredoptionIdstringRequiredReturns
Promise<void | Product>
the updated product
filterProductsBySalesChannel
filterProductsBySalesChannel(productIds, salesChannelId, config?): Promise<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
idstringRequiredsalesChannelIdsstring[]RequiredReturns
Promise<boolean>
PromisePromise<boolean>Required
PromisePromise<boolean>Requiredlist
list(selector, config?): Promise<Product[]>
Lists products based on the provided parameters.
Parameters
configFindProductConfigReturns
Promise<Product[]>
the result of the find operation
listAndCount
listAndCount(selector, config?): Promise<[Product[], number]>
Lists products based on the provided parameters and includes the count of products that match the query.
Parameters
configFindProductConfigReturns
Promise<[Product[], number]>
an array containing the products as
the first element and the total count of products that matches the query
as the second element.
listTagsByUsage
listTagsByUsage(take?): Promise<ProductTag[]>
Parameters
takenumberReturns
Promise<ProductTag[]>
listTypes
listTypes(): Promise<ProductType[]>
Returns
Promise<ProductType[]>
prepareListQuery_
Protected prepareListQuery_(selector, config): { q: string ; query: FindWithoutRelationsOptions ; relations: keyof 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>
Parameters
productIdstringRequiredvariantOrderstring[]RequiredReturns
Promise<Product>
retrieve
retrieve(productId, config?): Promise<Product>
Gets a product by id. Throws in case of DB Error and if product was not found.
Parameters
productIdstringRequiredconfigFindProductConfigReturns
Promise<Product>
the result of the find one operation.
retrieveByExternalId
retrieveByExternalId(externalId, config?): Promise<Product>
Gets a product by external id. Throws in case of DB Error and if product was not found.
Parameters
externalIdstringRequiredconfigFindProductConfigReturns
Promise<Product>
the result of the find one operation.
retrieveByHandle
retrieveByHandle(productHandle, config?): Promise<Product>
Gets a product by handle. Throws in case of DB Error and if product was not found.
Parameters
productHandlestringRequiredconfigFindProductConfigReturns
Promise<Product>
the result of the find one operation.
retrieveOptionByTitle
retrieveOptionByTitle(title, productId): Promise<null | ProductOption>
Retrieve product's option by title.
Parameters
titlestringRequiredproductIdstringRequiredReturns
Promise<null | ProductOption>
product option
retrieveVariants
retrieveVariants(productId, config?): Promise<ProductVariant[]>
Gets all variants belonging to a product.
Parameters
productIdstringRequiredconfigFindProductConfigReturns
Promise<ProductVariant[]>
an array of variants
retrieve_
retrieve_(selector, config?): Promise<Product>
Gets a product by selector. Throws in case of DB Error and if product was not found.
Parameters
configFindProductConfigReturns
Promise<Product>
the result of the find one operation.
shouldRetryTransaction_
Protected shouldRetryTransaction_(err): boolean
Parameters
errRecord<string, unknown> | { code: string }RequiredReturns
boolean
booleanbooleanInherited from
TransactionBaseService.shouldRetryTransaction_
update
update(productId, update): Promise<Product>
Updates a product. Product variant updates should use dedicated methods,
e.g. addVariant, etc. The function will throw errors if metadata or
product variant updates are attempted.
Parameters
productIdstringRequiredReturns
Promise<Product>
resolves to the update result.
updateOption
updateOption(productId, optionId, data): Promise<Product>
Updates a product's option. Throws if the call tries to update an option not associated with the product. Throws if the updated title already exists.
Parameters
productIdstringRequiredoptionIdstringRequiredReturns
Promise<Product>
the updated product
updateShippingProfile
updateShippingProfile(productIds, profileId): Promise<Product[]>
Assign a product to a profile, if a profile id null is provided then detach the product from the profile
Parameters
productIdsstring | string[]RequiredprofileIdnull | stringRequiredReturns
Promise<Product[]>
updated products
withTransaction
withTransaction(transactionManager?): ProductService
Parameters
transactionManagerEntityManager