Class: Spree::CheckoutController
- Inherits:
-
StoreController
- Object
- BaseController
- StoreController
- Spree::CheckoutController
- Includes:
- BaseHelper, CheckoutAnalyticsHelper, CheckoutHelper
- Defined in:
- app/controllers/spree/checkout_controller.rb
Instance Method Summary collapse
-
#apply_coupon_code ⇒ Object
PATCH /checkout/<token>/coupon_code.
- #apply_store_credit ⇒ Object
-
#complete ⇒ Object
GET /checkout/<token>/complete.
-
#edit ⇒ Object
GET /checkout/<token>.
-
#remove_coupon_code ⇒ Object
DELETE /checkout/<token>/coupon_code.
-
#remove_missing_items ⇒ Object
DELETE /checkout/<token>/remove_missing_items.
- #remove_store_credit ⇒ Object
-
#update ⇒ Object
PATCH /checkout/<token> Updates the order and advances to the next state (when possible.) Passing params = true only updates order without the need to advance to the next state.
Methods included from CheckoutAnalyticsHelper
#clean_analytics_session, #clear_checkout_completed_session, #coupon_tracking_params, #order_tracking_params, #track_checkout_completed, #track_checkout_entered_email, #track_checkout_started, #track_checkout_step_completed, #track_checkout_step_viewed, #track_payment_info_entered
Methods included from CheckoutHelper
#already_have_an_account?, #can_use_store_credit_on_checkout?, #checkout_available_payment_methods, #checkout_payment_sources, #checkout_progress, #checkout_started?, #quick_checkout_enabled?
Methods inherited from StoreController
#current_taxon, #default_products_sort, #permitted_products_params, #products_filters_params, #render_404_if_store_not_exists, #store_filter_names, #store_filter_names_hash
Methods included from AnalyticsHelper
#analytics_event_handlers, #track_event, #unsupported_event?, #visitor_id
Methods included from WishlistHelper
Methods included from PasswordProtected
Methods included from StorefrontHelper
#as_aspect_ratio, #page_description, #page_image, #paths_equal?, #render_storefront_partials, #show_account_pane?, #spree_storefront_base_cache_key, #spree_storefront_base_cache_scope, #svg_country_icon, #tailwind_classes_for
Methods included from ThemeConcern
#default_url_options, #set_theme_view_paths
Instance Method Details
#apply_coupon_code ⇒ Object
PATCH /checkout/<token>/coupon_code
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/controllers/spree/checkout_controller.rb', line 90 def apply_coupon_code @order.coupon_code = params[:coupon_code] @result = coupon_handler.new(@order, { email: params[:promotion_email] }).apply track_event('coupon_entered', coupon_tracking_params) if @result&.successful? track_event('coupon_applied', coupon_tracking_params) else track_event('coupon_denied', coupon_tracking_params) end respond_to do |format| format.turbo_stream format.html do if @result&.successful? flash[:success] = 'Coupon applied successfully' else flash[:error] = @result&.error end redirect_to spree.checkout_path(@order.token) end end end |
#apply_store_credit ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'app/controllers/spree/checkout_controller.rb', line 128 def apply_store_credit add_store_credit_service.call(order: @order) respond_to do |format| format.turbo_stream format.html { redirect_to spree.checkout_path(@order.token) } end end |
#complete ⇒ Object
GET /checkout/<token>/complete
85 86 87 |
# File 'app/controllers/spree/checkout_controller.rb', line 85 def complete clear_order_token end |
#edit ⇒ Object
GET /checkout/<token>
35 36 37 |
# File 'app/controllers/spree/checkout_controller.rb', line 35 def edit track_checkout_step_viewed end |
#remove_coupon_code ⇒ Object
DELETE /checkout/<token>/coupon_code
116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/controllers/spree/checkout_controller.rb', line 116 def remove_coupon_code @result = coupon_handler.new(@order).remove(params[:coupon_code] || params[:gift_card]) track_event('coupon_removed', coupon_tracking_params) if @result.successful? params.delete(:coupon_code) respond_to do |format| format.turbo_stream format.html { redirect_to spree.checkout_path(@order.token) } end end |
#remove_missing_items ⇒ Object
DELETE /checkout/<token>/remove_missing_items
72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/spree/checkout_controller.rb', line 72 def remove_missing_items line_items_to_remove = @order.line_items.where(id: params[:line_item_ids]) ApplicationRecord.transaction do line_items_to_remove.each do |line_item| remove_line_item_service.call(order: @order, line_item: line_item) end end redirect_to spree.checkout_path(@order.token) end |
#remove_store_credit ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'app/controllers/spree/checkout_controller.rb', line 137 def remove_store_credit remove_store_credit_service.call(order: @order) respond_to do |format| format.turbo_stream format.html { redirect_to spree.checkout_path(@order.token) } end end |
#update ⇒ Object
PATCH /checkout/<token> Updates the order and advances to the next state (when possible.) Passing params = true only updates order without the need to advance to the next state.
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 |
# File 'app/controllers/spree/checkout_controller.rb', line 42 def update @previous_state = @order.state if @order.update_from_params(params, permitted_checkout_attributes, request.headers.env) track_checkout_entered_email track_payment_info_entered track_checkout_step_completed unless params[:do_not_advance] @order.temporary_address = !params[:save_user_address] unless @order.next return if @order.address? && @order.line_items_without_shipping_rates.any? && turbo_stream_request? # render update trubo_stream flash[:error] = @order.errors..values.flatten.join("\n") redirect_to(spree.checkout_state_path(@order.token, @order.state)) && return end if @order.completed? track_checkout_completed redirect_to spree.checkout_complete_path(@order.token), status: :see_other else redirect_to spree.checkout_state_path(@order.token, @order.state) end end else render :edit, status: :unprocessable_entity end end |