item price is now saved when added to cart
This commit is contained in:
@@ -12,7 +12,7 @@ class CreateItems < ActiveRecord::Migration
|
||||
t.integer :stock
|
||||
t.boolean :on_display
|
||||
|
||||
t.timestamps null: false
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddPriceToItemInCart < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :item_in_carts, :price, :decimal
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150312073820) do
|
||||
ActiveRecord::Schema.define(version: 20150313065130) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -69,6 +69,7 @@ ActiveRecord::Schema.define(version: 20150312073820) do
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "count"
|
||||
t.decimal "price"
|
||||
end
|
||||
|
||||
create_table "items", force: :cascade do |t|
|
||||
|
||||
@@ -12,6 +12,7 @@ class ItemInCart < ActiveRecord::Base
|
||||
item_in_cart = ItemInCart.where(cart_id: cart_id, item_id: item_id).first
|
||||
item_in_cart ||= ItemInCart.new(cart_id: cart_id, item_id: item_id)
|
||||
item_in_cart.count = count
|
||||
item_in_cart.price = item_in_cart.item.list_price
|
||||
item_in_cart.save!
|
||||
item_in_cart.destroy! if count <= 0
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user