From ae28d7a96b22eec182502269bc0edc7d754abd2b Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 12 Apr 2017 14:15:52 +1000 Subject: [PATCH] Adding a link in cart to allow user to edit existing + open orders for same OC --- app/helpers/spree/orders_helper.rb | 8 ++++++++ app/views/spree/orders/_bought.html.haml | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb index 5fd0f74fa8..a3183d8273 100644 --- a/app/helpers/spree/orders_helper.rb +++ b/app/helpers/spree/orders_helper.rb @@ -16,5 +16,13 @@ module Spree def cart_count current_order.andand.line_items.andand.count || 0 end + + def changeable_orders + return [] unless spree_current_user && current_distributor && current_order_cycle + Spree::Order.complete.where( + user_id: spree_current_user.id, + distributor_id: current_distributor.id, + order_cycle_id: current_order_cycle.id) + end end end diff --git a/app/views/spree/orders/_bought.html.haml b/app/views/spree/orders/_bought.html.haml index 0f44ef4d22..6c31acd25c 100644 --- a/app/views/spree/orders/_bought.html.haml +++ b/app/views/spree/orders/_bought.html.haml @@ -2,10 +2,11 @@ %tr %td.toggle-bought{ colspan: 2, ng: { click: 'showBought=!showBought' } } %h5.brick - %i{ ng: { class: "{ 'ofn-i_007-caret-right': !showBought, 'ofn-i_005-caret-down': showBought}"}} + %i{ ng: { class: "{ 'ofn-i_007-caret-right': !showBought, 'ofn-i_005-caret-down': showBought}"} } = t(:orders_bought_items_notice, count: @order.finalised_line_items.count) - %td.text-right{ colspan: 3} - %a.edit-finalised.button.radius.expand.small{ href: 'javascript:void(0)', ng: { class: "{secondary: !showBought, primary: showBought}" } } + %td.text-right{ colspan: 3 } + - edit_path = changeable_orders.count > 1 ? spree.user_path : spree.order_path(changeable_orders.first) + %a.edit-finalised.button.radius.expand.small{ href: edit_path, ng: { class: "{secondary: !showBought, primary: showBought}" } } = t(:orders_bought_edit_button) %i.ofn-i_007-caret-right