ecomUtils

ecomUtils

Members

$ecomConfig :object

Source:
See:
Global config values for E-Com Plus apps.
Type:
  • object
Example
ecomUtils.$ecomConfig.get('store_id')
// => 1011

Methods

(static) alphabeticalSort(list) → {array}

Source:
Sort list of objects alphabetically by name ot title property.
Example
// Sample array with name or title's property
ecomUtils.alphabeticalSort(['product', 'category'])
// => ["category", "product"]
ecomUtils.alphabeticalSort(['Matheus', 'Vitor', 'Ana', 'Clara', 'Bruna'])
// => ["Ana", "Bruna", "Clara", "Matheus", "Vitor"]
// Can be an array of objects like:
const brand1 = {name: 'zara'}
const brand2 = {name: 'Thermaltake'}
const brand3 = {name: 'AeroCool'}
const brand4 = {name: 'Fortrek'}
const array = [brand1, brand2, brand3, brand4]
ecomUtils.alphabeticalSort(array)
// => [{name: "AeroCool"}, {name: "Fortrek"}, {name: "Thermaltake"}, {name: "Thermaltake"}, {name: "zara"}]
Parameters:
Name Type Description
list array | object Array of objects (products, brands...) or list body with 'results'
Returns:
Type
array

(static) birthDate(customer) → {string}

Source:
Returns birth date formatted string from customer body object.
Example
// costumer will be the parameter of this function and as result will return his birth date
// const customer = object (body customer)
// customer can be like:
const costumer = { main_email: '[email protected]', birth_date: { year: 1990, month: 10, day: 1 } }
ecomUtils.birthDate(costumer)
// => "10/1/1990"
Parameters:
Name Type Description
customer object Customer body object or birth date object with day, month and year
Returns:
Type
string

(static) categoriesList(product) → {array}

Source:
Parse category tree string to list of categories names.
Example
// Can be a category tree, like:
const categoryTree = 'Quarto > Cama > Travesseiros'
// So use categoryTree is parameter of function categoriesList, like:
ecomUtils.categoriesList(categoryTree)
// => ["Quarto", "Cama", "Travesseiros"]
// Or can be a product body object like:
const product = { name: 'Ultimate', categories: [{name: 'Cadeira Gamer'},{name: 'Periféricos'}]}
ecomUtils.categoriesList(product)
=> ["Cadeira Gamer"]
Parameters:
Name Type Description
product object | string Product object body or category tree string
Returns:
Type
array

(static) filterByParentSlug(categories, slug) → {array}

Source:
Filter categories list by parent category slug.
Example
// Full object ref.: https://developers.e-com.plus/docs/api/#/store/categories/
const categories = []
categories.push({ name: 'PCs', slug: 'pcs', parent: { name: 'Info', slug: 'info' } })
categories.push({ name: 'Shirts', slug: 'shirts', parent: { name: 'Clothes', slug: 'clothes' } })
categories.push({ name: 'Info', slug: 'info' })
ecomUtils.filterByParentSlug(categories, 'info')
// => [ { name: 'PCs', slug: 'pcs', parent: { name: 'Info', slug: 'info' } } ]
Parameters:
Name Type Description
categories array List of category objects
slug string Parent category slug value
Returns:
Type
array

(static) findByName(list, title) → {object|undefined}

Source:
Find object from list by name or title value.
Example
const listOfNested = [{"name": "Ultimate Blaster", "sku": "MHP4824"}, {"name": "Xiaomi","sku": "smtp-xomi-9746"}]
ecomUtils.findByName(listOfNested, 'Ultimate Blaster')
// => {name: "Ultimate Blaster", sku: "MHP4824"}
Parameters:
Name Type Description
list array List of nested objects
title string Object (category, brand, product...) name or title value
Returns:
Type
object | undefined

(static) findByProperty(list, prop, value) → {object|undefined}

Source:
Find object from list by some property value.
Example
// Find on list of generic objects
ecomUtils.findByProperty([ { a: 1, b: 1 }, { a: 2 } ], 'a', 1)
// => { a: 1, b: 1 }
ecomUtils.findByProperty([ { a: 1 }, { a: 1, b: 1 }, { a: 0 } ], 'a', 1)
// => { a: 1 }
ecomUtils.findByProperty([ { a: 0, b: 0 }, { a: 1 } ], 'a', 3)
// => undefined
Parameters:
Name Type Description
list array List of nested objects
prop string Property name
value mixed Property value to be matched
Returns:
Type
object | undefined

(static) findBySlug(list, slug) → {object|undefined}

Source:
Find object from list by slug value.
Example
// Find on list of brands, categories, products, any...
ecomUtils.findBySlug([ { name: 'Nike', slug: 'nike' }, { name: 'Puma', slug: 'puma' } ], 'nike')
// => { name: 'Nike', slug: 'nike' }
ecomUtils.findBySlug([ { slug: 'a' }, { slug: 'b' } ], 'b')
// => { slug: 'b' }
ecomUtils.findBySlug([ { slug: 'a' }, { slug: 'b' } ], 'c')
// => undefined
Parameters:
Name Type Description
list array List of nested objects
slug string Object (category, brand, product...) slug value
Returns:
Type
object | undefined

(static) formatDate(date, langopt, optionsopt) → {string}

Source:
Parse date to locale formatted string.
Example
const notification = { datetime: '2019-06-19T03:35:52.811Z', content: {api_event: {resource: 'orders'}}}
ecomUtils.formatDate(notification, 'pt-br')
// => "19/06/2019"
Parameters:
Name Type Attributes Default Description
date string | object Date object or ISO string, or body object (order, product...)
lang string <optional>
$ecomConfig.get('lang') Snake case language code, eg.: 'en_us', 'pt_br'
options object <optional>
Options object for `toLocaleDateString` function
Returns:
Type
string

(static) formatMoney(value, currencyopt, langopt) → {string}

Source:
Parse price number to formatted currency string.
Examples
// With number as value
ecomUtils.formatMoney(10.6)
// => $10.60
ecomUtils.formatMoney(10.6, 'BRL')
// => R$10.60
ecomUtils.formatMoney(10.6, 'BRL', 'pt_br')
// => R$ 10,60
// With product, variation or cart item object as value
// Full object ref.: https://developers.e-com.plus/docs/api/#/store/products/
ecomUtils.formatMoney({ sku: 'TEST', name: 'Test', price: 140.56 })
// => $140.56
// You can also set the configured lang and currency first
$ecomConfig.set('lang', 'pt_br')
$ecomConfig.set('currency', 'BRL')
$ecomConfig.set('currency_symbol', 'R$')
// Then call `formatMoney` without expliciting currency and lang
ecomUtils.formatMoney(10.6)
// => R$ 10,60
Parameters:
Name Type Attributes Default Description
value number | object Price number or body object (product or variation)
currency string | null <optional>
$ecomConfig.get('currency') Currency code such as 'BRL'
lang string <optional>
$ecomConfig.get('lang') Snake case language code, eg.: 'en_us', 'pt_br'
Returns:
Type
string

(static) fullName(customer) → {string}

Source:
Returns user full name from customer object.
Example
const customer = { 'name': { 'given_name': 'Jonh', 'family_name': 'Lock' }, 'display_name': 'Locky' }
ecomUtils.fullName(customer)
// => 'Jonh Lock'
Parameters:
Name Type Description
customer object Customer body object
Returns:
Type
string

(static) gridTitle(gridId, grids, langopt) → {string}

Source:
Returns grid title by grid ID and lang.
Example
const gridId = 'canais'
const grid1 = {title: 'Canais', grid_id: 'canais'}
const grid2 = {title: 'Cores', grid_id: 'colors'}
const grid3 = {title: 'Tamanho', grid_id: 'size'}
const grids = [ grid1, grid2, grid3 ]
const lang = 'pt_br'
ecomUtils.gridTitle(gridId, grids, lang)
// => "Canais"
Parameters:
Name Type Attributes Default Description
gridId string The unique ID of the grid ('colors', 'size'...)
grids array List of grid objects
lang string <optional>
$ecomConfig.get('lang') Snake case language code, eg.: 'en_us', 'pt_br'
Returns:
Type
string

(static) i18n(dictionary, langopt) → {string|object}

Source:
Get translated string by lang code from dictionary object.
Examples
// With simple dictionary objects
ecomUtils.i18n({ en_us: 'Hello', pt_br: 'Olá' })
// => 'Hello'
ecomUtils.i18n({ en_us: 'Hello', pt_br: 'Olá' }, 'pt_br')
// => 'Olá'
// With nested objects
ecomUtils.i18n({ hello: { en_us: 'Hello', pt_br: 'Olá' }})
// => { hello: 'Hello' }
ecomUtils.i18n({ hello: { en_us: 'Hello', pt_br: 'Olá' }, world: { en_us: 'World' }}, 'pt_br')
// => { hello: 'Olá', world: 'World' }
ecomUtils.i18n({ en_us: { hello: 'Hello', world: 'World' }, pt_br: { hello: 'Olá' }}, 'pt_br')
// => { hello: 'Olá' }
// You can also set the configured lang first
$ecomConfig.set('lang', 'pt_br')
// Then call `i18n` without expliciting lang
ecomUtils.i18n({ en_us: 'Hello', pt_br: 'Olá' })
// => Olá
Parameters:
Name Type Attributes Default Description
dictionary object Dictionary object containing string in multiple langs
lang string <optional>
$ecomConfig.get('lang') Snake case language code, eg.: 'en_us', 'pt_br'
Returns:
Type
string | object

(static) img(product, pictureIdopt, sizeopt) → {object|undefined}

Source:
Returns img object (with url and alt) from product body or pictures list.
Example
const product = { 'pictures': [ { 'small': { 'url': 'https://ecom.com/imgs/100px/64gb.jpg'}, 'big': { 'url': 'https://ecom.com/imgs/700px/64gb.jpg' }, '_id': '694890155127368133600000' }, { 'small': { 'url': 'https://ecom.com/imgs/100px/e-5-64gb.jpg' }, 'big': { 'url': 'https://ecom.com/imgs/700px/e-5-64gb.jpg' }, '_id': '694890155127368133600001' }, { 'small': { 'url': 'https://ecom.com/imgs/100px/5-64gb.jpg' }, 'big': { 'url': 'https://ecom.com/imgs/700px/5-64gb.jpg' }, '_id': '694890155127368133600002' } ], 'name': 'Smartphone Xiaomi' }
const id = '694890155127368133600001'
const size = 'big'
ecomUtils.img(product, id, size)
// => {url: 'https://ecom.com/imgs/700px/e-5-64gb.jpg'}
Parameters:
Name Type Attributes Default Description
product object | array Product body object or list of picture objects
pictureId string <optional>
ObjectID of preferred picture to find in the list
size string <optional>
$ecomConfig.get('default_img_size') Preferred image size (generally `normal`) to find on picture object
Returns:
Type
object | undefined

(static) imgSizes(img) → {object}

Source:
Splits image size string and returns object with 'width' and 'height'.
Example
// Using a img sizes string as parameter
const size = '200x50'
ecomUtils.imgSizes(size)
// => {width: 200, height: 50}
// Using a img sizes object as parameter
const sizeObj = {size: '1000x1000'}
ecomUtils.imgSizes(sizeObj)
// => {width: 1000, height: 1000}
Parameters:
Name Type Description
img object | string Image object body or size string
Returns:
Type
object

(static) inStock(product) → {boolean}

Source:
Check if item has stock equal or greater than minimum quantity.
Example
// Full object ref.: https://developers.e-com.plus/docs/api/#/store/products/
const product = { sku: 'TEST', name: 'Test', price: 10 }
ecomUtils.inStock(product)
// => true
product.quantity = 5
ecomUtils.inStock(product)
// => true
product.min_quantity = 10
ecomUtils.inStock(product)
// => false
ecomUtils.inStock({ quantity: 1, min_quantity: 2 })
// => false
ecomUtils.inStock({ quantity: 0 })
// => false
ecomUtils.inStock({ quantity: 1, min_quantity: 1 })
// => true
ecomUtils.inStock({ quantity: 1 })
// => true
Parameters:
Name Type Description
product object Body object (product or variation)
Returns:
Type
boolean

(static) lineAddress(address, noNumberStringopt, langopt) → {string}

Source:
Returns full address string from customer object.
Example
const address = { 'zip': '35800-999', 'name': 'Jonh Lock', 'street': 'Rua Europa', 'number': 900, 'borough': 'Santa Lucia', 'city': 'Bom Despacho', 'province_code': 'MG'}
const lang = 'pt_br'
ecomUtils.lineAddress(address, lang)
// => 'Rua Europa, 900, Santa Lucia | Bom Despacho | MG'
Parameters:
Name Type Attributes Default Description
address object Address object or customer body object
noNumberString string <optional>
String to show when address has no number
lang string <optional>
$ecomConfig.get('lang') Snake case language code, eg.: 'en_us', 'pt_br'
Returns:
Type
string

(static) minQuantity(product) → {number}

Source:
Returns the minimum quantity to add to cart.
Examples
// With min quantity specified
// Full object ref.: https://developers.e-com.plus/docs/api/#/store/products/
const product = { sku: 'TEST', name: 'Test', price: 10, min_quantity: 10 }
ecomUtils.minQuantity(product)
// => 10
product.min_quantity = 0
ecomUtils.minQuantity(product)
// => 0
// 1 by default when min quantity is undefined
ecomUtils.minQuantity({ sku: 'TEST', name: 'Test' })
// => 1
ecomUtils.minQuantity({})
// => 1
Parameters:
Name Type Description
product object Body object (product or variation)
Returns:
Type
number

(static) name(body, langopt) → {string}

Source:
Returns object name by lang.
Examples
// Sample object with name and translations
const product = { name: 'Test', i18n: { en_us: 'Test', pt_br: 'Teste' } }
ecomUtils.name(product)
// => 'Test'
ecomUtils.name(product, 'pt_br')
// => 'Teste'
// Without translations
ecomUtils.name({ name: 'Hello' })
// => 'Hello'
ecomUtils.name({ name: 'Hello' }, 'pt_br')
// => 'Hello'
ecomUtils.name({ title: 'Mundo' }, 'en_us')
// => 'Mundo'
// You can also set the configured lang first
$ecomConfig.set('lang', 'pt_br')
// Then call `name` without expliciting lang
ecomUtils.name({ name: 'Test', i18n: { en_us: 'Test', pt_br: 'Teste' } })
// => 'Teste'
Parameters:
Name Type Attributes Default Description
body object Object (product, category, brand, grid...) body
lang string <optional>
$ecomConfig.get('lang') Snake case language code, eg.: 'en_us', 'pt_br'
Returns:
Type
string

(static) nickname(customer) → {string}

Source:
Returns user name to display from customer object.
Example
const customer = { 'name': { 'given_name': 'Jonh', 'family_name': 'Lock' }, 'display_name': 'Locky' }
ecomUtils.nickname(customer)
// => 'Locky'
Parameters:
Name Type Description
customer object Customer body object
Returns:
Type
string

(static) objectIdPad(id, index) → {string}

Source:
Merge received ObjectID string with new index.
Example
const id = '5ce59fbf887ef430f1f6ed29'
const index = '5'
ecomUtils.objectIdPad(id, index)
// => '5ce59fbf887ef430f1f6ed25'
Parameters:
Name Type Description
id string Base ID string, 24 digits hexadecimal
index string The index to be inserted on the end of base ID, creating new ObjectID
Returns:
Type
string

(static) onPromotion(product) → {boolean}

Source:
Check if item has promotional price.
Examples
// Simple test with no promotion date range
// Full object ref.: https://developers.e-com.plus/docs/api/#/store/products/
ecomUtils.onPromotion({ sku: 'TEST', name: 'Test', price: 140.56 })
// => false
ecomUtils.onPromotion({ price: 100, base_price: 110 })
// => true
ecomUtils.onPromotion({ price: 190, base_price: 170 })
// => false
// With date range
const product = { sku: 'abc', price: 20.9, base_price: 30.9, price_effective_date: {} }
product.price_effective_date.start = '2019-06-01T16:03:45.035Z'
ecomUtils.onPromotion(product)
// => true
product.price_effective_date.end = '2019-06-10T16:03:45.035Z'
ecomUtils.onPromotion(product)
// => false
product.price_effective_date.end = '2021-08-12T00:00:00.000Z'
ecomUtils.onPromotion(product)
// => true
product.price_effective_date.start = '2021-01-01T00:00:00.000Z'
ecomUtils.onPromotion(product)
// => false
Parameters:
Name Type Description
product object Item (product or variation) body object
Returns:
Type
boolean

(static) parseDate(dateStr, countryCodeopt) → {object}

Source:
Returns customer birth date object from string.
Examples
// Date string is fixed to digits only and parsed to E-Com Plus APIs date object
ecomUtils.parseDate('1990-01-12')
// => { day: 12, month: 1, year: 1990 }
ecomUtils.parseDate('10/02/1997', 'BR')
// => { day: 10, month: 2, year: 1997 }
// You can also set the configured country code first
$ecomConfig.set('country_code', 'BR')
// Then call `parseDate` without expliciting country code again
ecomUtils.parseDate('10/02/1997')
// => { day: 10, month: 2, year: 1997 }
Parameters:
Name Type Attributes Default Description
dateStr string Formatted date string
countryCode string <optional>
$ecomConfig.get('country_code') Country ISO 3166-1 alpha-2 code
Returns:
Type
object

(static) parsePhone(phoneStr) → {object}

Source:
Returns customer phone object from string.
Examples
// Phone string is fixed and parsed to object with `number`
ecomUtils.parsePhone('31992980000')
// => { number: '31992980000' }
ecomUtils.parsePhone('31 99298-1000')
// => { number: '31992981000' }
// Country code is optional and identified by + signal
ecomUtils.parsePhone('+55 31992980000')
// => { country_code: 55, number: '31992980000' }
Parameters:
Name Type Description
phoneStr string Phone string
Returns:
Type
object

(static) phone(customer) → {string}

Source:
Returns phone string from customer body or phone object.
Example
const customer = { 'number': '31992980000'}
ecomUtils.phone(customer)
// => '31992980000'
Parameters:
Name Type Description
customer object Customer body object or phone object with number property
Returns:
Type
string

(static) price(product) → {number}

Source:
Returns current price from item object.
Examples
// Prices with no promotion date range
// Full object ref.: https://developers.e-com.plus/docs/api/#/store/products/
ecomUtils.price({ sku: 'TEST', name: 'Test', price: 140.56 })
// => 140.56
ecomUtils.price({ price: 100, base_price: 110 })
// => 100
ecomUtils.price({ price: 190, base_price: 170 })
// => 190
ecomUtils.price({})
// => 0
// With promotion date range
const product = { sku: 'abc', price: 20.9, base_price: 30.9, price_effective_date: {} }
product.price_effective_date.start = '2021-01-01T00:00:00.000Z'
ecomUtils.price(product)
// => 30.9
product.price_effective_date.start = '2019-06-01T16:03:45.035Z'
ecomUtils.price(product)
// => 20.9
product.price_effective_date.end = '2019-06-10T16:03:45.035Z'
ecomUtils.price(product)
// => 30.9
Parameters:
Name Type Description
product object Item (product or variation) body object
Returns:
Type
number

(static) randomObjectId() → {string}

Source:
Generate a random object id with 24 chars hexadecimal string.
Example
ecomUtils.randomObjectId()
// => '561025156443695764000000'
Returns:
Type
string

(static) recommendedIds(result) → {array}

Source:
Returns array of product IDs from Graphs API response.
Example
// Full Graphs API response samples:
// https://developers.e-com.plus/docs/api/#/graphs/products/recommended
const result = { results: [ { columns: [], data: [] } ] }
result.results[0].data.push(
  { row: [ 'a00000000000000000000001' ], meta: [ null ] },
  { row: [ 'a00000000000000000000002' ], meta: [ null ] },
  { row: [ 'a00000000000000000000006' ], meta: [ null ] }
)
ecomUtils.recommendedIds(result)
// => [ 'a00000000000000000000001', 'a00000000000000000000002', 'a00000000000000000000006' ]
Parameters:
Name Type Description
result object | array Recommend/related products response body
Returns:
Type
array

(static) searchedItems(result) → {array}

Source:
Returns array of items (products) from Search API response.
Example
// Full Search API response samples:
// https://developers.e-com.plus/docs/api/#/search/items/items
const result = { took: 6, hits: { total: 2, hits: [] } }
result.hits.hits.push({ _id: '123', _source: { sku: 'TEST', name: 'Test' } })
result.hits.hits.push({ _id: '456', _source: { sku: 'SMP', name: 'Smp' } })
ecomUtils.searchedItems(result)
// => [ { _id: '123', sku: 'TEST', name: 'Test' }, { _id: '456', sku: 'SMP', name: 'Smp' } ]
// Same passing the `hits` array as param
ecomUtils.searchedItems(result.hits.hits)
// => [ { _id: '123', sku: 'TEST', name: 'Test' }, { _id: '456', sku: 'SMP', name: 'Smp' } ]
Parameters:
Name Type Description
result object | array Search response body or ELS hits array
Returns:
Type
array

(static) specTextValue(product, gridId, gridsopt, delimiteropt) → {array|null}

Source:
Parse specifications array of nested objects to string.
Example
const product = { 'name': 'Cruzeiro 2019', 'variations': [ { 'name': 'Cruzeiro 2019 / P / azul', 'specifications': { 'colors': [ { 'text': 'azul', 'value': '#3300ff' }, { 'text': 'vermelho', 'value': '#ff0000' } ] } } ] }
const gridId = 'colors'
const delimiter = ','
const grid1 = { 'grid_id': 'size', 'title': 'Tamanho', 'options': [ { 'text': 'P', 'option_id': 'pp' } ] }
const grid2 = { 'title': 'Cores', 'grid_id': 'colors', 'options': [ { 'text': 'vermelho', 'option_id': 'vermelho', 'colors': [ '#ff0000' ] }, { 'text': 'azul', 'option_id': 'azul', 'colors': [ '#3300ff' ] } ] }
const grid3 = { 'title': 'Conector', 'grid_id': 'conector', 'options': [ { 'text': 'USB', 'option_id': 'usb' } ] }
const grids = [ grid1, grid2, grid3 ]
ecomUtils.specValues(product, gridId, grids, delimiter)
// => [{text: 'vermelho', value: '#ff0000'}, {text: 'azul', value: '#3300ff'}]
Parameters:
Name Type Attributes Default Description
product object | array Product body or array of variation objects
gridId string Grid ID string such as 'color'
grids array <optional>
List of grid objects
delimiter string <optional>
', ' Delimiter between each specification
Returns:
Type
array | null

(static) specValueByText(product, specText, gridId, gridsopt) → {string|undefined}

Source:
Get value property of spec object based on respective text.
Example
const product = { 'name': 'Cruzeiro 2018', 'variations': [ { 'name': 'Cruzeiro 2018 / P / azul', 'specifications': { 'colors': [ { 'text': 'azul', 'value': '#3300ff' }, { 'text': 'vermelho', 'value': '#ff0000' } ] } } ] }
const gridId = 'colors'
const specText = 'vermelho'
const grid1 = { 'grid_id': 'size', 'title': 'Tamanho', 'options': [ { 'text': 'P', 'option_id': 'pp' } ] }
const grid2 = { 'title': 'Cores', 'grid_id': 'colors', 'options': [ { 'text': 'vermelho', 'option_id': 'vermelho', 'colors': [ '#ff0000' ] }, { 'text': 'azul', 'option_id': 'azul', 'colors': [ '#3300ff' ] } ] }
const grid3 = { 'title': 'Conector', 'grid_id': 'conector', 'options': [ { 'text': 'USB', 'option_id': 'usb' } ] }
const grids = [ grid1, grid2, grid3 ]
ecomUtils.specValueByText(product, specText, gridId , grids)
// => '#ff0000'
Parameters:
Name Type Attributes Description
product object | array Product body or array of variation objects
specText string Spec object text property such as 'Blue'
gridId string Grid ID string such as 'color'
grids array <optional>
List of grid objects
Returns:
Type
string | undefined

(static) specValues(product, gridId, gridsopt) → {array}

Source:
Returns array of spec objects for specified grid.
Example
const product = { 'name': 'Cruzeiro 2019', 'variations': [ { 'name': 'Cruzeiro 2019 / P / azul', 'specifications': { 'colors': [ { 'text': 'azul', 'value': '#3300ff' } ] } } ] }
const gridId = 'colors'
const grid1 = { 'grid_id': 'size', 'title': 'Tamanho', 'options': [ { 'text': 'P', 'option_id': 'pp' } ] }
const grid2 = { 'title': 'Cores', 'grid_id': 'colors', 'options': [ { 'text': 'vermelho', 'option_id': 'vermelho', 'colors': [ '#ff0000' ] }, { 'text': 'azul', 'option_id': 'azul', 'colors': [ '#3300ff' ] } ] }
const grid3 = { 'title': 'Conector', 'grid_id': 'conector', 'options': [ { 'text': 'USB', 'option_id': 'usb' } ] }
const grids = [ grid1, grid2, grid3 ]
ecomUtils.specValues(product, gridId, grids)
// => [{text: "vermelho", value: "#ff0000"}, {text: "azul", value: "#3300ff"}]
Parameters:
Name Type Attributes Description
product object | array Product body or array of variation objects
gridId string Grid ID string such as 'color'
grids array <optional>
List of grid objects
Returns:
Type
array

(static) variationsGrids(product, filterGridsopt, inStockOnlyopt, delimiteropt) → {object}

Source:
Parse variations specifications to one object only.
Example
// Only param product
const product = { 'name': 'Cruzeiro 2019', 'variations': [
{ 'name': 'Cruzeiro 2019 / P', 'quantity': 10, 'specifications': { 'size': [ { 'text': 'P', 'value': 's' } ] } },
{ 'name': 'Cruzeiro 2019 / M', 'quantity': 10, 'specifications': { 'size': [ { 'text': 'M', 'value': 'm' } ] } },
{ 'name': 'Cruzeiro 2019 / G', 'specifications': { 'size': [ { 'text': 'G', 'value': 'l' } ] }, 'quantity': 0 }
] }
ecomUtils.variationsGrids(product)
// => {size: [ 'P', 'M', 'G' ]}
// You can also check for product stock to get only variations with available quantity
// Same product above
const inStockOnly = true
ecomUtils.variationsGrids(product, {}, inStockOnly)
// => {size: [ 'P', 'M' ]}
Parameters:
Name Type Attributes Default Description
product object Product body object
filterGrids object <optional>
Filter object with grids and searched values
inStockOnly boolean <optional>
True to consider only variations with positive stock quantity
delimiter string <optional>
', ' Delimiter between each specification
Returns:
Type
object