Class: SpreeSquare::Cart::AddItem
- Inherits:
-
Spree::Cart::AddItem
- Object
- Spree::Cart::AddItem
- SpreeSquare::Cart::AddItem
- Includes:
- Spree::ServiceModule::Base
- Defined in:
- app/services/spree_square/cart/add_item.rb
Overview
Mirrors Spree::Cart::AddItem's own step sequence (see CLAUDE.md pattern #2 — swap the service, don't decorate it) with one inserted step.
Selected modifier ids arrive via the line item's transient
square_modifier_ids (set by LineItem#options=, populated from the
options: param — see variant_decorator.rb's dispatch target and the
Spree::PermittedAttributes.line_item_attributes addition in this
extension's initializer). That gets the initial price right via
Spree's own price-modifier mechanism, but the persistent
LineItemModifier snapshot rows — what survives future recalculations
and what M5's order push reads — don't exist until this step creates
them. add_to_line_item already called recalculate_price once
(before these rows existed, so it found no delta); calling it again
here is what makes the response actually reflect the final price.
Instance Method Summary collapse
Instance Method Details
#call(order:, variant:, quantity: nil, metadata: {}, public_metadata: {}, private_metadata: {}, options: {}) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'app/services/spree_square/cart/add_item.rb', line 26 def call(order:, variant:, quantity: nil, metadata: {}, public_metadata: {}, private_metadata: {}, options: {}) ApplicationRecord.transaction do run :add_to_line_item run :attach_square_modifiers run :handle_stock_reservations run Spree.cart_recalculate_service end end |