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: Shopper sets Delivery Window #1234

Merged
merged 1 commit into from
Mar 22, 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
9 changes: 7 additions & 2 deletions app/furniture/marketplace/cart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def product_total
cart_products.sum(0, &:price_total)
end

def delivery_window
marketplace.delivery_window.presence || super
end

def delivery_fee
return marketplace.delivery_fee if delivery_address.present?

Expand All @@ -41,8 +45,9 @@ def price_total
product_total + delivery_fee + tax_total
end

def ready_for_delivery?
(delivery_address.present? && contact_phone_number.present?)
def ready_for_shopping?
(delivery_address.present? && contact_phone_number.present? && delivery_window.present?)
end
alias_method :ready_for_delivery?, :ready_for_shopping?
end
end
2 changes: 1 addition & 1 deletion app/furniture/marketplace/cart_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Marketplace
class CartPolicy < Policy
alias_method :cart, :object
def permitted_attributes(_params = nil)
%i[delivery_address contact_phone_number]
%i[delivery_address contact_phone_number delivery_window]
end

class Scope < ApplicationScope
Expand Down
12 changes: 9 additions & 3 deletions app/furniture/marketplace/carts/_cart.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<div id="<%= dom_id(cart) %>">

<%- if cart.delivery_address.blank? || cart.contact_phone_number.blank? %>
<%- if !cart.ready_for_shopping? %>
<%= form_with model: cart.location do |cart_form| %>
<%= render "text_field", attribute: :delivery_address, form: cart_form %>
<%= render "text_field", attribute: :delivery_window, form: cart_form, disabled?: cart.marketplace.delivery_window.present? %>
<%= render "text_field", attribute: :contact_phone_number, form: cart_form %>

<%= cart_form.submit t('marketplace.delivery_info.edit') %>
Expand Down Expand Up @@ -50,7 +51,12 @@
<%- end %>

<p class="italic text-right py-2 text-sm">
Orders placed by <%= cart.marketplace.order_by %>
are delivered on <%= cart.marketplace.delivery_window %>.
<%- if cart.marketplace.delivery_window.present? %>
Orders placed by <%= cart.marketplace.order_by %>
are delivered on <%= cart.marketplace.delivery_window %>.
<%- elsif cart.delivery_window.present? %>
Place orders <%= cart.marketplace.order_by %> to ensure an on-time delivery for <%= cart.delivery_window%>.<br />
<%= render ButtonComponent.new(href: cart.location.concat([params: { cart: { delivery_window: nil } }]), label: t('marketplace.delivery_window.edit'), title: nil, classes: "shrink font-light text-xs m-0 bg-primary-200 underline") %>
<%- end %>
</p>
</div>
2 changes: 2 additions & 0 deletions app/furniture/marketplace/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

en:
marketplace:
delivery_window:
edit: "Change Delivery Window"
delivery_info:
edit: "Update Delivery Info"
contact_phone_number:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddDeliveryWindowToMarketplaceOrders < ActiveRecord::Migration[7.0]
def change
add_column :marketplace_orders, :delivery_window, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_03_19_173737) do
ActiveRecord::Schema[7.0].define(version: 2023_03_20_190449) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
Expand Down Expand Up @@ -138,6 +138,7 @@
t.text "delivery_address_ciphertext"
t.string "contact_phone_number_ciphertext"
t.datetime "placed_at"
t.string "delivery_window"
t.index ["marketplace_id"], name: "index_marketplace_orders_on_marketplace_id"
t.index ["shopper_id"], name: "index_marketplace_orders_on_shopper_id"
end
Expand Down
3 changes: 2 additions & 1 deletion spec/furniture/marketplace/carts_controller_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

describe "#update" do
subject(:perform_request) do
put polymorphic_path(cart.location), params: {cart: {delivery_address: "123 N West St", contact_phone_number: "(415)-123-4567"}}
put polymorphic_path(cart.location), params: {cart: {delivery_address: "123 N West St", delivery_window: "Tomorrow at 3pm", contact_phone_number: "(415)-123-4567"}}
response
end

Expand All @@ -20,6 +20,7 @@
it { is_expected.to redirect_to(room.location) }
specify { expect { perform_request }.to change { cart.reload.delivery_address }.from(nil).to("123 N West St") }
specify { expect { perform_request }.to change { cart.reload.contact_phone_number }.from(nil).to("(415)-123-4567") }
specify { expect { perform_request }.to change { cart.reload.delivery_window }.from(nil).to("Tomorrow at 3pm") }
end

context "when a `Neighbor`" do
Expand Down