ProductService
constructor
Parameters
__namedParametersInjectedDependenciesRequiredProperties
__container__anyRequiredfeatureFlagRouter_FlagRouterRequiredmanager_EntityManagerRequiredremoteQuery_RemoteQueryFunctionRequiredtransactionManager_undefined | EntityManagerRequiredEventsobjectRequiredEvents.CREATEDstringRequiredDefault: "product.created"
Events.DELETEDstringRequiredDefault: "product.deleted"
Events.UPDATEDstringRequiredDefault: "product.updated"
IndexName"products"Required__configModule__Record<string, unknown>__moduleDeclaration__Record<string, unknown>Accessors
activeManager_
Returns
EntityManagerEntityManagerRequiredMethods
addOption
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
atomicPhase_
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.
Type Parameters
TResultobjectRequiredTErrorobjectRequiredParameters
work(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>Returns
PromisePromise<TResult>Requiredcount
Return the total number of documents in database
Parameters
Returns
PromisePromise<number>Requiredcreate
Creates a product.
Parameters
productObjectCreateProductInputRequiredReturns
decorateProductsWithSalesChannels
Temporary method to join sales channels of a product using RemoteQuery while MedusaV2 FF is on.
Parameters
Returns
delete
Deletes a product from a given product id. The product's associated variants will also be deleted.
Parameters
productIdstringRequiredReturns
PromisePromise<void>RequireddeleteOption
Delete an option from a product.
Parameters
productIdstringRequiredoptionIdstringRequiredReturns
filterProductsBySalesChannel
Parameters
productIdsstring[]RequiredsalesChannelIdstringRequiredconfigFindProductConfigRequiredReturns
getSalesChannelModuleChannels
Temporary method to fetch sales channels of a product using RemoteQuery while MedusaV2 FF is on.
Parameters
productIdsstring[]RequiredReturns
isProductInSalesChannels
Check if the product is assigned to at least one of the provided sales channels.
Parameters
idstringRequiredsalesChannelIdsstring[]RequiredReturns
PromisePromise<boolean>Requiredlist
Lists products based on the provided parameters.
Parameters
selectorProductSelectorRequiredconfigFindProductConfigRequiredReturns
listAndCount
Lists products based on the provided parameters and includes the count of products that match the query.
Parameters
selectorProductSelectorRequiredconfigFindProductConfigRequiredReturns
listTagsByUsage
Parameters
takenumberRequiredDefault: 10
Returns
listTypes
Returns
prepareListQuery_
Temporary method to be used in place we need custom query strategy to prevent typeorm bug
Parameters
configFindProductConfigRequiredReturns
reorderVariants
Parameters
productIdstringRequiredvariantOrderstring[]RequiredReturns
retrieve
Gets a product by id. Throws in case of DB Error and if product was not found.
Parameters
productIdstringRequiredconfigFindProductConfigRequiredReturns
retrieveByExternalId
Gets a product by external id. Throws in case of DB Error and if product was not found.
Parameters
externalIdstringRequiredconfigFindProductConfigRequiredDefault: {}
Returns
retrieveByHandle
Gets a product by handle. Throws in case of DB Error and if product was not found.
Parameters
productHandlestringRequiredconfigFindProductConfigRequiredDefault: {}
Returns
retrieveOptionByTitle
Retrieve product's option by title.
Parameters
titlestringRequiredproductIdstringRequiredReturns
retrieveVariants
Gets all variants belonging to a product.
Parameters
productIdstringRequiredconfigFindProductConfigRequiredReturns
retrieve_
Gets a product by selector. Throws in case of DB Error and if product was not found.
Parameters
Returns
shouldRetryTransaction_
Parameters
errRecord<string, unknown> | objectRequiredReturns
booleanbooleanRequiredupdate
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
productIdstringRequiredupdateUpdateProductInputRequiredReturns
updateOption
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
productIdstringRequiredoptionIdstringRequireddataProductOptionInputRequiredReturns
updateShippingProfile
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
withTransaction
Parameters
transactionManagerEntityManagerReturns
ProductServiceobjectRequired