-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Marketplace: Cart Total Updates as Products are Added and Removed (#927)
* Marketplace: Cart can Total Price Co-Authored-By: Ana Ulin <[email protected]> * Marketplace: Adding and Removing Products updates Cart's Total Co-authored-by: Ana Ulin <[email protected]> Co-authored-by: Ana Ulin <[email protected]>
- Loading branch information
Showing
7 changed files
with
76 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<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"> | ||
<%= Marketplace::Product.human_attribute_name(:price) %> | ||
</th> | ||
<th scope="col" class="w-48"> </th> | ||
</tr> | ||
</thead> | ||
<tbody class="divide-y divide-gray-200 bg-white"> | ||
<%- cart.marketplace.products.each do |product| %> | ||
<%= render cart.cart_products.find_or_initialize_by(product: product) %> | ||
<%- end %> | ||
</tbody> | ||
<%= render "marketplace/carts/footer", cart: cart %> | ||
</table> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<tfoot id="cart-footer-<%= cart.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(cart.price_total) %> | ||
</td> | ||
</tr> | ||
</tfoot |
28 changes: 4 additions & 24 deletions
28
app/furniture/marketplace/marketplaces/_marketplace.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Marketplace::Cart, type: :model do | ||
it { is_expected.to have_many(:cart_products) } | ||
it { is_expected.to have_many(:cart_products).dependent(:destroy) } | ||
|
||
it { is_expected.to have_many(:products).through(:cart_products) } | ||
|
||
it { is_expected.to belong_to(:marketplace).class_name("Marketplace::Marketplace") } | ||
|
||
describe "#price_total" do | ||
subject(:price_total) { cart.price_total } | ||
|
||
let(:cart) { create(:marketplace_cart) } | ||
let(:product_a) { create(:marketplace_product, marketplace: cart.marketplace) } | ||
let(:product_b) { create(:marketplace_product, marketplace: cart.marketplace) } | ||
|
||
before do | ||
cart.cart_products.create!(product: product_a, quantity: 1) | ||
cart.cart_products.create!(product: product_b, quantity: 2) | ||
end | ||
|
||
it { is_expected.to eql(product_a.price + product_b.price + product_b.price) } | ||
end | ||
end |