Class: Spree::AddressesController
- Inherits:
-
StoreController
- Object
- StoreController
- Spree::AddressesController
- Defined in:
- app/controllers/spree/addresses_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
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 33 34 35 |
# File 'app/controllers/spree/addresses_controller.rb', line 7 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 elsif params[:from_modal].present? render turbo_stream: turbo_stream.update(:new_address_modal, partial: 'spree/account/addresses/new_address_modal', locals: { address: @address }), status: :unprocessable_entity else render action: 'new', status: :unprocessable_entity end end |
#destroy ⇒ Object
82 83 84 85 86 |
# File 'app/controllers/spree/addresses_controller.rb', line 82 def destroy @address.destroy redirect_to(spree.account_addresses_path, status: :see_other, notice: Spree.t('address_book.successfully_removed')) end |
#edit ⇒ Object
37 38 39 |
# File 'app/controllers/spree/addresses_controller.rb', line 37 def edit store_location(request.env['HTTP_REFERER']) end |
#new ⇒ Object
41 42 43 |
# File 'app/controllers/spree/addresses_controller.rb', line 41 def new @address = Spree::Address.new(country: current_store.default_country, user: try_spree_current_user) end |
#update ⇒ Object
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 76 77 78 79 80 |
# File 'app/controllers/spree/addresses_controller.rb', line 45 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(fallback_location: spree.account_addresses_path) end elsif params[:from_modal].present? render turbo_stream: turbo_stream.update("edit_address_modal_#{@address.id}", partial: 'spree/account/addresses/edit_address_modal', locals: { address: @address }), status: :unprocessable_entity else render :edit, status: :unprocessable_entity end end |