From caf1c9ecd94967560da17a4feceed211f1a60cb1 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 13 Jan 2021 16:35:04 +0100 Subject: [PATCH] Move data fetching from injection helper to action Data fetching is a controller action responsibility. We shouldn't couple the controller with it too much but it should trigger it, not the view-layer. --- app/controllers/spree/users_controller.rb | 5 +++++ app/views/spree/users/show.html.haml | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/spree/users_controller.rb b/app/controllers/spree/users_controller.rb index 1fb03af1f9..5be52a0910 100644 --- a/app/controllers/spree/users_controller.rb +++ b/app/controllers/spree/users_controller.rb @@ -15,6 +15,11 @@ module Spree # Ignores invoice orders, only order where state: 'complete' def show @orders = @user.orders.where(state: 'complete').order('completed_at desc') + + customers = spree_current_user.customers + @shops = Enterprise + .where(id: @orders.pluck(:distributor_id).uniq | customers.pluck(:enterprise_id)) + @unconfirmed_email = spree_current_user.unconfirmed_email end diff --git a/app/views/spree/users/show.html.haml b/app/views/spree/users/show.html.haml index bddce94ce9..ec81685156 100644 --- a/app/views/spree/users/show.html.haml +++ b/app/views/spree/users/show.html.haml @@ -1,7 +1,8 @@ - content_for :injection_data do - = inject_orders - = inject_shops + = inject_json_array("orders", @orders.all, Api::OrderSerializer) + = inject_json_array("shops", @shops.all, Api::ShopForOrdersSerializer) = inject_saved_credit_cards + - if Stripe.publishable_key :javascript angular.module('Darkswarm').value("stripeObject", Stripe("#{Stripe.publishable_key}"))