Class: Workarea::Checkout::Steps::Addresses

Inherits:
Base
  • Object
show all
Defined in:
app/models/workarea/checkout/steps/addresses.rb

Instance Attribute Summary

Attributes inherited from Base

#checkout

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Workarea::Checkout::Steps::Base

Instance Method Details

#complete?Boolean

Whether this checkout step is finished. Requires:

  • order to be valid

  • payment address to be valid

  • shipping address to be valid if requires shipping

Used for redirecting and summary display in checkout.

Returns:

  • (Boolean)


46
47
48
# File 'app/models/workarea/checkout/steps/addresses.rb', line 46

def complete?
  order.valid? && billing_complete? && shipping_complete?
end

#default_shipping_optionShipping::Option

The default shipping option that will be assigned to this checkout when updating. Retrieved from Workarea::Checkout::ShippingOptions

Returns:

  • (Shipping::Option)


11
12
13
# File 'app/models/workarea/checkout/steps/addresses.rb', line 11

def default_shipping_option
  shipping_options.first
end

#update(params = {}) ⇒ Boolean

Update the addresses step of checkout. Includes:

  • email address (from params or user)

  • shipping address (if shippable)

  • shipping service (assigning a default if none exists and shippable)

  • billing address

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :email (String)

    The email for the order

  • :shipping_address (Hash)

    Shipping address attributes (not set if blank)

  • :billing_address (Hash)

    Payment address attributes (not set if blank)

Returns:

  • (Boolean)

    whether the update succeeded (order and payment were saved)



28
29
30
31
32
33
34
# File 'app/models/workarea/checkout/steps/addresses.rb', line 28

def update(params = {})
  set_order_email(params)
  set_shipping_address(params)
  set_payment_address(params)

  persist_update
end