-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a customer controller to allow editing the contact email
- Loading branch information
Showing
9 changed files
with
87 additions
and
5 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
12 changes: 12 additions & 0 deletions
12
admin/app/components/solidus_admin/orders/show/customer/component.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div class="<%= stimulus_id %>"> | ||
<%= render component("orders/show").new(order: @order) %> | ||
<%= render component("ui/modal").new(title: t(".title"), close_path: solidus_admin.order_path(@order)) do |modal| %> | ||
<%= form_for @order, url: solidus_admin.order_path(@order), html: { id: form_id} do |f| %> | ||
<%= render component("ui/forms/field").text_field(f, :email) %> | ||
<% end %> | ||
<% modal.with_actions do %> | ||
<%= render component("ui/button").new(form: form_id, type: :submit, text: "Update") %> | ||
<% end %> | ||
<% end %> | ||
</div> |
11 changes: 11 additions & 0 deletions
11
admin/app/components/solidus_admin/orders/show/customer/component.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,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Orders::Show::Customer::Component < SolidusAdmin::BaseComponent | ||
def initialize(order:) | ||
@order = order | ||
end | ||
|
||
def form_id | ||
dom_id(@order, "#{stimulus_id}_email_form") | ||
end | ||
end |
2 changes: 2 additions & 0 deletions
2
admin/app/components/solidus_admin/orders/show/customer/component.yml
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 @@ | ||
en: | ||
title: "Edit customer" |
19 changes: 19 additions & 0 deletions
19
admin/app/controllers/solidus_admin/customers_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,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::CustomersController < SolidusAdmin::BaseController | ||
before_action :load_order, only: :show | ||
|
||
def show | ||
render component('orders/show/customer').new(order: @order) | ||
end | ||
|
||
private | ||
|
||
def load_order | ||
@order = Spree::Order.find_by!(number: params[:order_id]) | ||
end | ||
|
||
def authorization_subject | ||
@order || Spree::Order | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ en: | |
solidus_admin: | ||
orders: | ||
title: "Orders" | ||
update: | ||
success: "Order was updated successfully" |
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 |
---|---|---|
|
@@ -2,11 +2,25 @@ | |
|
||
require 'spec_helper' | ||
|
||
describe "Order", type: :feature do | ||
describe "Order", :js, type: :feature do | ||
before { sign_in create(:admin_user, email: '[email protected]') } | ||
|
||
it "allows changing the order email" do | ||
create(:order, number: "R123456789", total: 19.99) | ||
|
||
visit "/admin/orders/R123456789/edit" | ||
|
||
expect(page).to have_content("Order R123456789") | ||
find("summary", text: "Customer").click | ||
click_on "Edit order email" | ||
fill_in "Customer Email", with: "[email protected]" | ||
click_on "Update" | ||
expect(page).to have_content("Order was updated successfully") | ||
expect(page).to have_content("Order contact email [email protected]", normalize_ws: true) | ||
end | ||
|
||
context "in cart state" do | ||
it "allows managing the cart", :js do | ||
it "allows managing the cart" do | ||
create(:product, name: "Just a product", slug: 'just-a-prod', price: 19.99) | ||
create(:product, name: "Just another product", slug: 'just-another-prod', price: 29.99) | ||
create(:order, number: "R123456789", total: 19.99, state: "cart") | ||
|