Skip to content

Commit

Permalink
Merge pull request #10805 from jibees/10717-bo-orders-changing-custom…
Browse files Browse the repository at this point in the history
…er-does-not-update-customer_id

Admin, Edit customer details for an order: when changing to another customer, update `customer_id` as well
  • Loading branch information
drummer83 committed May 10, 2023
2 parents bf7a559 + 3a15791 commit 2836751
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def order_params
params.require(:order).permit(
:email,
:use_billing,
:customer_id,
bill_address_attributes: ::PermittedAttributes::Address.attributes,
ship_address_attributes: ::PermittedAttributes::Address.attributes
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
= form_for @order, :url => admin_order_customer_url(@order) do |f|
= render 'form', :f => f
= f.hidden_field :customer_id, value: @order.customer_id, id: "customer_id"
1 change: 1 addition & 0 deletions app/webpacker/controllers/select_customer_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default class extends TomSelectController {
});
$("#order_email").val(customer.email);
$("#user_id").val(customer.user_id);
$("#customer_id").val(customer.id);
}

setValueOnTomSelectController = (element, value) => {
Expand Down
31 changes: 31 additions & 0 deletions spec/system/admin/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,37 @@ def new_order_with_distribution(distributor, order_cycle)
end
end

context "when creating an order with a customer-only" do
let(:customer2) { create(:customer, enterprise: distributor) }
let(:customer3) { create(:customer, enterprise: distributor) }

before do
login_as_admin
visit spree.new_admin_order_path
select2_select distributor.name, from: 'order_distributor_id'
select2_select order_cycle.name, from: 'order_order_cycle_id'
click_button 'Next'
expect(Spree::Order.last.customer_id).to be_nil
tomselect_search_and_select customer2.email, from: 'customer_search_override'
check 'order_use_billing'
click_button 'Update'
expect(page).to have_content 'Customer Details updated'
end

it "set the right customer attached to the order" do
expect(Spree::Order.last.reload.customer).to eq customer2
end

it "when changing the attached customer,"\
"it should update the order customer (not only its details)" do
tomselect_search_and_select customer3.email, from: 'customer_search_override'
expect do
click_button 'Update'
expect(page).to have_field 'order_email', with: customer3.email
end.to change { Spree::Order.last.reload.customer }.from(customer2).to(customer3)
end
end

it "can add a product to an existing order" do
login_as_admin
visit spree.edit_admin_order_path(order)
Expand Down

0 comments on commit 2836751

Please sign in to comment.