Skip to content

Commit

Permalink
🥔✨ Marketplace: Show Tax on Order
Browse files Browse the repository at this point in the history
- #1137

The entire `Marketplace::Order` page is potato-tier, but at least it
exists!
  • Loading branch information
zspencer committed Mar 10, 2023
1 parent 60054b2 commit bae4308
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 27 deletions.
4 changes: 1 addition & 3 deletions app/furniture/marketplace/cart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ class Cart < Record
}

def product_total
cart_products.sum(0) do |cart_product|
cart_product.price_total
end
cart_products.sum(0, &:price_total)
end

def delivery_fee
Expand Down
12 changes: 8 additions & 4 deletions app/furniture/marketplace/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ class Order < Record
}

def product_total
ordered_products.sum(0) do |ordered_product|
ordered_product.product.price * ordered_product.quantity
end
ordered_products.sum(0, &:price_total)
end


def tax_total
ordered_products.sum(0, &:tax_amount)
end


delegate :delivery_fee, to: :marketplace

def price_total
product_total + delivery_fee
product_total + delivery_fee + tax_total
end
end
end
10 changes: 9 additions & 1 deletion app/furniture/marketplace/ordered_product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ class OrderedProduct < Record
belongs_to :order, inverse_of: :ordered_products, foreign_key: :cart_id

belongs_to :product, inverse_of: :ordered_products
delegate :name, :description, :price, :price_cents, to: :product
delegate :name, :description, :price, :price_cents, :tax_rates, to: :product

def tax_amount
price_total * (tax_rates.sum(0, &:tax_rate) / 100)
end

def price_total
product.price * quantity
end
end
end
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
<tr id="<%=dom_id(ordered_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">
<td class="py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:w-auto sm:max-w-none sm:pl-6">
<%= ordered_product.name %>
<dl class="font-normal lg:hidden">
<dt class="sr-only"><%= ordered_product.class.human_attribute_name(:description) %></dt>
<dd class="mt-1 truncate text-gray-700"><%= ordered_product.description %></dd>
</dl>
</td>
<td class="hidden px-3 py-4 text-sm text-gray-500 lg:table-cell">
<%= ordered_product.description %>
</td>
<td class="hidden px-3 py-4 text-sm text-gray-500 sm:table-cell">
<%= humanized_money_with_symbol(ordered_product.price) %>
<td class="px-3 py-4 text-sm text-gray-500">
<%= humanized_money_with_symbol(ordered_product.price) %> x (<%=ordered_product.quantity%>)
</td>
</tr>
26 changes: 17 additions & 9 deletions app/furniture/marketplace/orders/_order.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<h1>Ordered on <%= order.created_at.to_fs(:long_ordinal) %>
<h1>
Ordered on
<%= link_to(order.created_at.to_fs(:long_ordinal), order.location) %>
</h1>
<div class="-mx-4 mt-8 overflow-hidden shadow ring-1 ring-black ring-opacity-5 sm:-mx-6 md:mx-0 md:rounded-lg">
<table class="min-w-full divide-y divide-gray-300 table-fixed">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6">
<%= Marketplace::Product.human_attribute_name(:name) %>
</th>
<th scope="col" class="hidden px-3 py-3.5 text-left text-sm font-semibold text-gray-900 lg:table-cell">
<%= Marketplace::Product.human_attribute_name(:description) %>
</th>
<th scope="col" class="hidden px-3 py-3.5 text-left text-sm font-semibold text-gray-900 sm:table-cell">
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900 sm:table-cell">
<%= Marketplace::Product.human_attribute_name(:price) %>
</th>
<th scope="col" class="w-48">&nbsp;</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200 bg-white">
Expand All @@ -21,9 +20,18 @@
<tfoot id="checkout-footer-<%= order.id%>" class="bg-gray-50">
<tr>
<td></td>
<th scope="row" class="text-right px-1 py-3.5">Total: </th>
<td class="text-left px-3 py-3.5 font-bold">
<%= humanized_money_with_symbol(order.price_total) %>
<td class="text-left px-3 py-3.5">
<p>
Products:
<%= humanized_money_with_symbol(order.product_total) %></p>
<p>
Taxes:
<%= humanized_money_with_symbol(order.tax_total) %></p>
<p>Delivery Fee:
<%= humanized_money_with_symbol(order.delivery_fee) %></p>

<p class="font-bold">
Total: <%= humanized_money_with_symbol(order.price_total) %></span>
</td>
</tr>
</tfoot>
Expand Down

0 comments on commit bae4308

Please sign in to comment.