Class: SpreeCmCommissioner::Cart::AddGuest
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Cart::AddGuest
- Includes:
- Spree::ServiceModule::Base
- Defined in:
- app/services/spree_cm_commissioner/cart/add_guest.rb
Instance Method Summary collapse
Instance Method Details
#call(order:, line_item:) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/services/spree_cm_commissioner/cart/add_guest.rb', line 6 def call(order:, line_item:) # Lock the line item (SELECT ... FOR UPDATE) so concurrent guest add/remove # on the same line item are serialized. with_lock reloads the record inside # the lock, so quantity/guests reflect the latest committed state before we # read-modify-write them. Without this, two simultaneous requests would # clobber each other's quantity update. line_item.with_lock do create_blank_guest(line_item) increase_quantity(line_item) if should_increase_quantity?(line_item) recalculate_cart(order, line_item) success(order: order, line_item: line_item) end end |