Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ₯”βœ¨ Marketplace: Show Product::Photo in Cart #1443

Merged
merged 1 commit into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class ApplicationController < ActionController::Base

protect_from_forgery with: :exception, unless: -> { api_request? }

# @see https://til.hashrocket.com/posts/3exmhtwqy6-setting-the-urloptions-hash-in-the-controller
include ActiveStorage::SetCurrent

# Referenced in application layout to display page title
# Override on a per-controller basis to display different title
# @return [String]
Expand Down
35 changes: 24 additions & 11 deletions app/furniture/marketplace/cart_products/_cart_product.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
<%- product = cart_product.product %>
<%- cart = cart_product.cart %>
<tr id="cart-product-<%= cart_product.product_id %>">
<tr id="<%= dom_id(cart_product)%>">
<td class="w-full max-w-0 py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:w-auto sm:max-w-none sm:pl-6">
<%= product.name %>
<%- if product.photo.present? %>
<figure>
<%= image_tag product.photo.variant(resize_to_limit: [550, 550]).processed.url, class: "rounded-lg"
%>
<figcaption class="text-center py-2">
<%=product.name%>
</figcaption>
</figure>
<%- else %>
<%= product.name %>
<%- end %>

<dl class="font-normal lg:hidden">
<dt class="sr-only"><%= product.class.human_attribute_name(:price) %></dt>
<dd><%= humanized_money_with_symbol(product.price) %></dd>
Expand All @@ -17,17 +28,19 @@
<td class="hidden px-3 py-4 text-sm text-gray-500 sm:table-cell">
<%= humanized_money_with_symbol(product.price) %>
</td>
<td class="py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6 flex flex-row justify-between items-center">
<%# TODO: Extract minus and plus buttons into components %>
<%- minus_quantity = [cart_product.quantity - 1, 0].max %>
<%- minus_method = minus_quantity.zero? ? :delete : :put %>
<%= render "buttons/minus", disabled: cart_product.quantity.zero?, method: minus_method, title: t('.remove'), disabled: cart_product.quantity.zero?, href: [cart.space, cart.room, cart.marketplace, cart, cart_product, { cart_product: { quantity: minus_quantity, product_id: product.id} }] %>
<td class="py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6">
<div class="flex flex-row justify-between items-center">
<%# TODO: Extract minus and plus buttons into components %>
<%- minus_quantity = [cart_product.quantity - 1, 0].max %>
<%- minus_method = minus_quantity.zero? ? :delete : :put %>
<%= render "buttons/minus", disabled: cart_product.quantity.zero?, method: minus_method, title: t('.remove'), disabled: cart_product.quantity.zero?, href: [cart.space, cart.room, cart.marketplace, cart, cart_product, { cart_product: { quantity: minus_quantity, product_id: product.id} }] %>


<span class="py-2 px-2 my-1 text-lg"><%= cart_product.quantity %></span>
<span class="py-2 px-2 my-1 text-lg"><%= cart_product.quantity %></span>

<%- add_quantity = cart_product.quantity + 1 %>
<%- add_method = add_quantity == 1 ? :post : :put %>
<%= render "buttons/plus", method: add_method, title: t('.add'), href: [cart.space, cart.room, cart.marketplace, cart, cart_product, { cart_product: {quantity: add_quantity, product_id: product.id} }] %>
<%- add_quantity = cart_product.quantity + 1 %>
<%- add_method = add_quantity == 1 ? :post : :put %>
<%= render "buttons/plus", method: add_method, title: t('.add'), href: [cart.space, cart.room, cart.marketplace, cart, cart_product, { cart_product: {quantity: add_quantity, product_id: product.id} }] %>
</div>
</td>
</tr>