ProductService
constructor
Parameters
__namedParameters
InjectedDependenciesRequiredProperties
manager_
EntityManagerRequiredtransactionManager_
undefined | EntityManagerRequired__container__
anyRequiredfeatureFlagRouter_
FlagRouterRequiredIndexName
"products"RequiredEvents
objectRequiredEvents.UPDATED
stringRequiredDefault: "product.updated"
Events.CREATED
stringRequiredDefault: "product.created"
Events.DELETED
stringRequiredDefault: "product.deleted"
__configModule__
Record<string, unknown>__moduleDeclaration__
Record<string, unknown>Accessors
activeManager_
Returns
EntityManager
EntityManagerRequiredMethods
withTransaction
Parameters
transactionManager
EntityManagerReturns
this
thisRequiredshouldRetryTransaction_
Parameters
err
Record<string, unknown> | objectRequiredReturns
boolean
booleanRequiredatomicPhase_
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
TResult
objectRequiredTError
objectRequiredParameters
work
(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandler
IsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail
(error: TError) => Promise<void | TResult>Returns
Promise
Promise<TResult>Requiredlist
Lists products based on the provided parameters.
Parameters
selector
ProductSelectorRequiredconfig
FindProductConfigRequiredReturns
listAndCount
Lists products based on the provided parameters and includes the count of products that match the query.
Parameters
selector
ProductSelectorRequiredconfig
FindProductConfigRequiredReturns
count
Return the total number of documents in database
Parameters
Returns
Promise
Promise<number>Requiredretrieve
Gets a product by id. Throws in case of DB Error and if product was not found.
Parameters
productId
stringRequiredconfig
FindProductConfigRequiredReturns
retrieveByHandle
Gets a product by handle. Throws in case of DB Error and if product was not found.
Parameters
productHandle
stringRequiredconfig
FindProductConfigRequiredDefault: {}
Returns
retrieveByExternalId
Gets a product by external id. Throws in case of DB Error and if product was not found.
Parameters
externalId
stringRequiredconfig
FindProductConfigRequiredDefault: {}
Returns
retrieve_
Gets a product by selector. Throws in case of DB Error and if product was not found.
Parameters
Returns
retrieveVariants
Gets all variants belonging to a product.
Parameters
productId
stringRequiredconfig
FindProductConfigRequiredReturns
filterProductsBySalesChannel
Parameters
productIds
string[]RequiredsalesChannelId
stringRequiredconfig
FindProductConfigRequiredReturns
listTypes
Returns
listTagsByUsage
Parameters
take
numberRequiredDefault: 10
Returns
isProductInSalesChannels
Check if the product is assigned to at least one of the provided sales channels.
Parameters
id
stringRequiredsalesChannelIds
string[]RequiredReturns
Promise
Promise<boolean>Requiredcreate
Creates a product.
Parameters
productObject
CreateProductInputRequiredReturns
update
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
productId
stringRequiredupdate
UpdateProductInputRequiredReturns
delete
Deletes a product from a given product id. The product's associated variants will also be deleted.
Parameters
productId
stringRequiredReturns
Promise
Promise<void>RequiredaddOption
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
reorderVariants
Parameters
productId
stringRequiredvariantOrder
string[]RequiredReturns
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
productId
stringRequiredoptionId
stringRequireddata
ProductOptionInputRequiredReturns
retrieveOptionByTitle
Retrieve product's option by title.
Parameters
title
stringRequiredproductId
stringRequiredReturns
deleteOption
Delete an option from a product.
Parameters
productId
stringRequiredoptionId
stringRequiredReturns
updateShippingProfile
Assign a product to a profile, if a profile id null is provided then detach the product from the profile
Parameters
productIds
string | string[]RequiredprofileId
null | stringRequiredReturns
prepareListQuery_
Temporary method to be used in place we need custom query strategy to prevent typeorm bug
Parameters
config
FindProductConfigRequiredReturns
decorateProductsWithSalesChannels
Temporary method to join sales channels of a product using RemoteQuery while MedusaV2 FF is on.
Parameters
Returns
getSalesChannelModuleChannels
Temporary method to fetch sales channels of a product using RemoteQuery while MedusaV2 FF is on.
Parameters
productIds
string[]Required