This commit is contained in:
Nicolas Bally 2017-10-16 00:21:22 +02:00
parent c87d5445a4
commit 853ade84ae
2 changed files with 15 additions and 4 deletions

View File

@ -6,20 +6,28 @@ class Public::ProductOrderProductsController < ApplicationController
#clear params #clear params
params[:product_order_product][:product_size_id] = nil if params[:product_order_product][:product_size_id] == "" params[:product_order_product][:product_size_id] = nil if params[:product_order_product][:product_size_id] == ""
params[:product_order_product][:product_option_id] = nil if params[:product_order_product][:product_option_id] == "" params[:product_order_product][:product_option_id] = nil if params[:product_order_product][:product_option_id] == ""
@product = Product.find(params[:product_order_product][:product_id])
# Trying to retreive an existing pop in the current cart # Trying to retreive an existing pop in the current cart
existing_product_order_product = @product_order.product_order_products.where(:product_id => params[:product_order_product][:product_id], :product_size_id => params[:product_order_product][:product_size_id], :product_option_id => params[:product_order_product][:product_option_id]).first existing_product_order_product = @product_order.product_order_products.where(:product_id => params[:product_order_product][:product_id], :product_size_id => params[:product_order_product][:product_size_id], :product_option_id => params[:product_order_product][:product_option_id]).first
# if the pop exists in the current cart, just increase the quantity # if the pop exists in the current cart, just increase the quantity
if existing_product_order_product if existing_product_order_product
existing_product_order_product.qty += 1 if [1,2].include?(@product.id)
existing_product_order_product.qty += 10
else
existing_product_order_product.qty += 1
end
existing_product_order_product.verify_qty existing_product_order_product.verify_qty
existing_product_order_product.save existing_product_order_product.save
else else
@product_order_product = ProductOrderProduct.new(params.require(:product_order_product).permit(:product_id, :product_size_id, :product_option_id)) @product_order_product = ProductOrderProduct.new(params.require(:product_order_product).permit(:product_id, :product_size_id, :product_option_id))
@product_order_product.qty = 1 if [1,2].include?(@product.id)
@product_order_product.qty = 10
else
@product_order_product.qty = 1
end
@product_order_product.save @product_order_product.save

View File

@ -20,7 +20,10 @@
-if !@recap -if !@recap
.qty_form .qty_form
= form_for [:public, product_order_product] do |f| = form_for [:public, product_order_product] do |f|
= f.text_field :qty, :style => "width:30px;" -if [1,2].include?(product_order_product.product_id)
= f.select :qty, [10,20,30,40,50,60,70,80,90,100], {:style => "width:30px;"}
-else
= f.text_field :qty, :style => "width:30px;"
= f.submit "Mettre à jour" = f.submit "Mettre à jour"
=link_to ic(:"trash-o"), public_product_order_product_path(:id => product_order_product.id, :product_order_product => {:qty => 0}), :method => :put =link_to ic(:"trash-o"), public_product_order_product_path(:id => product_order_product.id, :product_order_product => {:qty => 0}), :method => :put
-else -else