Sha256: 594e27bb84416808fa2172d33252248741fed8eb1be630fc99f52a23418dd9f8

Contents?: true

Size: 981 Bytes

Versions: 62

Compression:

Stored size: 981 Bytes

Contents

module Workarea
  class Login
    attr_reader :user, :current_order

    def initialize(user, current_order)
      @user = user
      @current_order = current_order
    end

    def previous_order
      @previous_order ||= Order
                            .carts
                            .where(user_id: user.id)
                            .order_by(:created_at.desc)
                            .first
    end

    def perform
      user.login_success!

      if previous_order &&
           !previous_order.checking_out? &&
           previous_order.items.present? &&
           previous_order != current_order

        OrderMerge.new(previous_order).merge(current_order)
        @current_order = previous_order
      elsif current_order.persisted?
        if current_order.started_checkout?
          Checkout.new(current_order).continue_as(user)
        else
          current_order.update_attributes!(user_id: user.id)
        end
      end

      self
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/services/workarea/login.rb
workarea-core-3.5.26 app/services/workarea/login.rb
workarea-core-3.4.45 app/services/workarea/login.rb
workarea-core-3.5.25 app/services/workarea/login.rb
workarea-core-3.5.23 app/services/workarea/login.rb
workarea-core-3.4.44 app/services/workarea/login.rb
workarea-core-3.5.22 app/services/workarea/login.rb
workarea-core-3.4.43 app/services/workarea/login.rb
workarea-core-3.5.21 app/services/workarea/login.rb
workarea-core-3.4.42 app/services/workarea/login.rb
workarea-core-3.5.20 app/services/workarea/login.rb
workarea-core-3.4.41 app/services/workarea/login.rb
workarea-core-3.5.19 app/services/workarea/login.rb
workarea-core-3.4.40 app/services/workarea/login.rb
workarea-core-3.5.18 app/services/workarea/login.rb
workarea-core-3.4.39 app/services/workarea/login.rb
workarea-core-3.5.17 app/services/workarea/login.rb
workarea-core-3.4.38 app/services/workarea/login.rb
workarea-core-3.5.16 app/services/workarea/login.rb
workarea-core-3.4.37 app/services/workarea/login.rb