Class: Spree::WishedProductsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/wished_products_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @wished_product = Spree::WishedProduct.new(params[:wished_product])
  @wishlist = current_user.wishlist

  if @wishlist.include? params[:wished_product][:variant_id]
    @wished_product = @wishlist.wished_products.detect {|wp| wp.variant_id == params[:wished_product][:variant_id].to_i }
  else
    @wished_product.wishlist = current_user.wishlist
    @wished_product.save
  end

  respond_with(@wished_product) do |format|
    format.html { redirect_to wishlist_url(@wishlist) }
  end
end

#destroyObject



29
30
31
32
33
34
35
36
# File 'app/controllers/spree/wished_products_controller.rb', line 29

def destroy
  @wished_product = Spree::WishedProduct.find(params[:id])
  @wished_product.destroy

  respond_with(@wished_product) do |format|
    format.html { redirect_to wishlist_url(@wished_product.wishlist) }
  end
end

#updateObject



20
21
22
23
24
25
26
27
# File 'app/controllers/spree/wished_products_controller.rb', line 20

def update
  @wished_product = Spree::WishedProduct.find(params[:id])
  @wished_product.update_attributes(params[:wished_product])

  respond_with(@wished_product) do |format|
    format.html { redirect_to wishlist_url(@wished_product.wishlist) }
  end
end