         product.categories = _.map prodCatsIds, (catId) ->
           id: catId
           typeId: 'category'
+      if slugs
+        product.slug = slugs
       Promise.resolve product
+
+  _ensureSlug: (product) ->
+    new Promise (resolve, reject) =>
+      if product.slug
+        resolve(product.slug)
+      if not product.name
+        reject("Product name is required.")
+      else
+        resolve(@_generateSlug product.name)
+
+  _generateSlug: (name, uniqueToken) ->
+    slugs = _.mapObject name, (val) =>
+      uniqueToken = @_generateUniqueToken unless uniqueToken
+      return slugify(val).concat("-#{uniqueToken}").substring(0, 256)
+    return slugs
+
+  _generateUniqueToken: ->
+    timestamp = new Date().getTime()
+    random = Math.floor(Math.random() * 90 + 10) # two digit random number.
+    return timestamp.concat random # to prevent same timestamp in parallel threads.
 
   _resolveProductCategories: (cats) ->
     new Promise (resolve) =>

_ = require 'underscore'
_.mixin require 'underscore-mixins'
Promise = require 'bluebird'
{SphereClient, ProductSync} = require 'sphere-node-sdk'

class ProductImport

    posts = _.map productsToProcess, (prodToProcess) =>
      existingProduct = @_isExistingEntry(prodToProcess, existingProducts)
      if existingProduct?
        if not prodToProcess.slug
          debug 'slug missing in product to process, assigning same as existing product: %s', existingProduct.slug
          prodToProcess.slug = existingProduct.slug # to prevent removing slug from existing product.
        synced = @sync.buildActions(prodToProcess, existingProduct)
        if synced.shouldUpdate()
          @client.products.byId(synced.getUpdateId()).update(synced.getUpdatePayload())
