Class: Workarea::Storefront::Checkout::AddressesViewModel

Inherits:
ApplicationViewModel
  • Object
show all
Includes:
Workarea::Storefront::CheckoutContent
Defined in:
app/view_models/workarea/storefront/checkout/addresses_view_model.rb

Instance Method Summary collapse

Methods included from Workarea::Storefront::CheckoutContent

#content_lookup

Methods included from DisplayContent

#browser_title, #content, #content_blocks, #content_blocks_for, #meta_description, #open_graph_asset

Instance Method Details

#billing_addressWorkarea::Address

The current billing address for the order. Used for errors and form fields.

Returns:

  • (Workarea::Address)


30
31
32
# File 'app/view_models/workarea/storefront/checkout/addresses_view_model.rb', line 30

def billing_address
  payment.address || Address.new
end

#default_billing_address_idUser::SavedAddress?

Return the default billing address id of the current user. Returns nil if not logged in or no addresses. Used as HTML data for JS address-selection functionality.

Returns:

  • (User::SavedAddress, nil)


60
61
62
# File 'app/view_models/workarea/storefront/checkout/addresses_view_model.rb', line 60

def default_billing_address_id
  user.try(:default_billing_address).try(:id)
end

#default_shipping_address_idUser::SavedAddress?

Return the default shipping address id of the current user. Returns nil if not logged in or no addresses. Used as HTML data for JS address-selection functionality.

Returns:

  • (User::SavedAddress, nil)


49
50
51
# File 'app/view_models/workarea/storefront/checkout/addresses_view_model.rb', line 49

def default_shipping_address_id
  user.try(:default_shipping_address).try(:id)
end

#saved_addressesArray<User::SavedAddress>

Returns an array of saved addresses for the current user. Used as HTML data for JS address-selection functionality.

Returns:

  • (Array<User::SavedAddress>)


69
70
71
# File 'app/view_models/workarea/storefront/checkout/addresses_view_model.rb', line 69

def saved_addresses
  user.try(:addresses)
end

#shipping_addressShipping::Address

The current shipping address for the order. Used for errors and form fields.

Returns:

  • (Shipping::Address)


39
40
41
# File 'app/view_models/workarea/storefront/checkout/addresses_view_model.rb', line 39

def shipping_address
  shipping.try(:address) || Shipping::Address.new
end

#show_email_field?Boolean

Whether to show the email field. Only show it if we have a user for the checkout.

Returns:

  • (Boolean)


12
13
14
# File 'app/view_models/workarea/storefront/checkout/addresses_view_model.rb', line 12

def show_email_field?
  user.blank?
end

#show_shipping_address?Boolean

Whether to show the shipping address. Only show it if the order requires shipping (has non-digital items).

Returns:

  • (Boolean)


21
22
23
# File 'app/view_models/workarea/storefront/checkout/addresses_view_model.rb', line 21

def show_shipping_address?
  order.requires_shipping?
end