Module: Comable::Checkout

Extended by:
ActiveSupport::Concern
Included in:
Order
Defined in:
app/models/concerns/comable/checkout.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#allow_cancel?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'app/models/concerns/comable/checkout.rb', line 83

def allow_cancel?
  !shipments.with_state(:completed).exists?
end

#allow_return?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'app/models/concerns/comable/checkout.rb', line 87

def allow_return?
  !allow_cancel?
end

#delivery_required?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'app/models/concerns/comable/checkout.rb', line 71

def delivery_required?
  ship_address.nil? || ship_address.new_record?
end

#orderer_required?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/concerns/comable/checkout.rb', line 67

def orderer_required?
  bill_address.nil? || bill_address.new_record?
end

#payment_required?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'app/models/concerns/comable/checkout.rb', line 75

def payment_required?
  Comable::PaymentMethod.exists? && payment.nil?
end

#shipment_required?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'app/models/concerns/comable/checkout.rb', line 79

def shipment_required?
  Comable::ShipmentMethod.activated.exists? && shipments.empty?
end

#stated?(target_state) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
65
# File 'app/models/concerns/comable/checkout.rb', line 61

def stated?(target_state)
  target_state_index = self.class.state_names.index(target_state.to_sym)
  current_state_index = self.class.state_names.index(state_name)
  target_state_index < current_state_index
end