-
-
Notifications
You must be signed in to change notification settings - Fork 20
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: Sprout Checkout #994
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e27058c
Marketplace: add checkout link and route
KellyAH d782442
Marketplace: expose Checkouts new page
KellyAH 0f1c65e
Marketplace: add WIP checkout request spec
KellyAH ea5c07b
fix request spec filename
KellyAH f32b6af
Marketplace: Checkout page shows Cart
KellyAH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,16 @@ | ||
<% | ||
marketplace = cart.marketplace | ||
room = marketplace.room | ||
space = room.space | ||
%> | ||
|
||
<tfoot id="cart-footer-<%= cart.id%>" class="bg-gray-50"> | ||
<tr> | ||
<td></td> | ||
<th> <%= link_to("checkout", new_space_room_marketplace_checkout_path(space, room, marketplace), html_options = {}) %> </th> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may be able to use |
||
<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) %> | ||
<%= render "marketplace/carts/total", cart: cart %> | ||
</td> | ||
</tr> | ||
</tfoot> |
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,3 @@ | ||
<span id="cart-total-<%= cart.id%>"> | ||
<%= humanized_money_with_symbol(cart.price_total) %> | ||
</span> |
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,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Marketplace | ||
class CheckoutPolicy < ApplicationPolicy | ||
alias checkout object | ||
|
||
def create? | ||
checkout.shopper.person == current_person | ||
end | ||
end | ||
end |
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,30 @@ | ||
<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"> | ||
<%= render checkout.cart.cart_products %> | ||
</tbody> | ||
<tfoot id="checkout-footer-<%= checkout.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"> | ||
<%= render "marketplace/carts/total" %> | ||
</td> | ||
</tr> | ||
</tfoot> | ||
</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,2 @@ | ||
<%- breadcrumb :marketplace_checkout, checkout%> | ||
<%= render checkout %> |
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,27 @@ | ||
class Marketplace | ||
class CheckoutsController < FurnitureController | ||
def new | ||
authorize(checkout) | ||
end | ||
|
||
helper_method def checkout | ||
@checkout ||= cart.build_checkout(shopper: shopper) | ||
end | ||
|
||
helper_method def shopper | ||
@shopper ||= if current_person.is_a?(Guest) | ||
Shopper.find_or_create_by(id: session[:current_cart] ||= SecureRandom.uuid) | ||
else | ||
Shopper.find_or_create_by(person: current_person) | ||
end | ||
end | ||
|
||
helper_method def cart | ||
@cart ||= marketplace.carts.find_or_create_by(shopper: shopper) | ||
end | ||
|
||
helper_method def marketplace | ||
@marketplace ||= policy_scope(Marketplace).find(params[:marketplace_id]) | ||
end | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
spec/furniture/marketplace/checkouts_controller_request_spec.rb
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,13 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Marketplace::Checkout, type: :request do | ||
let(:marketplace) { create(:marketplace) } | ||
let(:space) { marketplace.space } | ||
let(:room) { marketplace.room } | ||
|
||
describe "#create" do | ||
it "Create Checkout from a Cart" do | ||
# TODO: insert test | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice we make this particular change 3 different times in this controller; what if we gathered these three replace calls into a method so they aren't duplicated everywhere? What arguments would the method need to take to work appropriately across it's different calls?