@ecomplus/utils
Version:
JS utility functions to E-Com Plus (not only) related apps
35 lines • 1.51 kB
TypeScript
export default variationsGrids;
/**
* @method
* @memberof ecomUtils
* @name variationsGrids
* @description Parse variations specifications to one object only.
* @param {Object.<string, *>} product - Product body object
* @param {Object.<string, *>} [filterGrids] - Filter object with grids and searched values
* @param {boolean} [inStockOnly] - True to consider only variations with positive stock quantity
* @param {string} [delimiter=', '] - Delimiter between each specification
* @returns {Object.<string, *>}
*
* @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' ]}
*/
declare function variationsGrids(product: {
[x: string]: any;
}, filterGrids?: {
[x: string]: any;
}, inStockOnly?: boolean, delimiter?: string): {
[x: string]: any;
};
//# sourceMappingURL=variations-grids.d.ts.map