From 988eb259bd1aeafeefe030209125be2a7de29ae0 Mon Sep 17 00:00:00 2001 From: ger619 Date: Mon, 10 Jul 2023 19:01:39 +0300 Subject: [PATCH] shopping cart working --- app/views/product/_production.html.erb | 10 +++++----- db/migrate/20230708163512_create_orderables.rb | 1 + db/schema.rb | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/views/product/_production.html.erb b/app/views/product/_production.html.erb index fbb076147..56c08426f 100644 --- a/app/views/product/_production.html.erb +++ b/app/views/product/_production.html.erb @@ -12,19 +12,19 @@

<%= product.description %>

<%= product.name %>Color: Yellow with Black and White stripes

-
-

<%= product.size %>

-
+
Price: <%= product.price %>
-
Price: <%= product.price %>
<%= form_with(url: cart_add_path) do |f| %> <%= f.hidden_field :product_id, value: product.id %> + <%= f.select :size, ['SMALL', 'MEDIUM', 'LARGE'], prompt: 'Size of The Shirt', class: "border-[#FAE115] border-2 p-2 md:p-4 size-option uppercase" %> +

<%= f.number_field :quantity, value: 1, min: 1, id: "quantity", class: "bg-[#FAE115] border-none" %> +
<%= f.submit "Add to cart", class: "bg-[#FAE115] p-3 rounded-lg mt-2" %> <% end %> +
- <% if current_user %> <%= link_to 'Edit', edit_product_path(product), class: "bg-[#FAE115] p-3 rounded-lg mt-2" %> <%= link_to 'Destroy', @product, method: :delete, data: { confirm: 'Are you sure?' }, class: "bg-[#FAE115] p-3 rounded-lg mt-2" %> diff --git a/db/migrate/20230708163512_create_orderables.rb b/db/migrate/20230708163512_create_orderables.rb index 68e4adfa6..39b807a2f 100644 --- a/db/migrate/20230708163512_create_orderables.rb +++ b/db/migrate/20230708163512_create_orderables.rb @@ -3,6 +3,7 @@ def change create_table :orderables do |t| t.belongs_to :product, null: false, foreign_key: true t.belongs_to :cart, null: false, foreign_key: true + t.string :size t.integer :quantity t.timestamps diff --git a/db/schema.rb b/db/schema.rb index f18091369..3b2c66cec 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -71,6 +71,7 @@ create_table "orderables", force: :cascade do |t| t.bigint "product_id", null: false t.bigint "cart_id", null: false + t.string "size" t.integer "quantity" t.datetime "created_at", null: false t.datetime "updated_at", null: false @@ -115,7 +116,6 @@ t.datetime "confirmed_at" t.datetime "confirmation_sent_at" t.string "unconfirmed_email" - t.integer "role", default: 0, null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true