Product Factory

Product factory provides builder methods to help you create Firework product objects from any third-party format. Firework product objects are required for Product Hydration and Cart Sync.

Create a product

NameDescriptionRequired

extId

External ID in a partner database. It is used to match and update products synced with Firework.

Yes

name

Product name

Yes

description

Product description. Markdown for rich formating is allowed.

Yes

currency

Currency code. e.g. "USD".

Yes

variant

Variant factory, see below.

Yes, at least one variant should exist in a product

Sample Code

window._fwn.shopping.productFactory((builder) => {
  builder
    .description(remoteProduct.description)
    .extId(remoteProduct.id)
    .name(remoteProduct.title)
    .currency('USD')
    .variant((variantBuilder) => {
      // See "Create a variant" section.
    })
})

Create a variant (product unit)

Every product can have one or more variants. For example, a product may come in different sizes or colors. Please note each product needs at least one variant.

NameDescriptionRequired

extId

External variant ID in a partner database. It is used to match and update product variants synced with Firework.

Yes

url

URL to product/variant detail page.

Yes

price

Numeric value of current price

Yes

sku

SKU identifier.

Optional

name

Variant name.

Optional

originalPrice

Numeric value of original price

Optional

isAvailable

Boolean indicating whether variant is currently available (out of stock).

Optional

image

Image factory, see below.

Optional

option

Variant option. Accepts {name, value} object (e.g {name: 'Size', value: 'Large'})

Optional

position

Numeric position amongst other variants. Variant options will also be sorted by this position.

Optional

productbuilder.variant((variantBuilder) => {
  variantBuilder
    .extId(remoteVariant.id)
    .url('https://www.example.com')
    .price(remoteVariant.price)
    .sku(remoteVariant.sku)
    .name(remoteVariant.name)    
    .isAvailable(remoteVariant.isAvailable)
    .image((imageBuilder) => {
      // See "Create an image" section
    })
  remoteVariant.options.forEach(({name, value}) => {
    variantBuilder.option({
      name,
      value,
    })
  })
})

To update the default pricing, a variant must be hydrated that matches the existing unit_id

Create an image

NameDescriptionRequired

extId

External image ID in partner database. It is used to match images between the partner and the Firework database.

Yes

url

URL location of an image.

Yes

title

Alt title for an image.

Optional

position

Numeric value used to sort multiple images.

Optional

primary

Boolean to set an image as primary

Optional

variantBuilder
  .image((imageBuilder) => {
    imageBuilder
      .extId(remoteVariant.featured_image.id)
      .position(remoteVariant.featured_image.position)
      .title(remoteVariant.featured_image.alt)
      .url(remoteVariant.featured_image.src)
  })

Last updated