From 6f50c45bbac5549735292e56e76b46407313232b Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 28 Mar 2014 15:43:28 +1100 Subject: [PATCH] Adding the last checkout distributor to the account link --- .../controllers/account_sidebar_controller.js.coffee | 7 +++++++ app/helpers/spree/orders_helper.rb | 4 ++++ app/views/shared/_sidebar.html.haml | 8 +++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/darkswarm/controllers/account_sidebar_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/account_sidebar_controller.js.coffee index d049f4639f..247ef933e8 100644 --- a/app/assets/javascripts/darkswarm/controllers/account_sidebar_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/account_sidebar_controller.js.coffee @@ -7,3 +7,10 @@ window.AccountSidebarCtrl = Darkswarm.controller "AccountSidebarCtrl", ($scope, $scope.select = -> Navigation.navigate($scope.path) + + $scope.emptyCart = (href, ev)-> + console.log href + if $(ev.delegateTarget).hasClass "empties-cart" + location.href = href if confirm "Changing your collection date will clear your cart." + else + location.href = href diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb index d8430f723f..f3a7b433f8 100644 --- a/app/helpers/spree/orders_helper.rb +++ b/app/helpers/spree/orders_helper.rb @@ -14,5 +14,9 @@ module Spree def alternative_available_distributors(order) DistributionChangeValidator.new(order).available_distributors(Enterprise.all) - [order.distributor] end + + def last_completed_order + spree_current_user.orders.complete.last + end end end diff --git a/app/views/shared/_sidebar.html.haml b/app/views/shared/_sidebar.html.haml index 4c36651dca..c77805cae6 100644 --- a/app/views/shared/_sidebar.html.haml +++ b/app/views/shared/_sidebar.html.haml @@ -12,10 +12,12 @@ .panel %p %strong= link_to "Manage my account", account_path - - if order = spree_current_user.orders.last + - if order = last_completed_order %dl - %dt Last distributor: + %dt Last hub: %dd - = link_to "#{order.distributor.name}".html_safe, shop_enterprise_path(order.distributor), {class: distributor_link_class(order.distributor)} + = link_to "#{order.distributor.name}".html_safe, "", + {class: distributor_link_class(order.distributor), + "ng-click" => "emptyCart('#{main_app.shop_enterprise_path(order.distributor)}', $event)"} = yield :sidebar