Class: Spree::Account::WishedItemsController

Inherits:
BaseController show all
Defined in:
app/controllers/spree/account/wished_items_controller.rb

Instance Method Summary collapse

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 Spree::AnalyticsHelper

#analytics_event_handlers, #track_event, #unsupported_event?, #visitor_id

Methods included from WishlistHelper

#current_wishlist

Methods included from PasswordProtected

#redirect_to_password

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

#createObject

POST /account/wished_items



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/spree/account/wished_items_controller.rb', line 5

def create
  variant = current_store.variants.find(wished_item_params[:variant_id])
  @wished_item = current_wishlist.wished_items.build(variant: variant)

  if @wished_item.save
    track_event('product_added_to_wishlist', variant: variant)
  else
    flash.now[:error] = @wished_item.errors.full_messages.to_sentence.strip
  end

  respond_to do |format|
    format.html { redirect_to spree. }
    format.turbo_stream
  end
end

#destroyObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/spree/account/wished_items_controller.rb', line 21

def destroy
  @wished_item = current_wishlist.wished_items.find_by!(variant_id: params[:id])

  if @wished_item.destroy
    track_event('product_removed_from_wishlist', variant: @wished_item.variant)
  else
    flash.now[:error] = Spree.t('storefront.wished_items.remove_error')
  end

  respond_to do |format|
    format.html { redirect_to spree. }
    format.turbo_stream
  end
end