Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * First: pluck to extract all attributes_combinations from the items variations array
- * Second: union to join all arrays into one array of arrays
- * Third flattenDeep to make an array of arrays into an array
- * by now I have an array with all the attributes the item has available
- * Fourth: Remove duplicate attributes
- * Fifth: countBy 'name' to count how many different attributes names we have for each variation type
- * Example variations_count = {
- * 'Color Primario': 2 //It has 2 Color Primario available (blue and white)
- * 'Color Secundario': 1 //It has 1 Color Secundario available (only black)
- * 'Talle': 3 //It has 3 sizes available
- * }
- */
- var variations_count = _.countBy(_.unique(_.flattenDeep(_.union(_.pluck(fullItem.variations, 'attribute_combinations'))), 'value_name'), 'name');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement