Add possibility to remove products from the offer without breaking stuff
This commit is contained in:
parent
652c598722
commit
b7f40f8832
|
@ -8,7 +8,7 @@ class OrdersController < ApplicationController
|
||||||
init
|
init
|
||||||
@order = @user.orders.build
|
@order = @user.orders.build
|
||||||
|
|
||||||
products = (@user.products.select("products.*", "sum(order_items.count) as count").group(:product_id).order("count desc") | Product.all)
|
products = (@user.products.for_sale.select("products.*", "sum(order_items.count) as count").group(:product_id).order("count desc") | Product.for_sale)
|
||||||
@order.g_order_items products
|
@order.g_order_items products
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ class OrdersController < ApplicationController
|
||||||
slack_notification(@user, message)
|
slack_notification(@user, message)
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
else
|
else
|
||||||
@order.g_order_items Product.all
|
@order.g_order_items Product.for_sale
|
||||||
render 'new'
|
render 'new'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -57,6 +57,6 @@ class ProductsController < ApplicationController
|
||||||
private
|
private
|
||||||
|
|
||||||
def product_params
|
def product_params
|
||||||
params.require(:product).permit(:name, :price, :avatar, :category, :stock)
|
params.require(:product).permit(:name, :price, :avatar, :category, :stock, :deleted)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -49,7 +49,7 @@ class UsersController < ApplicationController
|
||||||
@user = User.find(params[:user_id])
|
@user = User.find(params[:user_id])
|
||||||
@dagschotel = @user.dagschotel
|
@dagschotel = @user.dagschotel
|
||||||
|
|
||||||
@products = Product.all
|
@products = Product.for_sale
|
||||||
@categories = Product.categories
|
@categories = Product.categories
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ class UsersController < ApplicationController
|
||||||
@user = User.find(params[:user_id])
|
@user = User.find(params[:user_id])
|
||||||
@user.dagschotel = Product.find(params[:product_id])
|
@user.dagschotel = Product.find(params[:product_id])
|
||||||
|
|
||||||
@products = Product.all
|
@products = Product.for_sale
|
||||||
@categories = Product.categories
|
@categories = Product.categories
|
||||||
|
|
||||||
if @user.save
|
if @user.save
|
||||||
|
|
|
@ -48,7 +48,11 @@ class FormattedFormBuilder < ActionView::Helpers::FormBuilder
|
||||||
label_content = block_given? ? capture(&block) : options[:label]
|
label_content = block_given? ? capture(&block) : options[:label]
|
||||||
|
|
||||||
content_tag :div, class: control_wrapper_class do
|
content_tag :div, class: control_wrapper_class do
|
||||||
checkbox + " " + label(name, label_content)
|
if options[:skip_label]
|
||||||
|
checkbox
|
||||||
|
else
|
||||||
|
checkbox + " " + label(name, label_content)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,8 @@ class Product < ActiveRecord::Base
|
||||||
presence: true,
|
presence: true,
|
||||||
content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
|
content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
|
||||||
|
|
||||||
|
scope :for_sale, -> { where deleted: false }
|
||||||
|
|
||||||
def price
|
def price
|
||||||
self.price_cents / 100.0
|
self.price_cents / 100.0
|
||||||
end
|
end
|
||||||
|
@ -36,4 +38,8 @@ class Product < ActiveRecord::Base
|
||||||
if value.is_a? String then value.sub!(',', '.') end
|
if value.is_a? String then value.sub!(',', '.') end
|
||||||
self.price_cents = (value.to_f * 100).to_int
|
self.price_cents = (value.to_f * 100).to_int
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def out_of_sale
|
||||||
|
update_attribute :deleted, true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
<td><%= f.text_field :name, skip_label: true %></td>
|
<td><%= f.text_field :name, skip_label: true %></td>
|
||||||
<td><%= f.price_field :price, skip_label: true %></td>
|
<td><%= f.price_field :price, skip_label: true %></td>
|
||||||
<td><%= f.number_field :stock, skip_label: true %></td>
|
<td><%= f.number_field :stock, skip_label: true %></td>
|
||||||
|
<td><%= f.check_box :deleted, skip_label: true %></td>
|
||||||
<td><%= f.button "Update", class: "btn btn-primary" %></td>
|
<td><%= f.button "Update", class: "btn btn-primary" %></td>
|
||||||
<%= javascript_tag do %>
|
<%= javascript_tag do %>
|
||||||
var id = "#edit_<%= dom_id(product) %>";
|
var id = "#edit_<%= dom_id(product) %>";
|
||||||
|
|
|
@ -3,5 +3,6 @@
|
||||||
<td><%= product.name %></td>
|
<td><%= product.name %></td>
|
||||||
<td><%= euro(product.price) %></td>
|
<td><%= euro(product.price) %></td>
|
||||||
<td><%= product.stock %></td>
|
<td><%= product.stock %></td>
|
||||||
|
<td><span class="glyphicon <%= product.deleted ? "glyphicon-check" : "glyphicon-unchecked" %>"></span></td>
|
||||||
<td><%= button_to "Edit", edit_product_path(product), method: :get, class: "btn btn-default", remote: true %></td>
|
<td><%= button_to "Edit", edit_product_path(product), method: :get, class: "btn btn-default", remote: true %></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Price</th>
|
<th>Price</th>
|
||||||
<th>Stock</th>
|
<th>Stock</th>
|
||||||
|
<th>Deleted</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
<%= render partial: 'products_list/product_row', collection: @products, as: :product %>
|
<%= render partial: 'products_list/product_row', collection: @products, as: :product %>
|
||||||
|
|
5
db/migrate/20150824142843_add_deleted_to_products.rb
Normal file
5
db/migrate/20150824142843_add_deleted_to_products.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddDeletedToProducts < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :products, :deleted, :boolean, default: false
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20150630183223) do
|
ActiveRecord::Schema.define(version: 20150824142843) do
|
||||||
|
|
||||||
create_table "order_items", force: :cascade do |t|
|
create_table "order_items", force: :cascade do |t|
|
||||||
t.integer "order_id"
|
t.integer "order_id"
|
||||||
|
@ -31,8 +31,8 @@ ActiveRecord::Schema.define(version: 20150630183223) do
|
||||||
add_index "orders", ["user_id"], name: "index_orders_on_user_id"
|
add_index "orders", ["user_id"], name: "index_orders_on_user_id"
|
||||||
|
|
||||||
create_table "products", force: :cascade do |t|
|
create_table "products", force: :cascade do |t|
|
||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
t.integer "price_cents", default: 0, null: false
|
t.integer "price_cents", default: 0, null: false
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "avatar_file_name"
|
t.string "avatar_file_name"
|
||||||
|
@ -40,7 +40,8 @@ ActiveRecord::Schema.define(version: 20150630183223) do
|
||||||
t.integer "avatar_file_size"
|
t.integer "avatar_file_size"
|
||||||
t.datetime "avatar_updated_at"
|
t.datetime "avatar_updated_at"
|
||||||
t.integer "category", default: 0
|
t.integer "category", default: 0
|
||||||
t.integer "stock", default: 0, null: false
|
t.integer "stock", default: 0, null: false
|
||||||
|
t.boolean "deleted", default: false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
|
|
Loading…
Reference in a new issue