 
     isBuyable = -> products.length > 0 && exports.buyer
 
-    entryByProductName = (name)->
-      return entry for entry in products when entry.product.name == name
+    entryByProductName = (entries, name)->
+      return entry for entry in entries when entry.product.name == name
       null
 
     delayedAddProduct = (name, amount)->

        #always return the current promise if resolving to prevent multiple requests being run for the same resource
        return buyer if buyer?.then?
        buyer = User.find(username).then (user)-> buyer = user
    #return api-object with methods/objects accessible from outside
    exports = {
      changeAmount: changeAmount
      remove: remove
      empty: empty
      productCount: productCount
      price: price
      isBuyable: isBuyable
      products: resolveProducts
      buyer: resolveBuyer
    }
])
    buyer = null

    changeAmount = (entry, amount)->
      name = entry.product.name
      currentAmount = parseInt($location.search()[name])
      unless currentAmount + amount < 1
        newAmount = currentAmount + amount
        $location.search(name, newAmount).replace()

    empty = ->
      searchObj = $location.search()
