I am implementing the functionality of shopping cart.
The problem is there is a textbox for updating quantity of the product
on the same page where the products are displayed after ading in the
cart. By default the quantity is one and after that the user can change
the quantity of the product.
Its like:
Qty Product Price Total
textbox. abc $10.00 $10.00 remove product
Total: $10.00
My problem is that I am not able to update the implement this
functionality. Can anyone give me some idea of how to implement it??
I am implementing the functionality of shopping cart.
The problem is there is a textbox for updating quantity of the product
on the same page where the products are displayed after ading in the
cart. By default the quantity is one and after that the user can change
the quantity of the product.
Its like:
Qty Product Price Total
textbox. abc $10.00 $10.00 remove product
Total: $10.00 update button for quantity.
My problem is that I am not able to update the implement this
functionality. Can anyone give me some idea of how to implement it??
Thanks,
Ruchita S…
I have written a code like:
store_controller.rb
def update @quantity = request.parameters[:quantity] @product = request.parameters[:productid]
quantity = @quantity
#productname=@product
product = @product @cart = find_cart @cart.add_product(product,quantity)
render :action => ‘display_cart’
end
you’re just setting @product to a string rather than using Product.find
Fred
Hi,
The code is working now but only for the first row of the table i.e only
for the first product.
My code is:
Store_controller.rb
def add_to_cart
product = Product.find(params[:id])
quantity = 1 @cart = find_cart @cart.add_product(product,quantity)
redirect_to(:action =>‘display_cart’)
rescue
logger.error(“Attempt to access invalid product #{params[:id]}”)
flash[:notice] =‘Invalid product’
redirect_to(:action => ‘index’)
end
In controller
def update
params[:items].each do|id,qty|
product=Product.find_by_id(id)
end
In params[:items] in am getting parameters like {“items”=>{“35”=>“1”,
“36”=>“9”}},
but when i am using this in my controller it is showing the last
selected product.
Can anyone tell me how to get the all parameters from
params[:items].each do |id,qty|.
I am implementing the functionality of shopping cart. The problem is
there is a textbox for updating quantity of the product on the same page
where the products are displayed after adding in the cart. By default
the quantity is one and after that the user can change the quantity of
the product by changing the quantity in the text field and clicking the
update button. The quantity is updating but only for the first product
in the table. Not able to get the id of the selected product for
updating the quantity.