Class: Spree::Admin::DashboardController

Inherits:
BaseController
  • Object
show all
Includes:
AnalyticsConcern
Defined in:
app/controllers/spree/admin/dashboard_controller.rb

Instance Method Summary collapse

Methods included from AnalyticsConcern

#analytics_time_range, #calc_growth_rate, #previous_analytics_time_range, #same_day?, #set_analytics_defaults

Methods included from BreadcrumbConcern

#add_breadcrumb_icon_instance_var

Instance Method Details

#analyticsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/spree/admin/dashboard_controller.rb', line 20

def analytics
  @orders_scope = current_store.orders.complete.where(currency: params[:analytics_currency])
  @products_scope = current_store.products

  if defined?(Spree::Vendor)
    # for vendors we need to count there sub-orders
    # for admins we need to counnt only the main orders (the ones that are splitted)
    @orders_scope = if @vendor.present?
                      @orders_scope.with_vendor(@vendor.id)
                    elsif @orders_scope.respond_to?(:without_vendor)
                      @orders_scope.without_vendor
                    end
  end

  load_top_products

  sales_total_sum = @orders_scope.where(completed_at: analytics_time_range).sum(:total)
  @sales_total = Spree::Money.new(sales_total_sum, currency: params[:analytics_currency])
  previous_sales_total = @orders_scope.where(completed_at: previous_analytics_time_range).sum(:total)
  @sales_growth_rate = calc_growth_rate(sales_total_sum, previous_sales_total)

  @orders_total = @orders_scope.where(completed_at: analytics_time_range).count
  previous_orders_total = @orders_scope.where(completed_at: previous_analytics_time_range).count
  @orders_growth_rate = calc_growth_rate(@orders_total, previous_orders_total)

  orders_avg = @orders_scope.where(completed_at: analytics_time_range).average(:total).to_f
  @orders_average = Spree::Money.new(orders_avg, currency: params[:analytics_currency])
  previous_orders_average = @orders_scope.where(completed_at: previous_analytics_time_range).average(:total).to_f
  @orders_average_growth_rate = calc_growth_rate(orders_avg, previous_orders_average)

  @grouped_orders_scope = if same_day?
                            @orders_scope.group_by_hour(:completed_at, range: analytics_time_range, time_zone: current_store.preferred_timezone,
                                                                       default_value: 0.0)
                          else
                            @orders_scope.group_by_day(:completed_at, range: analytics_time_range, time_zone: current_store.preferred_timezone,
                                                                      default_value: 0.0)
                          end

  load_analytics_data
end

#dismiss_enterprise_edition_noticeObject

PATCH /admin/dashboard/dismiss_enterprise_edition_notice



62
63
64
65
# File 'app/controllers/spree/admin/dashboard_controller.rb', line 62

def dismiss_enterprise_edition_notice
  session[:spree_enterprise_edition_notice_dismissed] = true
  redirect_back(fallback_location: spree.admin_dashboard_path)
end

#dismiss_updater_noticeObject

PATCH /admin/dashboard/dismiss_updater_notice



68
69
70
71
# File 'app/controllers/spree/admin/dashboard_controller.rb', line 68

def dismiss_updater_notice
  session[:spree_updater_notice_dismissed] = { value: true, expires_at: 7.days.from_now }
  redirect_back(fallback_location: spree.admin_dashboard_path)
end

#getting_startedObject



15
16
17
18
# File 'app/controllers/spree/admin/dashboard_controller.rb', line 15

def getting_started
  @breadcrumb_icon = 'map'
  add_breadcrumb Spree.t('admin.getting_started'), spree.admin_getting_started_path
end

#showObject



10
11
12
13
# File 'app/controllers/spree/admin/dashboard_controller.rb', line 10

def show
  @breadcrumb_icon = 'home'
  add_breadcrumb Spree.t(:home), spree.admin_dashboard_path
end