Methods/Products

Methods/Products

Source:

Methods for Products. Run these methods using Meteor.call().

Methods

(static) products/archiveProduct(productId) → {Number}

archive a product and unlink it from all media

Source:
Parameters:
Name Type Description
productId String

productId to delete

Returns:

returns number of removed products

Type
Number

(static) products/cloneProduct(productOrArray) → {Array}

clone a whole product, defaulting visibility, etc in the future we are going to do an inheritance product that maintains relationships with the cloned product tree

Source:
Parameters:
Name Type Description
productOrArray Array

products array to clone

Returns:

returns insert results

Type
Array

(static) products/cloneVariant(productId, variantId) → {Array}

clones a product variant into a new variant

Source:
To Do:
  • rewrite @description

the method copies variants, but will also create and clone child variants (options)

Parameters:
Name Type Description
productId String

the productId we're whose variant we're cloning

variantId String

the variantId that we're cloning

Returns:
  • list with cloned variants _ids
Type
Array

(static) products/createProduct(productopt) → {String}

when we create a new product, we create it with an empty variant. all products have a variant with pricing and details

Source:
Parameters:
Name Type Attributes Description
product Object <optional>

optional product object

Returns:

The new product ID

Type
String

(static) products/createVariant(parentId, newVariantopt) → {String}

initializes empty variant template

Source:
Parameters:
Name Type Attributes Description
parentId String

the product _id or top level variant _id where we create variant

newVariant Object <optional>

variant object

Returns:

new variantId

Type
String

(static) products/deleteVariant(variantId) → {Boolean}

delete variant, which should also delete child variants

Source:
Parameters:
Name Type Description
variantId String

variantId to delete

Returns:

returns update results: true - if at least one variant was removed or false if nothing was removed

Type
Boolean

(static) products/getpublishedProductHash(productId) → {String}

hashes product information for comparison purposes

Source:
Parameters:
Name Type Description
productId String

the product _id of the product to hash

Returns:

hash of product

Type
String

(static) products/publishProduct(productId) → {Boolean}

publish (visibility) of product

Source:
To Do:
  • hook into publishing flow
Parameters:
Name Type Description
productId String

productId

Returns:

product.isVisible

Type
Boolean

(static) products/removeMetaFields(productId, metafields, type) → {Number}

update product metafield

Source:
Parameters:
Name Type Description
productId String

productId

metafields Object

metadata object to remove

type Object

optional product type for schema selection

Returns:

collection update result

Type
Number

(static) products/removeProductTag(productId, tagId) → {String}

method to remove tag from product

Source:
Parameters:
Name Type Description
productId String

productId

tagId String

tagId

Returns:

return update result

Type
String

(static) products/setHandle(productId) → {String}

copy of "products/setHandleTag", but without tag

Source:
Parameters:
Name Type Description
productId String

productId

Returns:

handle - product handle

Type
String

(static) products/setHandleTag(productId, tagId) → {String}

set or toggle product handle

Source:
Parameters:
Name Type Description
productId String

productId

tagId String

tagId

Returns:

return update result

Type
String

(static) products/toggleVisibility(productId) → {Boolean}

publish (visibility) of product

Source:
To Do:
  • hook into publishing flow
Parameters:
Name Type Description
productId String

productId

Returns:

product.isVisible

Type
Boolean

(static) products/updateMetaFields(productId, updatedMeta, meta) → {Number}

update product metafield

Source:
To Do:
  • should this method works for variants also?
Parameters:
Name Type Description
productId String

productId

updatedMeta Object

update object with metadata

meta Object | Number | undefined | null

current meta object, or a number index

Returns:

collection update result

Type
Number

(static) products/updateProductField(_id, field, value) → {Number}

update single product or variant field

Source:
To Do:
  • rename it to something like "products/updateField" to reflect
  • we need to know which type of entity field belongs. For that we could do something like: const type = Products.findOne(_id).type or transmit type as param if it possible latest changes. its used for products and variants
Parameters:
Name Type Description
_id String

product._id or variant._id to update

field String

key to update

value *

update property value

Returns:

returns update result

Type
Number

(static) products/updateProductTags(productId, tagName, tagId) → {Number}

method to insert or update tag with hierarchy

Source:
Parameters:
Name Type Description
productId String

productId

tagName String

tagName

tagId String

tagId

Returns:

return result

Type
Number

(static) products/updateVariant(variant) → {Number}

update individual variant with new values, merges into original only need to supply updated information. Currently used for a one use case

  • to manage top-level variant autoform.

Source:
To Do:
  • some use cases of this method was moved to "products/ updateProductField", but it still used
Parameters:
Name Type Description
variant Object

current variant object

Returns:

returns update result

Type
Number

(static) products/updateVariantsPosition(sortedVariantIds) → {Number}

updates top level variant position index

.

Source:
Since:
  • 0.11.0

updates top level variant position index

Parameters:
Name Type Description
sortedVariantIds Array

array of top level variant _ids

Returns:

Products.update result

Type
Number