Skip to content

Latest commit

 

History

History
451 lines (330 loc) · 16.1 KB

ddl-tools-plugin-product.md

File metadata and controls

451 lines (330 loc) · 16.1 KB

Classes

Product

Helper class to build product objects for use in a digital data layer.

Constants

productPlugin

Plugin that adds general product-related methods and a sub-class to ddl-tools.

Typedefs

PlainProductCategory

Product categorization data.

PlainProductInfo

Standard product information.

PlainProduct

Metadata describing a product.

Product

Helper class to build product objects for use in a digital data layer.

Kind: global class

new Product([product])

Instantiates a new Product.

Param Type Description
[product] PlainProduct Data describing the product

product.setProductInfo(productInfo) ⇒ Product

Sets standard product information by replacing productInfo with the productInfo argument, destroying any existing standard product information.

Kind: instance method of Product
Returns: Product - - Self reference for chaining
See: https://www.w3.org/2013/12/ceddl-201312.pdf

Param Type Description
productInfo PlainProductInfo Standard product information

product.mergeProductInfo(productInfo) ⇒ Product

Updates standard product information by deeply merging the key/value pairs from the productInfo argument into the productInfo object, creating a new productInfo object if one did not already exist.

Kind: instance method of Product
Returns: Product - - Self reference for chaining
See: https://www.w3.org/2013/12/ceddl-201312.pdf

Param Type Description
productInfo PlainProductInfo Standard product information

product.setCategory(category) ⇒ Product

Sets product categorization data by replacing category with the category argument, destroying any existing product categorization data.

Kind: instance method of Product
Returns: Product - - Self reference for chaining
See: https://www.w3.org/2013/12/ceddl-201312.pdf

Param Type Description
category PlainProductCategory Product categorization data

product.mergeCategory(category) ⇒ Product

Updates product categorization data by deeply merging the key/value pairs from the category argument into the category object, creating a new category object if one did not already exist.

Kind: instance method of Product
Returns: Product - - Self reference for chaining
See: https://www.w3.org/2013/12/ceddl-201312.pdf

Param Type Description
category PlainProductCategory Product categorization data

product.setAttributes(attributes) ⇒ Product

Sets additional facts about the product by replacing attributes with the attributes argument, destroying any existing attributes.

Kind: instance method of Product
Returns: Product - - Self reference for chaining

Param Type Description
attributes object Additional facts about the product

product.mergeAttributes(attributes) ⇒ Product

Updates additional facts about the product by deeply merging the key/value pairs from the attributes argument into the attributes object, creating a new attributes object if one did not already exist.

Kind: instance method of Product
Returns: Product - - Self reference for chaining

Param Type Description
attributes object Additional facts about the product

product.addAttribute(name, value) ⇒ Product

Sets an additional fact about the product.

Kind: instance method of Product
Returns: Product - - Self reference for chaining

Param Type Description
name string Attribute name
value mixed Attribute value

product.setProductId(value) ⇒ Product

Sets the unique identifier of the product.

Kind: instance method of Product
Returns: Product - - Self reference for chaining

Param Type Description
value string value to set

product.setProductName(value) ⇒ Product

Sets the name of the product.

Kind: instance method of Product
Returns: Product - - Self reference for chaining

Param Type Description
value string value to set

product.setDescription(value) ⇒ Product

Sets the description of the product.

Kind: instance method of Product
Returns: Product - - Self reference for chaining

Param Type Description
value string value to set

product.setProductURL(value) ⇒ Product

Sets the URL of the product.

Kind: instance method of Product
Returns: Product - - Self reference for chaining

Param Type Description
value string value to set

product.setProductImage(value) ⇒ Product

Sets the image of the product.

Kind: instance method of Product
Returns: Product - - Self reference for chaining

Param Type Description
value string value to set

product.setProductThumbnail(value) ⇒ Product

Sets the thumbnail of the product.

Kind: instance method of Product
Returns: Product - - Self reference for chaining

Param Type Description
value string value to set

product.setManufacturer(value) ⇒ Product

Sets the manufacturer of the product.

Kind: instance method of Product
Returns: Product - - Self reference for chaining

Param Type Description
value string value to set

product.setSku(value) ⇒ Product

Sets the sku of the product.

Kind: instance method of Product
Returns: Product - - Self reference for chaining

Param Type Description
value string value to set

product.setColor(value) ⇒ Product

Sets the color of the product.

Kind: instance method of Product
Returns: Product - - Self reference for chaining

Param Type Description
value string value to set

product.setSize(value) ⇒ Product

Sets the size of the product.

Kind: instance method of Product
Returns: Product - - Self reference for chaining

Param Type Description
value string value to set

product.setPrimaryCategory(value) ⇒ Product

Sets the primary category of the product.

Kind: instance method of Product
Returns: Product - - Self reference for chaining

Param Type Description
value string value to set

product.setSubCategory(value) ⇒ Product

Sets the sub-level category of the product.

Kind: instance method of Product
Returns: Product - - Self reference for chaining

Param Type Description
value string value to set

product.setCategoryProductType(value) ⇒ Product

Sets the type of the product.

Kind: instance method of Product
Returns: Product - - Self reference for chaining

Param Type Description
value string value to set

Product.normalize(product) ⇒ PlainProduct

Transforms a plain product or a Product class instance into a plain javascript object and returns it.

Kind: static method of Product
Returns: PlainProduct - - The normalized form of the given product

Param Type Description
product PlainProduct | Product The product object to normalize

productPlugin

Plugin that adds general product-related methods and a sub-class to ddl-tools.

Kind: global constant
Example

import DDLTools from 'ddl-tools';
import DDLValidator from 'ddl-validator';
import productPlugin from 'ddl-tools-plugin-product';
import schema from './path/to/mySchema';

const ddlValidator = new DDLValidator(schema);
const ddlTools = new DDLTools(window.digitalData, ddlValidator);
ddlTools.use(productPlugin);

productPlugin.Product

The Product class.

Kind: static property of productPlugin
See: Product

productPlugin.addProduct(product) ⇒ object

Adds a product to the list of products.

Kind: static method of productPlugin
Returns: object - - Self reference for chaining

Param Type Description
product PlainProduct | Product The product to add

Example

ddlTools.addProduct({
productID: '1234a',
productName: 'Example Product',
description: 'Amazing new example product',
});

Example

const product = new ddlTools.Product();
product
.setProductId('1234a')
.setProductName('Example Product')
.setDescription('Amazing new example product');
ddlTools.addProduct(product);

PlainProductCategory

Product categorization data.

Kind: global typedef
Properties

Name Type Description
primaryCategory string Top-level category of the product
subCategory string Sub-level category of the product
productType string Type of product

PlainProductInfo

Standard product information.

Kind: global typedef
Properties

Name Type Description
productID string Unique identifier for the product
productName string Human-friendly name of the product
description string Human-friendly product description
productURL string Web address for the product
productImage string Regular-sized image of the product
productThumbnail string Thumbnail-sized image of the product
manufacturer string Name of the company that makes the product
sku string Stock Keeping Unit identification code
color string The color of the product in the cart
size string The physical dimensions of the product in the car

PlainProduct

Metadata describing a product.

Kind: global typedef
Properties

Name Type Description
productInfo PlainProductInfo Standard product information
category PlainProductCategory Product categorization data
linkedProduct Array.<PlainProduct> List of data describing products linked to the product
attributes object Extensible key-value pairs describing additional facts about the product