diff --git a/app/controllers/product_cart_controller.rb b/app/controllers/product_cart_controller.rb index d552c22..87760a2 100644 --- a/app/controllers/product_cart_controller.rb +++ b/app/controllers/product_cart_controller.rb @@ -16,7 +16,9 @@ def show def remove item = @cart.product_cart_items.find_by(product_id: params[:product_id]) item.destroy if item - redirect_to( product_cart_path, notice: 'Item removed from cart') + @cart_items = @cart.product_cart_items.includes(:product) + render "destroy" + # redirect_to( product_cart_path, notice: 'Item removed from cart') end private diff --git a/app/views/product_cart/_cart.erb b/app/views/product_cart/_cart.erb new file mode 100644 index 0000000..69a081a --- /dev/null +++ b/app/views/product_cart/_cart.erb @@ -0,0 +1,29 @@ +
+

Your Cart

+ + <% if @cart.product_cart_items.any? %> +
+ <% @cart.product_cart_items.each do |item| %> +
+
+

+ <%= link_to item.product.title, user_product_path(item.product.user.username, item.product), class: "text-link" %> +

+

Quantity: <%= item.quantity %>

+

Price: <%= number_to_currency(item.product.price) %>

+
+ <%= button_to "Remove", product_cart_remove_path(product_id: item.product.id), method: :delete, data: {turbo_method: :delete, turbo_confirm: "delete item?", turbo_frame: "_top"}, class: "bg-red-500 text-default px-4 py-2 rounded" %> +
+ <% end %> +
+ +
+

Total: <%= number_to_currency(@cart.total_price) %>

+ <%= form_tag product_checkout_index_path, method: :post, data: {turbo: false } do %> + <%= submit_tag "Proceed to Checkout", class: "mt-4 bg-muted text-default px-6 py-3 rounded-lg font-bold cursor-pointer" %> + <% end %> +
+ <% else %> +

Your cart is empty.

+ <% end %> +
\ No newline at end of file diff --git a/app/views/product_cart/destroy.turbo_stream.erb b/app/views/product_cart/destroy.turbo_stream.erb new file mode 100644 index 0000000..8778ad0 --- /dev/null +++ b/app/views/product_cart/destroy.turbo_stream.erb @@ -0,0 +1,5 @@ +<%= turbo_stream.replace("cart-show") do %> + + <%= render "cart" %> + +<% end %> \ No newline at end of file diff --git a/app/views/product_cart/show.erb b/app/views/product_cart/show.erb index d1a9ae2..4df5dbc 100644 --- a/app/views/product_cart/show.erb +++ b/app/views/product_cart/show.erb @@ -1,30 +1,4 @@ - -
-

Your Cart

- <% if @cart.product_cart_items.any? %> -
- <% @cart.product_cart_items.each do |item| %> -
-
-

- <%= link_to item.product.title, user_product_path(item.product.user.username, item.product), class: "text-link" %> -

-

Quantity: <%= item.quantity %>

-

Price: <%= number_to_currency(item.product.price) %>

-
- <%= button_to "Remove", product_cart_remove_path(product_id: item.product.id), method: :delete, data: {turbo_method: :delete, turbo_confirm: "delete item?", turbo_frame: "_top"}, class: "bg-red-500 text-default px-4 py-2 rounded" %> -
- <% end %> -
- -
-

Total: <%= number_to_currency(@cart.total_price) %>

- <%= form_tag product_checkout_index_path, method: :post, data: {turbo: false } do %> - <%= submit_tag "Proceed to Checkout", class: "mt-4 bg-muted text-default px-6 py-3 rounded-lg font-bold cursor-pointer" %> - <% end %> -
- <% else %> -

Your cart is empty.

- <% end %> +
+ <%= render "cart" %>
\ No newline at end of file diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb index cd35a80..b0dff99 100644 --- a/app/views/products/show.html.erb +++ b/app/views/products/show.html.erb @@ -113,13 +113,13 @@
-
<% render "variants_info" %>
- <% if @product.available? %> - <%= button_to "Add to Cart", "#", method: :post, class: "mt-10 flex w-full items-center justify-center rounded-md border border-transparent bg-indigo-600 px-8 py-3 text-base font-medium text-default hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2" %> + <% if @product.available? %> + <%= button_to "Add to cart", product_cart_add_path(product_id: @product.id), method: :post, class: "button-sm-outline w-full text-center justify-center" %> + <% # button_to "Add to Cart", "#", method: :post, class: "mt-10 flex w-full items-center justify-center rounded-md border border-transparent bg-indigo-600 px-8 py-3 text-base font-medium text-default hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2" %> <% else %>

Sold Out

<% end %> @@ -132,11 +132,11 @@
-
+ - +