I'm building an online store in meteor where customers can customize products in the store. I have setup a client-only collection called Inventory
which stores all the product data and is updated accordingly in response to user input. Once the user is ready to checkout, I dump the product data into a client & server side collection called ShoppingCart
. I want to allow users to go back and revise their edits on the product in Inventory
so I setup my router to $set
data from the ShoppingCart
into Inventory
if it finds a match:
Router.route '/:_type/:_id', ->
Session.set "inCart", false
@render @params._type,
data: =>
storedItem = ShoppingCart.findOne {
userId: Meteor.userId(),
image: @params._id
}
if storedItem?
delete storedItem._id
Inventory.update {image: @params._id}, {
$set: storedItem
}
Inventory.findOne image: @params._id
EDIT: This seems to cause my router method to get stuck in an infinite loop whenever data in Inventory
changes. Is there any way to avoid this issue? Is there a better way of handling this kind of data altogether that I should consider?