Class: Workarea::Checkout::AutoComplete

Inherits:
Object
  • Object
show all
Defined in:
app/models/workarea/checkout/auto_complete.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order, payment, user) ⇒ AutoComplete

Returns a new instance of AutoComplete.



10
11
12
13
14
# File 'app/models/workarea/checkout/auto_complete.rb', line 10

def initialize(order, payment, user)
  @order = order
  @payment = payment
  @user = user
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order.



8
9
10
# File 'app/models/workarea/checkout/auto_complete.rb', line 8

def order
  @order
end

#paymentObject (readonly)

Returns the value of attribute payment.



8
9
10
# File 'app/models/workarea/checkout/auto_complete.rb', line 8

def payment
  @payment
end

#userObject (readonly)

Returns the value of attribute user.



8
9
10
# File 'app/models/workarea/checkout/auto_complete.rb', line 8

def user
  @user
end

Instance Method Details

#billing_addressAddress?

The billing address used to autocomplete the checkout.

Returns:



47
48
49
# File 'app/models/workarea/checkout/auto_complete.rb', line 47

def billing_address
  user.default_billing_address
end

#credit_cardPayment::SavedCreditCard?

The credit card used to autocomplete the checkout.

Returns:



64
65
66
# File 'app/models/workarea/checkout/auto_complete.rb', line 64

def credit_card
  payment.default_credit_card
end

#paramsHash

The params for the most autocomplete info that is present for the current user. Passed to Workarea::Checkout#update to autocomplete the order.

Returns:

  • (Hash)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/workarea/checkout/auto_complete.rb', line 22

def params
  result = {
    email: user.email,
    payment: credit_card.try(:id)
  }

  if billing_address.present?
    result[:billing_address] = billing_address.attributes.slice(
        *address_attr_keys
      )
  end

  if shipping_address.present?
    result[:shipping_address] = shipping_address.attributes.slice(
        *address_attr_keys
      )
  end

  result
end

#shipping_addressAddress?

The shipping address used to autocomplete the checkout.

Returns:



56
57
58
# File 'app/models/workarea/checkout/auto_complete.rb', line 56

def shipping_address
  user.default_shipping_address
end