mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Refactor setting default addresses
This commit is contained in:
@@ -63,18 +63,26 @@ class CheckoutController < Spree::CheckoutController
|
||||
|
||||
def set_default_bill_address
|
||||
if params[:order][:default_bill_address] == 'YES'
|
||||
new_bill_address = @order.bill_address.clone
|
||||
spree_current_user.set_bill_address(new_bill_address)
|
||||
@order.customer.bill_address.andand.update_attributes(new_bill_address.attributes)
|
||||
new_bill_address = @order.bill_address.clone.attributes
|
||||
|
||||
user_bill_address_id = spree_current_user.bill_address.andand.id
|
||||
spree_current_user.update_attributes(bill_address_attributes: new_bill_address.merge('id' => user_bill_address_id))
|
||||
|
||||
customer_bill_address_id = @order.customer.bill_address.andand.id
|
||||
@order.customer.update_attributes(bill_address_attributes: new_bill_address.merge('id' => customer_bill_address_id))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def set_default_ship_address
|
||||
if params[:order][:default_ship_address] == 'YES'
|
||||
new_ship_address = @order.ship_address.clone
|
||||
spree_current_user.set_ship_address(new_ship_address)
|
||||
@order.customer.ship_address.andand.update_attributes(new_ship_address.attributes)
|
||||
new_ship_address = @order.ship_address.clone.attributes
|
||||
|
||||
user_ship_address_id = spree_current_user.ship_address.andand.id
|
||||
spree_current_user.update_attributes!(ship_address_attributes: new_ship_address.merge('id' => user_ship_address_id))
|
||||
|
||||
customer_ship_address_id = @order.customer.ship_address.andand.id
|
||||
@order.customer.update_attributes(ship_address_attributes: new_ship_address.merge('id' => customer_ship_address_id))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -14,7 +14,10 @@ Spree.user_class.class_eval do
|
||||
|
||||
accepts_nested_attributes_for :enterprise_roles, :allow_destroy => true
|
||||
|
||||
attr_accessible :enterprise_ids, :enterprise_roles_attributes, :enterprise_limit
|
||||
accepts_nested_attributes_for :bill_address
|
||||
accepts_nested_attributes_for :ship_address
|
||||
|
||||
attr_accessible :enterprise_ids, :enterprise_roles_attributes, :enterprise_limit, :bill_address_attributes, :ship_address_attributes
|
||||
after_create :send_signup_confirmation
|
||||
|
||||
validate :limit_owned_enterprises
|
||||
@@ -76,22 +79,6 @@ Spree.user_class.class_eval do
|
||||
data_array.sort! { |a, b| b.distributed_orders.length <=> a.distributed_orders.length }
|
||||
end
|
||||
|
||||
def set_bill_address(address)
|
||||
if self.bill_address
|
||||
self.bill_address.update_attributes(address.clone.attributes)
|
||||
else
|
||||
self.update_attribute(:bill_address, address.clone)
|
||||
end
|
||||
end
|
||||
|
||||
def set_ship_address(address)
|
||||
if self.ship_address
|
||||
self.ship_address.update_attributes(address.clone.attributes)
|
||||
else
|
||||
self.update_attribute(:ship_address, address.clone)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def limit_owned_enterprises
|
||||
|
||||
Reference in New Issue
Block a user