Class: Spree::AddressesController
Instance Method Summary
collapse
#current_taxon, #default_products_sort, #permitted_products_params, #products_filters_params, #render_404_if_store_not_exists, #store_filter_names, #store_filter_names_hash
#analytics_event_handlers, #track_event, #unsupported_event?
#current_wishlist
#redirect_to_password
#as_aspect_ratio, #page_description, #page_image, #paths_equal?, #render_storefront_partials, #show_account_pane?, #svg_country_icon, #tailwind_classes_for
#default_url_options, #set_theme_view_paths
Instance Method Details
#create ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/controllers/spree/addresses_controller.rb', line 6
def create
order_token = params[:order_token]
@order = current_store.orders.incomplete.not_canceled.find_by(token: order_token) if order_token.present?
result = create_service.call(
user: try_spree_current_user,
address_params: address_params,
default_billing: params[:default_billing].to_b,
default_shipping: params[:default_shipping].to_b,
order: @order
)
@address = result.value
if result.success?
if @order.present?
respond_to do |format|
format.html { redirect_to spree.checkout_state_path(order_token, 'address') }
format.turbo_stream do
render turbo_stream: turbo_stream.update('checkout_content', partial: 'spree/checkout/address', locals: { order: @order })
end
end
else
redirect_to spree.account_addresses_path, notice: Spree.t('address_book.successfully_created')
end
else
render action: 'new', status: :unprocessable_entity
end
end
|
#destroy ⇒ Object
77
78
79
80
81
|
# File 'app/controllers/spree/addresses_controller.rb', line 77
def destroy
@address.destroy
redirect_to(spree.account_addresses_path, status: :see_other, notice: Spree.t('address_book.successfully_removed'))
end
|
#edit ⇒ Object
34
35
36
|
# File 'app/controllers/spree/addresses_controller.rb', line 34
def edit
store_location(request.env['HTTP_REFERER'])
end
|
#new ⇒ Object
38
39
40
|
# File 'app/controllers/spree/addresses_controller.rb', line 38
def new
@address = Spree::Address.new(country: current_store.default_country, user: try_spree_current_user)
end
|
#update ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'app/controllers/spree/addresses_controller.rb', line 42
def update
@order = if params[:checkout].present?
current_store.orders.incomplete.not_canceled.find_by(token: params[:checkout])
else
try_spree_current_user.orders.incomplete.not_canceled.where(ship_address_id: @address.id).
or(try_spree_current_user.orders.incomplete.not_canceled.where(bill_address_id: @address.id)).take
end
result = update_service.call(
address: @address,
address_params: address_params,
default_billing: params[:default_billing].to_b,
default_shipping: params[:default_shipping].to_b,
order: @order,
address_changes_except: address_changes_except
)
@address = result.value
if result.success?
flash[:notice] = Spree.t('address_book.successfully_updated') unless turbo_frame_request?
if params[:checkout].present?
respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.update('checkout_content', partial: 'spree/checkout/address', locals: { order: @order })
end
format.html { redirect_to spree.checkout_state_path(@order.token, 'address') }
end
else
redirect_back_or_default(spree.account_addresses_path)
end
else
render :edit, status: :unprocessable_entity
end
end
|