Sha256: 6965b609356796e43063f02562d1ba0139f72a91c1d4848b432c895510ff4c16
Contents?: true
Size: 877 Bytes
Versions: 26
Compression:
Stored size: 877 Bytes
Contents
# adds item to an existing shipment # if this variant is already added to the cart it will increase the quantity # if not it will create new line item module Spree module Shipments class AddItem prepend Spree::ServiceModule::Base include Helper def call(shipment:, variant_id:, quantity: nil) ActiveRecord::Base.transaction do run :prepare_arguments run :add_or_update_line_item end end protected def prepare_arguments(shipment:, variant_id:, quantity: nil) order = shipment.order store = order.store variant = store.variants.find_by(id: variant_id) return failure(nil, :variant_not_found) if variant.nil? quantity = quantity&.to_i || 1 success(order: order, shipment: shipment, variant: variant, quantity: quantity) end end end end
Version data entries
26 entries across 26 versions & 1 rubygems