-
-
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.
Shopper may add Notes to a Product in their Cart on checkout
- Fixes #2661
- Loading branch information
Showing
13 changed files
with
88 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<%= form_with(model: cart_product, | ||
url: polymorphic_path(cart_product.location(child: :note))) do |form| %> | ||
|
||
<%= form.label :note %> | ||
<%= form.text_area :note %> | ||
|
||
<%= form.submit %> | ||
<%- 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,6 @@ | ||
<%- if cart_product.note.present? %> | ||
<p><%= cart_product.note %></p> | ||
<%= link_to("Edit Note", cart_product.location(:edit, child: :note)) %> | ||
<%- else %> | ||
<%= link_to("Add Note", cart_product.location(:new, child: :note)) %> | ||
<%- 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,4 @@ | ||
|
||
<%= turbo_frame_tag(cart_product, :note) do %> | ||
<%= render "form", cart_product: %> | ||
<%- 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,4 @@ | ||
|
||
<%= turbo_frame_tag(cart_product, :note) do %> | ||
<%= render "form", cart_product: %> | ||
<%- 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,3 @@ | ||
<%= turbo_frame_tag(cart_product, :note) do %> | ||
<%= render "note", cart_product: %> | ||
<%- end %> |
33 changes: 33 additions & 0 deletions
33
app/furniture/marketplace/cart_product/notes_controller.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,33 @@ | ||
class Marketplace | ||
class CartProduct::NotesController < Controller | ||
expose :cart, scope: -> { policy_scope(marketplace.carts) }, model: Cart | ||
expose :cart_product, scope: -> { policy_scope(cart.cart_products) }, model: CartProduct | ||
|
||
def new | ||
authorize(cart_product, :update?) | ||
end | ||
|
||
def show | ||
authorize(cart_product) | ||
end | ||
|
||
def edit | ||
authorize(cart_product) | ||
end | ||
|
||
def update | ||
authorize(cart_product) | ||
cart_product.update(cart_product_params) | ||
|
||
if cart_product.errors.present? | ||
render :new, status: :unprocessable_entity | ||
else | ||
redirect_to cart_product.location(child: :note) | ||
end | ||
end | ||
|
||
def cart_product_params | ||
params.require(:cart_product).permit(:note) | ||
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
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
5 changes: 5 additions & 0 deletions
5
db/migrate/20241017003307_marketplace_add_note_to_cart_product.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,5 @@ | ||
class MarketplaceAddNoteToCartProduct < ActiveRecord::Migration[7.1] | ||
def change | ||
add_column :marketplace_cart_products, :note, :string, null: false, default: "" | ||
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
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 |
---|---|---|
|
@@ -81,6 +81,10 @@ def url_options | |
click_link("Checkout") | ||
expect(page).to have_current_path(polymorphic_path(marketplace.carts.first.location(child: :checkout))) | ||
|
||
click_link("Add Note") | ||
fill_in("Note", with: "No bananas!") | ||
click_button("Save changes") | ||
|
||
set_delivery_details(delivery_address: "123 N West St Oakland, CA", | ||
contact_email: "[email protected]", | ||
contact_phone_number: "1234567890") | ||
|