-
-
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
: Collect Shopper
s Delivery Address before Checkout
#1173
Changes from 2 commits
fe15761
bc7f76b
b3b7280
314d4d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
class Marketplace | ||
class CartPolicy < ApplicationPolicy | ||
alias_method :cart, :object | ||
def permitted_attributes(_params = nil) | ||
%i[delivery_address] | ||
end | ||
|
||
def create? | ||
true | ||
end | ||
|
||
def update? | ||
cart.shopper.person == current_person | ||
end | ||
|
||
class Scope < ApplicationScope | ||
def resolve | ||
scope.all | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,44 @@ | ||
<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 id="<%= dom_id(cart) %>"> | ||
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. Sorry for the indentation change, but I needed to put in an id for the whole shebang so we could replace it all at once :X. 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. what is 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. nevermind. found it in https://apidock.com/rails/ActionView/RecordIdentifier/dom_id 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. Yea, it's part of the Rails Model/View/Controller coupling; where a unique |
||
|
||
<%- if cart.delivery_address.blank? %> | ||
<%= form_with model: cart.location do |cart_form| %> | ||
<%= render "text_field", attribute: :delivery_address, form: cart_form %> | ||
|
||
<%= cart_form.submit %> | ||
<%- end %> | ||
<%- else %> | ||
<div class="flex flex-wrap"> | ||
<p class="p-3"> | ||
Delivering to <%= cart.delivery_address %> | ||
|
||
</p> | ||
<%= button_to "Update Address", cart.location, params: { cart: { delivery_address: nil } }%> | ||
</div> | ||
|
||
<%- end %> | ||
|
||
<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> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,9 @@ | |
<tr> | ||
<td class="text-left px-3 py-3.5 text-right" colspan="8"> | ||
<%= render "marketplace/carts/total", cart: cart %> | ||
<%= button_to("Checkout", cart.location(child: :checkout), data: { turbo: false }) %> | ||
<%- if cart.delivery_address.present? %> | ||
<%= button_to("Checkout", cart.location(child: :checkout), data: { turbo: false }) %> | ||
<%- end %> | ||
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. this seems to make the checkout button hidden if the user never inputted a Why not just have the 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.
I also considered putting the entire cart except for the 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. @KellyAH - Do you have a preference between:
Part of me thinks option 2 is actually worth doing; since it serves as a forcing function and reduces the amount of elements on the page significantly... 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. wouldn't 2️⃣ IMHO 1️⃣ makes it clear that some other required action is needed to be allowed to proceed to the checkout flow. 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. I think we can presume a lot about what would or would not freak a customer out, but I don't like to design out of an expectation of fear or anxiety. It's not terribly unusual for clicking a link to navigate to a different page; so a customer freaking out because when they clicked a link they went somewhere else would surprise me. 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. My hesitation on 2️⃣ is that I just couldn't visualize how it would look in the UI/UX. If the flow looks fine with the 2️⃣ change and is something you as a customer would be comfy with. I say do 2️⃣ 👍 😄 As we say at work: "Do whatever is easiest/simplest. Because we can always iterate/refactor later" 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. Here is 2️⃣'s flow! I think it's pretty decent (but it needs better text! lol) split-setting-address-from-cart.mp4 |
||
</td> | ||
|
||
</tr> | ||
</tfoot> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
<span id="cart-total-<%= cart.id%>" class="w-full flex flex-col"> | ||
<span class="text-right"> | ||
<span id="cart-total-<%= cart.id%>" class="w-full flex flex-col sm:text-right"> | ||
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 were setting the text-right in every span, which seemed excessive. |
||
<span> | ||
Products: | ||
<%= humanized_money_with_symbol(cart.product_total) %></span> | ||
<span class="text-right">Delivery: | ||
<%= humanized_money_with_symbol(cart.delivery_fee) %></span> | ||
<span class="text-right font-bold"> | ||
<%- if cart.delivery_address.present? %> | ||
<span>Delivery Fee: | ||
<%= humanized_money_with_symbol(cart.delivery_fee) %></span> | ||
<%- end %> | ||
<span class="font-bold"> | ||
Total: <%= humanized_money_with_symbol(cart.price_total) %> | ||
</span> | ||
</span> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Marketplace | ||
class CartsController < Controller | ||
def update | ||
authorize(cart) | ||
cart.update(cart_params) | ||
respond_to do |format| | ||
format.html do | ||
redirect_to cart.room.location | ||
end | ||
format.turbo_stream do | ||
render turbo_stream: [turbo_stream.replace(dom_id(cart), cart)] | ||
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. Is this logic using turbo stream to AJAX-like update/rerender only the cart item elements on the webpage instead of rerendering the whole page? 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. Yep! |
||
end | ||
end | ||
end | ||
|
||
def cart | ||
@cart ||= policy_scope(marketplace.carts).find(params[:id]) | ||
end | ||
|
||
def cart_params | ||
policy(Cart).permit(params.require(:cart)) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,6 @@ def create_stripe_session(success_url:, cancel_url:) | |
mode: "payment", | ||
success_url: success_url, | ||
cancel_url: cancel_url, | ||
shipping_address_collection: { | ||
allowed_countries: ["US"], | ||
}, | ||
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 don't want to get it from Stripe anymore, since we get it before hand. 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. I assume: "get it before hand." from the user via this code change that allows the user to input their delivery address in a field. 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. Yep |
||
payment_intent_data: { | ||
transfer_group: cart.id | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,13 @@ | |
cart.cart_products.create!(product: product_b, quantity: 2) | ||
end | ||
|
||
it { is_expected.to eql(product_a.price + product_b.price + product_b.price + marketplace.delivery_fee) } | ||
it { is_expected.to eql(product_a.price + product_b.price * 2) } | ||
|
||
context "when the #delivery_address is present" do | ||
let(:cart) { create(:marketplace_cart, delivery_address: "123", marketplace: marketplace) } | ||
|
||
it { is_expected.to eql(product_a.price + product_b.price + product_b.price + marketplace.delivery_fee) } | ||
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. why is 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. Yep, the 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. IMHO and nitpick: 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. Done! |
||
end | ||
end | ||
|
||
describe "#product_total" do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Marketplace::CartsController, type: :request do | ||
let(:marketplace) { create(:marketplace) } | ||
let(:space) { marketplace.space } | ||
let(:room) { marketplace.room } | ||
let(:person) { create(:person) } | ||
|
||
let(:shopper) { create(:marketplace_shopper, person: person) } | ||
|
||
describe "#update" do | ||
it "changes the delivery address" do | ||
cart = create(:marketplace_cart, marketplace: marketplace, shopper: shopper) | ||
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. why can't the 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. Nah, it's because I didn't have multiple 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. leave it. it can be pulled out if more 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. Wound up finding a bug during my testing, which made me want to write a second test case! So |
||
sign_in(space, person) | ||
|
||
put polymorphic_path(cart.location), params: {cart: {delivery_address: "123 N West St"}} | ||
|
||
expect(response).to redirect_to(room.location) | ||
end | ||
end | ||
end |
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 assume this logic is covering the fact that the
cart.delivery_fee
cannot be calculated without adelivery_address
so it setsdelivery_fee
to zero.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.
Exactly.