These are chat archives for reactioncommerce/reaction

6th
Aug 2015
Spencer Norman
@spencern
Aug 06 2015 21:19
Is it possible that this method could be run — and inventory adjusted — more than once for a single orderId?
  inventoryAdjust: (orderId) ->
    check orderId, String

    order = Orders.findOne orderId
    return false unless order
    for product in order.items
      Products.update {_id: product.productId, "variants._id": product.variants._id}, {$inc: {"variants.$.inventoryQuantity": -product.quantity }}
    return
Aaron Judd
@aaronjudd
Aug 06 2015 21:47
@spencern funny you should ask...
Aaron Judd
@aaronjudd
Aug 06 2015 21:52
working on a new cart workflow mechanism, that should make each step independant of each other, and support multiple different flows… including rerunning methods in #278
Spencer Norman
@spencern
Aug 06 2015 21:54
Excellent. Hopefully events will make it easier to adjust the flow. My next question was about how to adjust this checkout flow from another package, but I guess I’ll hold off on that until you’ve adjusted the workflow.
Aaron Judd
@aaronjudd
Aug 06 2015 21:54
re: inventoryAdjust no reason it can’t be run more than once right now - but I can see where that could potentially be a problem as well (tracking if the inventory had or had not been adjusted for this particular item yet). we’ll probably need have a method for tracking change history as well
Spencer Norman
@spencern
Aug 06 2015 21:56
Yeah, that’s what I was getting at. It seems like theres no security preventing someone/some method/ whatever from running inventoryAdjust for an orderId that’s already gone through and as long as the orderId exists, the inventory could be adjusted again without another order occuring
Also, just realized that the inventoryVariants stuff I added a few weeks ago will definitely break with this current version of inventoryAdjust
Anyways, working on a rental inventory adjustment method and was looking at this to figure out how to secure it so that it could only be run once by the checkout process
Aaron Judd
@aaronjudd
Aug 06 2015 22:01
probably just need a inventory collection, where you insert on new variant, and add a record for each change to that variant, with (orderId, cartId, userId, qty) so that you can track history (and roll forward, back inventory changes as well from there)
I’m going to be adding Method hooks as a permanent part as well, and moving all the cart mechanics to server methods, so you’ll be able to use a before / after hook / override for any step
Spencer Norman
@spencern
Aug 06 2015 22:03
:+1: That will be perfect