Class: Spree::FavoriteProductsController

Inherits:
StoreController
  • Object
show all
Defined in:
app/controllers/spree/favorite_products_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/spree/favorite_products_controller.rb', line 11

def create
  favorite = spree_current_user.favorites.new :product_id => params[:id]
  if @success = favorite.save
    @message = "Product has been successfully marked as favorite"
  else
    @message = favorite.errors.full_messages.to_sentence
  end
  respond_to do |format|
    format.js
  end
end

#destroyObject



23
24
25
26
27
# File 'app/controllers/spree/favorite_products_controller.rb', line 23

def destroy
  if @favorite
    @success = @favorite.destroy
  end
end

#indexObject



7
8
9
# File 'app/controllers/spree/favorite_products_controller.rb', line 7

def index
  @favorite_products = spree_current_user.favorite_products.page(params[:page]).per(Spree::Config.favorite_products_per_page)
end