Sha256: 7ec59971a1132e388e91442be55affa224e409e3eee4359c9aae4fad6e6bebb9

Contents?: true

Size: 947 Bytes

Versions: 2

Compression:

Stored size: 947 Bytes

Contents

module Spree
  class Exchange

    def initialize(order, reimbursement_objects)
      @order = order
      @reimbursement_objects = reimbursement_objects
    end

    def description
      @reimbursement_objects.map do |reimbursement_object|
        "#{reimbursement_object.variant.options_text} => #{reimbursement_object.exchange_variant.options_text}"
      end.join(" | ")
    end

    def display_amount
      Spree::Money.new @reimbursement_objects.map(&:total).sum
    end

    def perform!
      shipments = Spree::Stock::Coordinator.new(@order, @reimbursement_objects.map(&:build_exchange_inventory_unit)).shipments
      @order.shipments += shipments
      @order.save!
      shipments.each do |shipment|
        shipment.update!(@order)
        shipment.finalize!
      end
    end

    def to_key
      nil
    end

    def self.param_key
      "spree_exchange"
    end

    def self.model_name
      Spree::Exchange
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_core-2.4.0.rc2 app/models/spree/exchange.rb
spree_core-2.4.0.rc1 app/models/spree/exchange.rb