     # Thus we delete the original value (containing key and label) and set
     # the key as value at the attribute.
     # This way (l)enum attributes are handled the same way as text attributes.
-    patchEnum = (attribute) ->
-      return if _.isUndefined(attribute.value) or _.isNull(attribute.value)
-      if isEnum attribute.value
-        v = attribute.value.key
-        delete attribute.value
-        attribute.value = v
-      else if _.isArray(attribute.value)
-        for val, index in attribute.value
-          if isEnum val
-            attribute.value[index] = val.key
-          else # if we can't find key and label it isn't an (l)enum set and we can stop immediately
-            return
-
-    patchEnums = (obj) ->
-      _.each allVariants(obj), (variant) ->
-        if variant.attributes
-          _.each variant.attributes, (attrib, index) ->
-            patchEnum attrib
-
-    patchEnums(old_obj)
-    patchEnums(new_obj)
-
-    super(old_obj, new_obj)
+    patchEnums = (variant) ->
+      if variant.attributes
+        _.each variant.attributes, (attribute) ->
+          if attribute.value?
+            if isEnum attribute.value
+              v = attribute.value.key
+              delete attribute.value
+              attribute.value = v
+            else if _.isArray(attribute.value)
+              for val, index in attribute.value
+                if isEnum val
+                  attribute.value[index] = val.key
+                else # if we can't find key and label it isn't an (l)enum set and we can stop immediately
+                  return
+
+    patch = (obj) ->
+      _.each allVariants(obj), (variant, index) ->
+        patchVariantId variant, index
+        patchPrices variant
+        patchEnums variant
+
+    patch old_obj
+    patch new_obj
+
+    super old_obj, new_obj
 
 
   ###

        else if REGEX_UNDERSCORE_NUMBER.test(key) and _.isArray(variant)
          action =
            action: 'removeVariant'
            id: variant[0].id
          actions.push action

    _.sortBy actions, (a) -> a.action is 'addVariant'

  if attribute
    action =
      action: 'setAttribute'
      variantId: getVariantId old_variant
      name: attribute.name

    if _.contains(sameForAllAttributeNames, attribute.name)
