Class: Refinery::Addresses::Address
- Inherits:
-
Core::BaseModel
- Object
- Core::BaseModel
- Refinery::Addresses::Address
- Defined in:
- app/models/refinery/addresses/address.rb
Class Method Summary collapse
-
.update_addresses(parent_obj, params) ⇒ Object
—————————————————————————.
Class Method Details
.update_addresses(parent_obj, params) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/refinery/addresses/address.rb', line 21 def self.update_addresses(parent_obj, params ) # if bill exists; update with parameters # else create bill if (bill_address = parent_obj.billing_address) bill_address.update_attributes( params[:billing_address] ) else bill_address = parent_obj.addresses.create( params[:billing_address].merge( { :is_billing => true } ) ) end # if..then..else billing address setup # continue if error free if bill_address.errors.empty? # does customer wants same address for both ? ship_params = ( params[:use_billing] ? params[:billing_address] : params[:shipping_address] ).merge( { :is_billing => false } ) if (ship_address = parent_obj.shipping_address) ship_address.update_attributes( ship_params ) else ship_address = parent_obj.addresses.create( ship_params ) end # if..then..else shiping address setup else # need placeholder for re-editing the order ship_address = parent_obj.addresses.build( params[:shipping_address] ) end # if no bill address errors return bill_address, ship_address end |