From 5d9f92eaa7aadb6eef60cc15bfc2d231a28ffd7b Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 6 Apr 2017 12:38:34 +1000 Subject: [PATCH] Adding 'Cancel Order' button to order confimation interface --- app/models/spree/order_decorator.rb | 2 +- app/views/spree/orders/form/_update_buttons.html.haml | 10 +++++----- app/views/spree/orders/show.html.haml | 11 +++++++++-- config/locales/en.yml | 4 +++- spec/features/consumer/shopping/orders_spec.rb | 11 +++++++++-- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 0060b5adf2..2c1fbcf45a 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -290,7 +290,7 @@ Spree::Order.class_eval do end def editable? - distributor.andand.allow_order_changes? && order_cycle.andand.open? + complete? && distributor.andand.allow_order_changes? && order_cycle.andand.open? end private diff --git a/app/views/spree/orders/form/_update_buttons.html.haml b/app/views/spree/orders/form/_update_buttons.html.haml index a319f4ff67..965fd1bde7 100644 --- a/app/views/spree/orders/form/_update_buttons.html.haml +++ b/app/views/spree/orders/form/_update_buttons.html.haml @@ -4,11 +4,11 @@ %i.ofn-i_008-caret-left = t(:back_to_store) - if order.editable? - .columns.show-for-medium-up.medium-6   - -# .columns.small-12.medium-3   - -# = link_to "#", method: :delete, :class => "button secondary expand" do - -# %i.ofn-i_009-close - -# =t(:cancel_order) + .columns.show-for-medium-up.medium-3   + .columns.small-12.medium-3 + = link_to spree.cancel_order_path(@order), method: :put, :class => "button secondary expand" do + %i.ofn-i_009-close + = t(:cancel_order) .columns.small-12.medium-3 = button_tag :class => 'button primary radius expand', :id => 'update-button' do %i.ofn-i_051-check-big diff --git a/app/views/spree/orders/show.html.haml b/app/views/spree/orders/show.html.haml index 41b3682383..24d058db49 100644 --- a/app/views/spree/orders/show.html.haml +++ b/app/views/spree/orders/show.html.haml @@ -10,8 +10,15 @@ .row .columns.large-12.text-center %h2 - = t :orders_show_number - = " #" + @order.number + = t(:orders_show_order_number, number: @order.number) + - if @order.canceled? + %span.brick + = t(:orders_show_cancelled) + %i.ofn-i_009-close + - elsif @order.complete? + %span.turquoise + = t(:orders_show_confirmed) + %i.ofn-i_051-check-big #order{"data-hook" => ""} - if params.has_key? :checkout_complete diff --git a/config/locales/en.yml b/config/locales/en.yml index 9484e0b291..9637a744a3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1047,7 +1047,9 @@ See the %{link} to find out more about %{sitename}'s features and to start using orders_oc_expired_phone: "Phone:" orders_show_title: Order Confirmation orders_show_time: Order ready on - orders_show_number: Order confirmation + orders_show_order_number: "Order #%{number}" + orders_show_cancelled: Cancelled + orders_show_confirmed: Confirmed orders_your_order_has_been_cancelled: "Your order has been cancelled" orders_could_not_cancel: "Sorry, the order could not be cancelled" diff --git a/spec/features/consumer/shopping/orders_spec.rb b/spec/features/consumer/shopping/orders_spec.rb index 11e65806fc..8a55439441 100644 --- a/spec/features/consumer/shopping/orders_spec.rb +++ b/spec/features/consumer/shopping/orders_spec.rb @@ -38,8 +38,10 @@ feature "Order Management", js: true do order.distributor.update_attributes(allow_order_changes: true) end - it "shows already ordered line items" do + it "allows quantity to be changed, items to be removed and the order to be cancelled" do visit spree.order_path(order) + + # Changing the quantity of an item within "tr.variant-#{item1.variant.id}" do expect(page).to have_content item1.product.name expect(page).to have_field 'order_line_items_attributes_0_quantity' @@ -53,13 +55,18 @@ feature "Order Management", js: true do expect(find(".order-total.grand-total")).to have_content "$40.00" expect(item1.reload.quantity).to eq 2 + # Deleting an item within "tr.variant-#{item2.variant.id}" do click_link "delete_line_item_#{item2.id}" end expect(find(".order-total.grand-total")).to have_content "$30.00" - expect(Spree::LineItem.find_by_id(item2.id)).to be nil + + # Cancelling the order + click_link(I18n.t(:cancel_order)) + expect(page).to have_content I18n.t(:orders_show_cancelled) + expect(order.reload).to be_canceled end end end