<commit_before>_ = require 'underscore'
BaseSync = require './base-sync'
ProductUtils = require './utils/product'

# Public: Define a `ProductSync` to provide basic methods to sync SPHERE.IO products.
#
# Action groups for products are:
# - `base` (name, slug, description)
# - `references` (taxCategory, categories)
# - `prices`
# - `attributes`
# - `images`
# - `variants`
#
# Examples
#
#   {ProductSync} = require 'sphere-node-sdk'
#   sync = new ProductSync
#   syncedActions = sync.buildActions(newCategory, existingCategory)
#   if syncedActions.shouldUpdate()
#     client.products.byId(syncedActions.getUpdatedId())
#     .update(syncedActions.getUpdatePayload())
#   else
#     # do nothing
class ProductSync extends BaseSync

  # Public: Construct a `ProductSync` object.
  constructor: ->
    # Override base utils
    @_utils = new ProductUtils

  buildActions: (new_obj, old_obj, sameForAllAttributeNames = []) ->
    @sameForAllAttributeNames = sameForAllAttributeNames
    super new_obj, old_obj

  _doMapActions: (diff, new_obj, old_obj) ->
    allActions = []
    allActions.push @_mapActionOrNot 'base', => @_utils.actionsMapBase(diff, old_obj)
    allActions.push @_mapActionOrNot 'references', => @_utils.actionsMapReferences(diff, old_obj, new_obj)
    allActions.push @_mapActionOrNot 'prices', => @_utils.actionsMapPrices(diff, old_obj, new_obj)
    allActions.push @_mapActionOrNot 'attributes', => @_utils.actionsMapAttributes(diff, old_obj, new_obj, @sameForAllAttributeNames)
    allActions.push @_mapActionOrNot 'images', => @_utils.actionsMapImages(diff, old_obj, new_obj)
    allActions.push @_mapActionOrNot 'variants', => @_utils.actionsMapVariants(diff, old_obj, new_obj)
    allActions.push @_mapActionOrNot 'categories', => @_utils.actionsMapCategories(diff)
    _.flatten allActions

module.exports = ProductSync
<commit_msg>Add: static property for list of action groups in Product Sync.<commit_after>_ = require 'underscore'
BaseSync = require './base-sync'
ProductUtils = require './utils/product'

# Public: Define a `ProductSync` to provide basic methods to sync SPHERE.IO products.
#
# Action groups for products are:
# - `base` (name, slug, description)
# - `references` (taxCategory)
# - `prices`
# - `attributes`
# - `images`
# - `variants`
# - `categories`
#
# Examples
#
#   {ProductSync} = require 'sphere-node-sdk'
#   sync = new ProductSync
#   syncedActions = sync.buildActions(newProduct, existingProduct)
#   if syncedActions.shouldUpdate()
#     client.products.byId(syncedActions.getUpdatedId())
#     .update(syncedActions.getUpdatePayload())
#   else
#     # do nothing
class ProductSync extends BaseSync

  @actionGroups = ['base', 'references', 'prices', 'attributes', 'images', 'variants', 'categories']

  # Public: Construct a `ProductSync` object.
  constructor: ->
    # Override base utils
    @_utils = new ProductUtils

  buildActions: (new_obj, old_obj, sameForAllAttributeNames = []) ->
    @sameForAllAttributeNames = sameForAllAttributeNames
    super new_obj, old_obj

  _doMapActions: (diff, new_obj, old_obj) ->
    allActions = []
    allActions.push @_mapActionOrNot 'base', => @_utils.actionsMapBase(diff, old_obj)
    allActions.push @_mapActionOrNot 'references', => @_utils.actionsMapReferences(diff, old_obj, new_obj)
    allActions.push @_mapActionOrNot 'prices', => @_utils.actionsMapPrices(diff, old_obj, new_obj)
    allActions.push @_mapActionOrNot 'attributes', => @_utils.actionsMapAttributes(diff, old_obj, new_obj, @sameForAllAttributeNames)
    allActions.push @_mapActionOrNot 'images', => @_utils.actionsMapImages(diff, old_obj, new_obj)
    allActions.push @_mapActionOrNot 'variants', => @_utils.actionsMapVariants(diff, old_obj, new_obj)
    allActions.push @_mapActionOrNot 'categories', => @_utils.actionsMapCategories(diff)
    _.flatten allActions

module.exports = ProductSync

{'fraction_non_alphanumeric': 0.1240010311936066, 'fraction_numerical': 0.0, 'mean_word_length': 4.996908809891808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3205662', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1228, 'n_words': 274}