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



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

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



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

def destroy
  if @product_id = Spree::Product.where(:permalink => params[:id]).first.try(:id)
    @favorite_product = Spree::Favorite.where("user_id = ? and product_id = ?", spree_current_user.id, @product_id).first
    @success = @favorite_product.try(:destroy)
  else
    @success = false
  end
end

#indexObject



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

def index
  @favorite_products = spree_current_user.favorite_products
end