Class: Workarea::Storefront::Checkout::AddressesViewModel
- Inherits:
-
ApplicationViewModel
- Object
- ApplicationViewModel
- Workarea::Storefront::Checkout::AddressesViewModel
- Includes:
- Workarea::Storefront::CheckoutContent
- Defined in:
- app/view_models/workarea/storefront/checkout/addresses_view_model.rb
Instance Method Summary collapse
-
#billing_address ⇒ Workarea::Address
The current billing address for the order.
-
#default_billing_address_id ⇒ User::SavedAddress?
Return the default billing address id of the current user.
-
#default_shipping_address_id ⇒ User::SavedAddress?
Return the default shipping address id of the current user.
-
#saved_addresses ⇒ Array<User::SavedAddress>
Returns an array of saved addresses for the current user.
-
#shipping_address ⇒ Shipping::Address
The current shipping address for the order.
-
#show_email_field? ⇒ Boolean
Whether to show the email field.
-
#show_shipping_address? ⇒ Boolean
Whether to show the shipping address.
Methods included from Workarea::Storefront::CheckoutContent
Methods included from DisplayContent
#browser_title, #content, #content_blocks, #content_blocks_for, #meta_description, #open_graph_asset
Instance Method Details
#billing_address ⇒ Workarea::Address
The current billing address for the order. Used for errors and form fields.
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_id ⇒ User::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.
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_id ⇒ User::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.
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_addresses ⇒ Array<User::SavedAddress>
Returns an array of saved addresses for the current user. Used as HTML data for JS address-selection functionality.
69 70 71 |
# File 'app/view_models/workarea/storefront/checkout/addresses_view_model.rb', line 69 def saved_addresses user.try(:addresses) end |
#shipping_address ⇒ Shipping::Address
The current shipping address for the order. Used for errors and form fields.
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.
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).
21 22 23 |
# File 'app/view_models/workarea/storefront/checkout/addresses_view_model.rb', line 21 def show_shipping_address? order.requires_shipping? end |