Skip to content

Commit

Permalink
feat(method): new 'specTextValue' method
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Jul 2, 2019
1 parent 0331e25 commit 095de7b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import inStock from './methods/in-stock'
import searchedItems from './methods/searched-items'
import splitCategoryTree from './methods/split-category-tree'
import specValues from './methods/spec-values'
import specTextValue from './methods/spec-text-value'

/**
* JS utility functions for E-Com Plus (not only) related apps.
Expand Down Expand Up @@ -56,7 +57,8 @@ export {
inStock,
searchedItems,
splitCategoryTree,
specValues
specValues,
specTextValue
}

/**
Expand Down
36 changes: 36 additions & 0 deletions src/methods/spec-text-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import specValues from './specValues'

const specTextValue = (product, gridId, grids, delimiter = ', ') => {
// using text property of each spec object
let values = specValues(product, gridId, grids)
if (values.length) {
let valuesString = values[0].text
for (let i = 1; i < values.length; i++) {
valuesString += delimiter + values[i].text
}
return valuesString
}
// specification not found
return null
}

/**
* @method
* @memberof ecomUtils
* @name specTextValue
* @description Parse specifications array of nested objects to string.
* @param {object|array} product - Product body or array of variation objects
* @param {string} gridId - Grid ID string such as 'color'
* @param {array} [grids] - List of grid objects
* @param {string} [delimiter=', '] - Delimiter between each specification
* @returns {string|null}
*
* @example
* // TODO
*
* @example
* // Importing this method standalone
* import specTextValue from '@ecomplus/utils/dist/methods/spec-text-value'
*/

export default specTextValue

0 comments on commit 095de7b

Please sign in to comment.