Module: Auth::Concerns::Shopping::CartControllerConcern

Extended by:
ActiveSupport::Concern
Included in:
Shopping::CartsController
Defined in:
app/controllers/auth/concerns/shopping/cart_controller_concern.rb

Instance Method Summary collapse

Instance Method Details

#bulk_createObject

GIVEN product ids, first create cart items, then CREATE CART

USED FROM THE DISCOUNT_OBJECT_SHOW PAGE



92
93
94
95
# File 'app/controllers/auth/concerns/shopping/cart_controller_concern.rb', line 92

def bulk_create
  ## first create cart items.
  ## this will bypass the controller and create problems.
end

#createObject

responds with an array of the created cart items. resource id is set only during create, never during update.



34
35
36
37
38
39
40
# File 'app/controllers/auth/concerns/shopping/cart_controller_concern.rb', line 34

def create
  check_for_create(@auth_shopping_cart)
  @auth_shopping_cart = add_owner_and_signed_in_resource(@auth_shopping_cart)
  @auth_shopping_cart.save
  @auth_shopping_cart.process_items
  respond_with @auth_shopping_cart
end

#destroyObject

will respond with nothing, or an array of cart_items that were removed, or whatever errors they have for not remvoing them.



56
57
58
59
60
61
# File 'app/controllers/auth/concerns/shopping/cart_controller_concern.rb', line 56

def destroy    
  check_for_destroy(@auth_shopping_cart)
  @auth_shopping_cart.prepare_cart
  @auth_shopping_cart.destroy
  respond_with @auth_shopping_cart
end

#editObject



78
79
80
# File 'app/controllers/auth/concerns/shopping/cart_controller_concern.rb', line 78

def edit

end

#indexObject

returns all the carts of the user. basically all his orders.



65
66
67
68
69
70
71
72
# File 'app/controllers/auth/concerns/shopping/cart_controller_concern.rb', line 65

def index
  query_clause = {:resource_id => lookup_resource.id.to_s}
  query_clause.merge({:personality_id => @auth_shopping_cart_params[:personality_id]}) if @auth_shopping_cart_params[:personality_id]
  @auth_shopping_carts = @auth_shopping_cart_class.where(query_clause)
  @auth_shopping_carts = @auth_shopping_carts.to_a
  @auth_shopping_carts.map{|c| c.prepare_cart}
  respond_with @auth_shopping_carts
end

#initialize_varsObject

if an id is provided in the permitted params then tries to find that in the database, and makes a new cart item out of it. if no id is provided then creates a new cart_item from the permitted params, but excluding the id key. if a collection i.e plural resources is present in the permitted_params and its also there in our auth resources, then create a resource class and resource symbol out of it and assign resource as in the comments.



12
13
14
15
16
17
18
19
20
# File 'app/controllers/auth/concerns/shopping/cart_controller_concern.rb', line 12

def initialize_vars
  
  instantiate_shopping_classes
 
  @auth_shopping_cart_params = permitted_params.fetch(:cart,{})
  
  @auth_shopping_cart = params[:id] ? @auth_shopping_cart_class.find_self(params[:id],current_signed_in_resource) : @auth_shopping_cart_class.new(@auth_shopping_cart_params)
      
end

#newObject



74
75
76
# File 'app/controllers/auth/concerns/shopping/cart_controller_concern.rb', line 74

def new

end

#showObject

override the as_json for cart_item, to show errors if there are any, otherwise just the id.



23
24
25
26
27
28
29
30
# File 'app/controllers/auth/concerns/shopping/cart_controller_concern.rb', line 23

def show
  
  not_found if @auth_shopping_cart.nil?
  @auth_shopping_cart.prepare_cart
  @auth_shopping_cart_items = @auth_shopping_cart.cart_items
  
  respond_with @auth_shopping_cart
end

#updateObject

always returns an empty array.



43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/auth/concerns/shopping/cart_controller_concern.rb', line 43

def update
  puts "------ came to update cart -----------"
  check_for_update(@auth_shopping_cart)
  @auth_shopping_cart.assign_attributes(@auth_shopping_cart_params)
  @auth_shopping_cart = add_owner_and_signed_in_resource(@auth_shopping_cart)
  puts "Called save."
  @auth_shopping_cart.save
  puts "Came to process items."
  @auth_shopping_cart.process_items
  respond_with @auth_shopping_cart
end