From f3f67144723b5c730225584dcfca6041bba35d09 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 9 Nov 2016 12:50:53 +1100 Subject: [PATCH] Add message about previous orders on checkout page The message appears if the user ordered before within the same order cycle and the shop allows to change previous orders. --- app/helpers/enterprises_helper.rb | 6 +++++- app/views/checkout/_already_ordered.html.haml | 2 ++ app/views/checkout/_form.html.haml | 1 + app/views/shared/menu/_cart.html.haml | 2 +- config/locales/en.yml | 9 +++++++++ .../consumer/shopping/checkout_spec.rb | 18 ++++++++++++++++++ 6 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 app/views/checkout/_already_ordered.html.haml diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index c20ac636cf..5987b20475 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -89,7 +89,11 @@ module EnterprisesHelper distance_of_time_in_words(Time.zone.now, enterprise.shop_trial_start_date + Spree::Config[:shop_trial_length_days].days) end - def show_bought_items? + def order_changes_allowed? current_order.andand.distributor.andand.allow_order_changes? end + + def show_bought_items? + order_changes_allowed? && current_order.finalised_line_items.present? + end end diff --git a/app/views/checkout/_already_ordered.html.haml b/app/views/checkout/_already_ordered.html.haml new file mode 100644 index 0000000000..1327365a2f --- /dev/null +++ b/app/views/checkout/_already_ordered.html.haml @@ -0,0 +1,2 @@ +%p.alert-box.info + = t '.message_html', cart: link_to(t('.cart'), cart_path) diff --git a/app/views/checkout/_form.html.haml b/app/views/checkout/_form.html.haml index 65ed90b069..42f31f4a35 100644 --- a/app/views/checkout/_form.html.haml +++ b/app/views/checkout/_form.html.haml @@ -11,6 +11,7 @@ = render "checkout/billing", f: f = render "checkout/shipping", f: f = render "checkout/payment", f: f + = render "checkout/already_ordered", f: f if show_bought_items? %p %button.button.primary{type: :submit} = t :checkout_send diff --git a/app/views/shared/menu/_cart.html.haml b/app/views/shared/menu/_cart.html.haml index 0cbe12b917..37c67fd067 100644 --- a/app/views/shared/menu/_cart.html.haml +++ b/app/views/shared/menu/_cart.html.haml @@ -48,7 +48,7 @@ = "{{ Cart.dirty ? '#{t(:cart_updating)}' : (Cart.empty() ? '#{t(:cart_empty)}' : '#{t(:cart_edit)}' ) }}" %a.button.primary.tiny{href: checkout_path, "ng-disabled" => "Cart.dirty || Cart.empty()"} = t '.checkout' - - if show_bought_items? + - if order_changes_allowed? %h5{"ng-if" => "Cart.line_items_finalised.length", style: 'margin-top: 1em'} = t '.already_ordered_products' %table diff --git a/config/locales/en.yml b/config/locales/en.yml index 3a421a192d..92944c9298 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -550,6 +550,15 @@ en: invoice_style2?: Use the alternative invoice model that includes total tax breakdown per rate and tax rate info per item (not yet suitable for countries displaying prices excluding tax) enable_receipt_printing?: Show options for printing receipts using thermal printers in order dropdown? +# Frontend views +# +# These keys are referenced relatively like `t('.message')` in +# app/views/checkout/_already_ordered.html.haml. +# + checkout: + already_ordered: + cart: "cart" + message_html: "You have an order for this order cycle already. Check the %{cart} to see the items you ordered before. You can also cancel items as long as the order cycle is open." home: hubs: show_closed_shops: "Show closed shops" diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index 18360b806a..da846bae88 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -113,6 +113,24 @@ feature "As a consumer I want to check out my cart", js: true, retry: 3 do user.reload.bill_address.address1.should eq '123 Your Head' user.reload.ship_address.address1.should eq '123 Your Head' end + + it "it doesn't tell about previous orders" do + expect(page).to_not have_content("You have an order for this order cycle already.") + end + + context "with previous orders" do + let!(:prev_order) { create(:completed_order_with_totals, order_cycle: order_cycle, distributor: distributor, user: order.user) } + + before do + order.distributor.allow_order_changes = true + order.distributor.save + end + + it "informs about previous orders" do + visit checkout_path + expect(page).to have_content("You have an order for this order cycle already.") + end + end end context "on the checkout page" do