Skip to main content
Skip to main content

upsert - Product Module Reference

This documentation provides a reference to the upsert method. This belongs to the Product Module.

upsert(data, sharedContext?): Promise<ProductDTO[]>

This method updates existing products, or creates new ones if they don't exist.

Example

const products = await productModuleService.upsert([
{
id: "prod_123",
handle: "pant",
},
{
title: "Shirt",
},
])

Parameters

dataUpsertProductDTO[]Required
The attributes to update or create for each product.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<ProductDTO[]>Required
The updated and created products.

upsert(data, sharedContext?): Promise<ProductDTO>

This method updates the product if it exists, or creates a new ones if it doesn't.

Example

const product = await productModuleService.upsert({
title: "Shirt",
})

Parameters

dataUpsertProductDTORequired
The attributes to update or create for the new product.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<ProductDTO>Required
The updated or created product.
Was this section helpful?