Continue adding product variants

This commit is contained in:
2015-04-13 17:57:06 +02:00
parent 6746eaa383
commit 2b036368cf
32 changed files with 169 additions and 12224 deletions
@@ -24,6 +24,13 @@ module Suppliers
# POST /product_variants
# POST /product_variants.json
def create
@product_variant = ProductVariant.new(product_variant_params)
@product_variant.supplier = current_supplier
if @product_variant.save
render json: @product_variant
else
render json: {errors: @product_variant.errors}, status: :unprocessable_entity
end
end
# PUT /product_variants/1
@@ -44,13 +51,10 @@ module Suppliers
# DELETE /product_variants/1
# DELETE /product_variants/1.json
def destroy
@product_variant = ProductVariant.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
#@product_variant = ProductVariant.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
@product_variant = ProductVariant.find(params[:id])
@product_variant.destroy
respond_to do |format|
format.html { redirect_to suppliers_product_variants_url, notice: t('action.destroy.successfull', model: ProductVariant.model_name.human) }
format.json { head :no_content }
end
render json: {}
end
private
+4 -7
View File
@@ -6,9 +6,6 @@ module Users
# POST /user/orders
def create
# render json: {}, status: :unprocessable_entity and return unless params[:order].present? && params[:order][:product_orders].present?
# converted_order = params[:order][:product_orders].each_with_object({}){|po, o| o[po[:product_id]] = po[:quantity] }
converted_order = params[:order]
table_id = params[:order].delete('table_id')
if list = current_user.active_list
render json: {}, status: :not_acceptable and return unless list.supplier.open?
else
@@ -16,8 +13,8 @@ module Users
#NOTE: security bug here!!!!!!
# - supplier.open?
# - etc....
render json: {}, status: :unprocessable_entity and return unless table_id.present?
table = Table.find(table_id)
render json: {}, status: :unprocessable_entity and return unless params[:table_id].present?
table = Table.find(params[:table_id])
render json: {}, status: :not_acceptable and return unless table.supplier.open?
if table.occupied?
@@ -27,8 +24,8 @@ module Users
list = List.from_table( table, current_user )
end
order = list.place_order products: converted_order, user: current_user
render json: order, serializer: OrderSerializer
order = list.place_order product_orders: params[:product_orders], user: current_user
render json: order, serializer: OrderSerializer
#render nothing: true
end
end