         #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
+
+    setFromBuy = (buy)->
+      empty()
+      search = $location.search()
+      search.buyer = buy.buyer.username
+      for entry in buy.consistsOfProducts
+        search[entry.product.name] = entry.amount
+      $location.search(search).replace()
+
     #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
+      setFromBuy: setFromBuy
     }
 ])
      (product)-> entry.product = product

    resolveProducts = ->
      for own k, v of $location.search()
        v = parseInt(v)
        continue if isNaN(v)
        entry = entryByProductName(k)
        if entry?
          entry.amount = v
        else
          Product.find(k).then delayedAddProduct(k, v)
      products

    resolveBuyer = ->


    isBuyable = -> products.length > 0 && exports.buyer

    entryByProductName = (entries, name)->
      return entry for entry in entries when entry.product.name == name
      null

    delayedAddProduct = (name, amount)->
