From 36c7953841242784bf65fd9b5757344479693e62 Mon Sep 17 00:00:00 2001 From: ger619 Date: Mon, 10 Jul 2023 17:32:50 +0300 Subject: [PATCH 1/2] shopping cart working --- app/views/layouts/_navbar.html.erb | 5 +---- app/views/product/_production.html.erb | 4 ++-- app/views/product/index.html.erb | 2 +- app/views/product/show.html.erb | 1 + 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index 2994499c0..711e18a01 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -62,11 +62,8 @@
  • <%= link_to "OUR CLUB", club_index_path %>
  • -
  • - <%= link_to "SHOP", shop_index_path %> -
  • - <%= link_to "SHOP/PRODUCT", product_index_path %> + <%= link_to "SHOP", product_index_path %>
  • diff --git a/app/views/product/_production.html.erb b/app/views/product/_production.html.erb index 693a98f1b..fbb076147 100644 --- a/app/views/product/_production.html.erb +++ b/app/views/product/_production.html.erb @@ -26,8 +26,8 @@ <% if current_user %> - <%= link_to 'Edit', edit_product_path(product), class: "bg-[#FAE115] p-3 rounded-lg mt-2" %> - <%= link_to 'Destroy', product, class: "bg-[#FAE115] p-3 rounded-lg mt-2", method: :delete, data: { confirm: 'Are you sure?' } %> + <%= 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" %> <% end %> diff --git a/app/views/product/index.html.erb b/app/views/product/index.html.erb index 9a6881feb..c930d3e0c 100644 --- a/app/views/product/index.html.erb +++ b/app/views/product/index.html.erb @@ -1,5 +1,5 @@
    - PRODUCT + SHOP <%= render partial: "cart/cart" if @render_cart %> diff --git a/app/views/product/show.html.erb b/app/views/product/show.html.erb index a0942954d..1e73cd71c 100644 --- a/app/views/product/show.html.erb +++ b/app/views/product/show.html.erb @@ -8,6 +8,7 @@ <%= image_tag(@product.photo_product) %> <%= @product.price %>
    + <%= button_to "Destroy this product", @product, method: :delete %> From 988eb259bd1aeafeefe030209125be2a7de29ae0 Mon Sep 17 00:00:00 2001 From: ger619 Date: Mon, 10 Jul 2023 19:01:39 +0300 Subject: [PATCH 2/2] 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