Module: Auth::Concerns::Shopping::CartItemControllerConcern
- Extended by:
- ActiveSupport::Concern
- Included in:
- Shopping::CartItemsController
- Defined in:
- app/controllers/auth/concerns/shopping/cart_item_controller_concern.rb
Instance Method Summary collapse
-
#create ⇒ Object
expects the product id, resource_id is the logged in resource, and quantity.
-
#create_multiple ⇒ Object
BULK ITEM CREATE.
-
#destroy ⇒ Object
can be removed.
-
#index ⇒ Object
should show those cart items which do not have a parent_id.
-
#initialize_vars ⇒ Object
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.
-
#permitted_params ⇒ Object
this permitted params is overridden in the dummy app, and as a result throws unpermitted parameters for the daughter app parameters, even though they are subsequently permitted, since super is called first.
- #show ⇒ Object
-
#update ⇒ Object
only permits the quantity to be changed, transaction id is internally assigned and can never be changed by the external world.
Instance Method Details
#create ⇒ Object
expects the product id, resource_id is the logged in resource, and quantity
37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/auth/concerns/shopping/cart_item_controller_concern.rb', line 37 def create ##ensure that the cart item is new check_for_create(@auth_shopping_cart_item) @auth_shopping_cart_item = add_owner_and_signed_in_resource(@auth_shopping_cart_item) @auth_shopping_cart_item.save respond_with @auth_shopping_cart_item end |
#create_multiple ⇒ Object
BULK ITEM CREATE. This is utilized to create multiple cart items, first , then redirects to create a cart, with those cart items.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/controllers/auth/concerns/shopping/cart_item_controller_concern.rb', line 91 def create_multiple #puts "came to create multiple." #puts "params are:" #puts params.to_s @auth_shopping_cart_items = [] @auth_shopping_cart = @auth_shopping_cart_class.new(:add_cart_item_ids => [], :remove_cart_item_ids => []) #puts "auth shopping discount is:" #puts @auth_shopping_discount.to_s @auth_shopping_cart.discount_id = @auth_shopping_discount.id.to_s #puts "is it is a new record" #puts @auth_shopping_discount.new_record? unless @auth_shopping_discount.new_record? @auth_shopping_discount.product_ids.each do |product_id| if product = @auth_shopping_product_class.find(product_id) cart_item = create_cart_item_from_product(product) cart_item = add_owner_and_signed_in_resource(cart_item) if cart_item.save == true @auth_shopping_cart_items << cart_item @auth_shopping_cart.add_cart_item_ids << cart_item.id.to_s else puts "the errors trying to save the item" puts cart_item.errors..to_s end end end else end end |
#destroy ⇒ Object
can be removed. responds with 204, and empty response body, if all is ok.
74 75 76 77 78 79 80 |
# File 'app/controllers/auth/concerns/shopping/cart_item_controller_concern.rb', line 74 def destroy not_found if @auth_shopping_cart_item.nil? puts "the accepted is:" puts @auth_shopping_cart_item.accepted.to_s @auth_shopping_cart_item.destroy respond_with @auth_shopping_cart_item end |
#index ⇒ Object
should show those cart items which do not have a parent_id. since these are the pending cart items. all remaining cart items have already been assigned to carts
66 67 68 69 |
# File 'app/controllers/auth/concerns/shopping/cart_item_controller_concern.rb', line 66 def index @auth_shopping_cart_items = @auth_shopping_cart_item_class.find_cart_items({:resource => lookup_resource}).page 1 respond_with @auth_shopping_cart_items end |
#initialize_vars ⇒ Object
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.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/auth/concerns/shopping/cart_item_controller_concern.rb', line 18 def initialize_vars instantiate_shopping_classes @auth_shopping_discount_object_params = permitted_params.fetch(:discount,{}) if !@auth_shopping_discount_object_params.blank? @auth_shopping_discount = params[:id] ? @auth_shopping_discount_class.find(params[:id]) : @auth_shopping_discount_class.new(@auth_shopping_discount_object_params) end @auth_shopping_cart_item_params = permitted_params.fetch(:cart_item,{}) @auth_shopping_cart_item = params[:id] ? @auth_shopping_cart_item_class.find_self(params[:id],current_signed_in_resource) : @auth_shopping_cart_item_class.new(@auth_shopping_cart_item_params) end |
#permitted_params ⇒ Object
this permitted params is overridden in the dummy app, and as a result throws unpermitted parameters for the daughter app parameters, even though they are subsequently permitted, since super is called first.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'app/controllers/auth/concerns/shopping/cart_item_controller_concern.rb', line 131 def permitted_params if action_name.to_s == "update" && !current_signed_in_resource.is_admin? params.permit({cart_item: [:discount_code,:quantity]},:id) elsif action_name.to_s == "create_multiple" params.permit({discount: [:id, {:product_ids => []}]}) else params.permit({cart_item: [:product_id,:discount_code,:quantity]},:id) end end |
#show ⇒ Object
58 59 60 61 |
# File 'app/controllers/auth/concerns/shopping/cart_item_controller_concern.rb', line 58 def show not_found if @auth_shopping_cart_item.nil? respond_with @auth_shopping_cart_item end |
#update ⇒ Object
only permits the quantity to be changed, transaction id is internally assigned and can never be changed by the external world.
49 50 51 52 53 54 55 56 |
# File 'app/controllers/auth/concerns/shopping/cart_item_controller_concern.rb', line 49 def update check_for_update(@auth_shopping_cart_item) @auth_shopping_cart_item.assign_attributes(@auth_shopping_cart_item_params) @auth_shopping_cart_item = add_owner_and_signed_in_resource(@auth_shopping_cart_item) @auth_shopping_cart_item.save puts @auth_shopping_cart_item.errors..to_s respond_with @auth_shopping_cart_item end |