From e3683d25ca492e4da08cc624a8d806d676952ea5 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 19 May 2022 17:17:57 +0200 Subject: [PATCH 1/4] Change second step order: Customer Details instead of Order Details This second step comes from a first one, which is Set Distribution --- app/controllers/spree/admin/orders_controller.rb | 6 +++++- .../spree/admin/orders/set_distribution.html.haml | 1 + app/views/spree/admin/shared/_order_tabs.html.haml | 14 +++++++------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/controllers/spree/admin/orders_controller.rb b/app/controllers/spree/admin/orders_controller.rb index 0030d969ea..c7bd070146 100644 --- a/app/controllers/spree/admin/orders_controller.rb +++ b/app/controllers/spree/admin/orders_controller.rb @@ -42,6 +42,10 @@ module Spree @order.update_order! end + if params[:set_distribution_step] && @order.update(order_params) + return redirect_to spree.admin_order_customer_path(@order) + end + unless order_params.present? && @order.update(order_params) && @order.line_items.present? if @order.line_items.empty? && !params[:suppress_error_msg] @order.errors.add(:line_items, Spree.t('errors.messages.blank')) @@ -55,7 +59,7 @@ module Spree redirect_to spree.edit_admin_order_path(@order) else # Jump to next step if order is not complete - redirect_to spree.admin_order_customer_path(@order) + redirect_to spree.admin_order_payments_path(@order) end end diff --git a/app/views/spree/admin/orders/set_distribution.html.haml b/app/views/spree/admin/orders/set_distribution.html.haml index 3579619185..9c2955647f 100644 --- a/app/views/spree/admin/orders/set_distribution.html.haml +++ b/app/views/spree/admin/orders/set_distribution.html.haml @@ -21,6 +21,7 @@ = render 'spree/admin/orders/_form/distribution_fields' -# This param passed to stop validation error in next page due to no line items in order yet: = hidden_field_tag 'suppress_error_msg', "true" + = hidden_field_tag "set_distribution_step", "true" = button_tag :class => 'secondary radius expand small', :id => 'update-button' do %i.icon-arrow-right = t(:next) diff --git a/app/views/spree/admin/shared/_order_tabs.html.haml b/app/views/spree/admin/shared/_order_tabs.html.haml index 4f4c70bfca..8b46243b08 100644 --- a/app/views/spree/admin/shared/_order_tabs.html.haml +++ b/app/views/spree/admin/shared/_order_tabs.html.haml @@ -44,22 +44,22 @@ %nav.menu %ul - - order_details_classes = "active" if current == "Order Details" - %li{ class: order_details_classes } - = link_to_with_icon 'icon-edit', t(:order_details), spree.edit_admin_order_url(@order) - - customer_details_classes = "active" if current == "Customer Details" %li{ class: customer_details_classes } = link_to_with_icon 'icon-user', t(:customer_details), spree.admin_order_customer_url(@order) - - adjustments_classes = "active" if current == "Adjustments" - %li{ class: adjustments_classes } - = link_to_with_icon 'icon-cogs', t(:adjustments), spree.admin_order_adjustments_url(@order) + - order_details_classes = "active" if current == "Order Details" + %li{ class: order_details_classes } + = link_to_with_icon 'icon-edit', t(:order_details), spree.edit_admin_order_url(@order) - payments_classes = "active" if current == "Payments" %li{ class: payments_classes } = link_to_with_icon 'icon-credit-card', t(:payments), spree.admin_order_payments_url(@order) + - adjustments_classes = "active" if current == "Adjustments" + %li{ class: adjustments_classes } + = link_to_with_icon 'icon-cogs', t(:adjustments), spree.admin_order_adjustments_url(@order) + - if @order.completed? - authorizations_classes = "active" if current == "Return Authorizations" %li{ class: authorizations_classes } From fa9c2b24f2b7a4bce9669d9b53e5bc1214704f4d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 19 May 2022 17:18:46 +0200 Subject: [PATCH 2/4] Select Customer Details as step title for Set Distribution step --- app/views/spree/admin/orders/set_distribution.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/spree/admin/orders/set_distribution.html.haml b/app/views/spree/admin/orders/set_distribution.html.haml index 9c2955647f..8cd9038788 100644 --- a/app/views/spree/admin/orders/set_distribution.html.haml +++ b/app/views/spree/admin/orders/set_distribution.html.haml @@ -9,7 +9,7 @@ \# = @order.number -= render 'spree/admin/shared/order_tabs', :current => 'Order Details' += render 'spree/admin/shared/order_tabs', :current => 'Customer Details' = csrf_meta_tags From f087b7184ca1b1ffc70e15d44e7738ff589f1e0e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 20 May 2022 09:16:39 +0200 Subject: [PATCH 3/4] Update specs to reflect order steps changes --- .../spree/admin/orders_controller_spec.rb | 4 +-- spec/system/admin/order_spec.rb | 27 ++++++++++--------- spec/system/admin/variant_overrides_spec.rb | 1 + 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/spec/controllers/spree/admin/orders_controller_spec.rb b/spec/controllers/spree/admin/orders_controller_spec.rb index a6251602c5..9934ab66c7 100644 --- a/spec/controllers/spree/admin/orders_controller_spec.rb +++ b/spec/controllers/spree/admin/orders_controller_spec.rb @@ -239,12 +239,12 @@ describe Spree::Admin::OrdersController, type: :controller do end context "and no errors" do - it "updates distribution charges and redirects to customer details page" do + it "updates distribution charges and redirects to payments page" do expect_any_instance_of(Spree::Order).to receive(:recreate_all_fees!) spree_put :update, params - expect(response).to redirect_to spree.admin_order_customer_path(order) + expect(response).to redirect_to spree.admin_order_payments_path(order) end end diff --git a/spec/system/admin/order_spec.rb b/spec/system/admin/order_spec.rb index ee91f1f354..9a7368c044 100644 --- a/spec/system/admin/order_spec.rb +++ b/spec/system/admin/order_spec.rb @@ -64,6 +64,12 @@ describe ' expect(page).not_to have_selector '.flash.error' expect(page).not_to have_content "Line items can't be blank" + expect(page).to have_selector 'h1', text: 'Customer Details' + o = Spree::Order.last + expect(o.distributor).to eq(distributor) + expect(o.order_cycle).to eq(order_cycle) + + click_link "Order Details" click_button "Update And Recalculate Fees" expect(page).to have_selector '.flash.error' expect(page).to have_content "Line items can't be blank" @@ -77,11 +83,6 @@ describe ' expect(page).to have_selector 'td', text: product.name click_button 'Update' - - expect(page).to have_selector 'h1', text: 'Customer Details' - o = Spree::Order.last - expect(o.distributor).to eq(distributor) - expect(o.order_cycle).to eq(order_cycle) end it "can add a product to an existing order" do @@ -372,12 +373,6 @@ describe ' # When I create a new order login_as user new_order_with_distribution(distributor, order_cycle) - select2_select product.name, from: 'add_variant_id', search: true - find('button.add_variant').click - page.has_selector? "table.index tbody[data-hook='admin_order_form_line_items'] tr" # Wait for JS - click_button 'Update' - - expect(page).to have_selector 'h1.js-admin-page-title', text: "Customer Details" # The customer selection partial should be visible expect(page).to have_selector '#select-customer' @@ -385,7 +380,6 @@ describe ' # And I select that customer's email address and save the order tomselect_search_and_select customer.email, from: 'customer_search_override' click_button 'Update' - expect(page).to have_selector "h1.js-admin-page-title", text: "Customer Details" # Then their addresses should be associated with the order order = Spree::Order.last @@ -395,6 +389,12 @@ describe ' expect(order.bill_address.zipcode).to eq customer.bill_address.zipcode expect(order.ship_address.city).to eq customer.ship_address.city expect(order.bill_address.city).to eq customer.bill_address.city + + click_link "Order Details" + + select2_select product.name, from: 'add_variant_id', search: true + find('button.add_variant').click + page.has_selector? "table.index tbody[data-hook='admin_order_form_line_items'] tr" # Wait for JS end context "as an enterprise manager" do @@ -686,6 +686,8 @@ describe ' it "creating an order with distributor and order cycle" do new_order_with_distribution(distributor1, order_cycle1) + expect(page).to have_selector 'h1', text: 'Customer Details' + click_link "Order Details" expect(page).to have_content 'ADD PRODUCT' select2_select product.name, from: 'add_variant_id', search: true @@ -704,7 +706,6 @@ describe ' click_button 'Update' - expect(page).to have_selector 'h1', text: 'Customer Details' o = Spree::Order.last expect(o.distributor).to eq distributor1 expect(o.order_cycle).to eq order_cycle1 diff --git a/spec/system/admin/variant_overrides_spec.rb b/spec/system/admin/variant_overrides_spec.rb index 21b0991a26..3e52064295 100644 --- a/spec/system/admin/variant_overrides_spec.rb +++ b/spec/system/admin/variant_overrides_spec.rb @@ -449,6 +449,7 @@ describe " select2_select distributor.name, from: 'order_distributor_id' select2_select order_cycle.name, from: 'order_order_cycle_id' click_button 'Next' + click_link "Order Details" end # Reproducing a bug, issue #1446 From 4791b570e41fc1c7aec551ab83acb9dfb731c3c2 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 20 May 2022 15:39:09 +0200 Subject: [PATCH 4/4] Update specs ; Expect customer creation later when creating order The terms are a bit confusing. Updating "Customer Details" updates attributes of the order which will later be used to create a customer. Customers are not created while the order is in `cart` state. That happens later when the order advances automatically. --- spec/system/admin/order_spec.rb | 53 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/spec/system/admin/order_spec.rb b/spec/system/admin/order_spec.rb index 9a7368c044..c206280d6d 100644 --- a/spec/system/admin/order_spec.rb +++ b/spec/system/admin/order_spec.rb @@ -277,32 +277,10 @@ describe ' login_as user new_order_with_distribution(distributor, order_cycle) - expect(page).to have_content I18n.t('spree.add_product').upcase + expect(page).to have_selector 'h1', text: "Customer Details" end it "creates order and shipment successfully and allows proceeding to payment" do - select2_select product.name, from: 'add_variant_id', search: true - - within("table.stock-levels") do - expect(page).to have_selector("#stock_item_quantity") - fill_in "stock_item_quantity", with: 50 - find("button.add_variant").click - end - - expect(page).to_not have_selector("table.stock-levels") - expect(page).to have_selector("table.stock-contents") - - within("tr.stock-item") do - expect(page).to have_text("50") - end - - order = Spree::Order.last - expect(order.line_items.first.quantity).to eq(50) - expect(order.shipments.count).to eq(1) - - click_button "Update And Recalculate Fees" - expect(page).to have_selector 'h1', text: "Customer Details" - fill_in "order_email", with: "test@test.com" expect(page).to have_selector('#order_ship_address_attributes_firstname') @@ -326,19 +304,40 @@ describe ' select "Victoria", from: "order_bill_address_attributes_state_id" fill_in "order_bill_address_attributes_phone", with: "111 1111 1111" - expect { click_button "Update" }.to change { Customer.count }.by(1) + click_button "Update" + + expect(page).to have_content "Customer Details updated" + click_link "Order Details" + + expect(page).to have_content I18n.t('spree.add_product').upcase + select2_select product.name, from: 'add_variant_id', search: true + + within("table.stock-levels") do + expect(page).to have_selector("#stock_item_quantity") + fill_in "stock_item_quantity", with: 50 + find("button.add_variant").click + end + + expect(page).to_not have_selector("table.stock-levels") + expect(page).to have_selector("table.stock-contents") + + within("tr.stock-item") do + expect(page).to have_text("50") + end + + order = Spree::Order.last + expect(order.line_items.first.quantity).to eq(50) + expect(order.shipments.count).to eq(1) new_customer = Customer.last - expect(new_customer.full_name).to eq('Clark Kent') expect(new_customer.bill_address.address1).to eq('Smallville') expect(new_customer.bill_address.city).to eq('Kansas') expect(new_customer.bill_address.zipcode).to eq('SP1 M11') expect(new_customer.bill_address.phone).to eq('111 1111 1111') - expect(new_customer.bill_address).to eq(new_customer.ship_address) - expect(page).to have_content "Customer Details updated" + click_button "Update And Recalculate Fees" click_link "Payments"