   # @param {String} name - name of the attribute
   # @return {Any} attribute value if found
   @valueOf: (attributes, name) ->
-    attrib = _.find(attributes || [], (attribute) ->
+    attrib = _.find(attributes, (attribute) ->
       attribute.name is name)
     attrib?.value
 
   @formatAttributePredicate: (name, items) ->
-    "#{attribute} in (\"#{items.join('", "')}\")"
+    "#{name} in (\"#{items.join('", "')}\")"
 
   @applyPredicateToVariants: (predicate) ->
     "masterVariant(#{predicate}) or variants(#{predicate})"

  @matchBySku: (products) ->
    skus = _.flatten(products.map((p) ->
      [p.product.masterVariant.sku].concat(p.product.variants.map((v) ->
        v.sku)))).filter(x ->
          !!x)
    predicate = QueryUtils.formatAttributePredicate("sku", skus)
    QueryUtils.applyPredicateToVariants(predicate)


        [
          QueryUtils.valueOf(p.product.masterVariant.attributes, attribute)
        ].concat(p.product.variants.map((v) ->
          QueryUtils.valueOf(v.attributes, attribute)))))
          .filter(Helpers.exists)
      predicate = QueryUtils.formatAttributePredicate(attribute, values)
      QueryUtils.applyPredicateToVariants(predicate)

