Catalog

Catalog

Source:

Catalog methods

Methods

(static) createCatalogProduct(product, context) → {boolean}

Publish a product to the Catalog collection

Source:
Parameters:
Name Type Description
product Object

A product object

context Object

The app context

Returns:

true on successful publish, false if publish was unsuccessful

Type
boolean

(static) createProductHash(product, collections) → {String}

Create a hash of a product to compare for updates

Source:
Parameters:
Name Type Description
product String

The Product document to hash. Expected to be a top-level product, not a variant

collections Object

Raw mongo collections

Returns:

product hash

Type
String

(static) createProductHash(product) → {String}

Create a hash of a product to compare for updates

Source:
Parameters:
Name Type Description
product String

The Product document to hash

Returns:

product hash

Type
String

(static) getProductPriceRange(productIdopt) → {Object}

get price range of a product if only one price available, return it otherwise return a string range

Source:
To Do:
  • move all this methods this to export function after 1.3
Parameters:
Name Type Attributes Description
productId String <optional>

current product _id

Returns:

range, min, max

Type
Object

(static) getProductQuantity(variant, variants) → {number}

Get the number of product variants still avalible to purchase. This function can take only a top level variant object as a param to return the product's quantity. This method can also take a top level variant and an array of product variant options as params return the product's quantity.

Source:
Parameters:
Name Type Description
variant Object

A top level product variant object.

variants Array.<Object>

Array of product variant option objects.

Returns:

Variant quantity

Type
number

(static) getTopVariants(idopt) → {Array}

Get only product top level variants

.

Source:

Get only product top level variants

Parameters:
Name Type Attributes Description
id String <optional>

product _id

Returns:

Product top level variants or empty array

Type
Array

(static) getVariantPriceRange(variantIdopt) → {String}

get price range of a variant if it has child options. if no child options, return main price value

Source:
To Do:
  • remove string return and replace with object
Parameters:
Name Type Attributes Description
variantId String <optional>

current variant _Id

Returns:

formatted price or price range

Type
String

(static) getVariantQuantity(variant) → {Number}

calculate a sum of descendants inventoryQuantity

.

Source:

calculate a sum of descendants inventoryQuantity

Parameters:
Name Type Description
variant Object

top-level variant

Returns:

summary of options quantity

Type
Number

(static) getVariants(idopt, typeopt) → {Array}

could be useful for products and for top level variants

Source:

Get all parent variants

Parameters:
Name Type Attributes Description
id String <optional>

product _id

type String <optional>

type of variant

Returns:

Parent variants or empty array

Type
Array

(static) hashProduct(productId, collections, isPublished) → {Object}

Create a hash of a product to compare for updates

Source:
Parameters:
Name Type Description
productId String

A productId

collections Object

Raw mongo collections

isPublished Boolean

Is product published to catalog

Returns:

updated product if successful, original product if unsuccessful

Type
Object

(static) hashProduct(productId, collections, isPublished) → {Object}

Create a hash of a product to compare for updates

Source:
Parameters:
Name Type Description
productId String

A productId

collections Object

Raw mongo collections

isPublished Boolean

Is product published to catalog

Returns:

updated product if successful, original product if unsuccessful

Type
Object

(static) isBackorder(variants) → {boolean}

If all the products variants have inventory policy disabled, inventory management enabled and a quantity of zero return true

Source:
Parameters:
Name Type Description
variants Array.<Object>

Array with product variant objects

Returns:

is backorder allowed or not for a product

Type
boolean

(static) isLowQuantity(variants) → {boolean}

If at least one of the product variants quantity is less than the low inventory threshold return true.

Source:
Parameters:
Name Type Description
variants Array.<Object>

Array of child variants

Returns:

low quantity or not

Type
boolean

(static) isSoldOut(variants) → {Boolean}

If all the product variants have a quantity of 0 return true.

Source:
Parameters:
Name Type Description
variants Array.<Object>

Array with top-level variants

Returns:

true if quantity is zero.

Type
Boolean

(static) publishProductsToCatalog(productIds, context) → {boolean}

Publish one or more products to the Catalog

Source:
Parameters:
Name Type Description
productIds Array

An array of product IDs. Must be top-level products.

context Object

The app context

Returns:

true on successful publish for all documents, false if one ore more fail to publish

Type
boolean

(static) publishProductToCatalog(product, context) → {boolean}

Publish a product to the Catalog collection

Source:
Parameters:
Name Type Description
product Object

A product object

context Object

The app context

Returns:

true on successful publish, false if publish was unsuccessful

Type
boolean

(static) publishProductToCatalogById(productId, context) → {boolean}

Publish a product to the Catalog by ID

Source:
Parameters:
Name Type Description
productId string

A product ID. Must be a top-level product.

context Object

The app context

Returns:

true on successful publish, false if publish was unsuccessful

Type
boolean

(static) updateCatalogProductInventoryStatus(productId, collections) → {Promise.<boolean>}

Update inventory status for a single Catalog Product.

Source:
Parameters:
Name Type Description
productId string

A string product id

collections Object

Raw mongo collections

Returns:

true on success, false on failure

Type
Promise.<boolean>