Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. /*
  2. * First: pluck to extract all attributes_combinations from the items variations array
  3. * Second: union to join all arrays into one array of arrays
  4. * Third flattenDeep to make an array of arrays into an array
  5. * by now I have an array with all the attributes the item has available
  6. * Fourth: Remove duplicate attributes
  7. * Fifth: countBy 'name' to count how many different attributes names we have for each variation type
  8. * Example variations_count = {
  9. * 'Color Primario': 2 //It has 2 Color Primario available (blue and white)
  10. * 'Color Secundario': 1 //It has 1 Color Secundario available (only black)
  11. * 'Talle': 3 //It has 3 sizes available
  12. * }
  13. */
  14.  
  15. 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