Class: ShopifyDashboardPlus::RevenueReport

Inherits:
Report
  • Object
show all
Defined in:
lib/shopify_dashboard_plus/report.rb

Constant Summary

Constants included from ApplicationHelpers

ApplicationHelpers::DESIRED_FIELDS

Instance Method Summary collapse

Methods inherited from Report

#initialize

Methods included from ApplicationHelpers

#close_connection, #connected?, #date_range_valid?, #date_today, #days, #display_as_currency, #get_average_revenue, #get_daily_revenues, #get_date_range, #get_detailed_revenue_metrics, #get_host, #get_list_of_orders, #get_total_revenue, #hash_to_graph_format, #open_connection, #order_parameters_paginate, #set_connection, #shop_name, #strip_protocol

Constructor Details

This class inherits a constructor from ShopifyDashboardPlus::Report

Instance Method Details

#revenue_per_countryObject



83
84
85
86
87
88
89
90
91
92
# File 'lib/shopify_dashboard_plus/report.rb', line 83

def revenue_per_country
  revenue_per_country = []
  @orders.each do |order|
    order.line_items.each do |item|
      revenue_per_country.push({:name => item.title, 
                                :data => [order.billing_address.country, item.price.to_f]})
    end
  end
  hash_to_graph_format(revenue_per_country, merge_results: true)
end

#revenue_per_price_pointObject



94
95
96
97
98
99
100
# File 'lib/shopify_dashboard_plus/report.rb', line 94

def revenue_per_price_point
  revenue_per_price_point = Hash.new(0)
  @line_items.each do |item|
    revenue_per_price_point[item.price] = revenue_per_price_point[item.price].plus(item.price)
  end
  revenue_per_price_point.sort_by{ |x,y| x.to_f }.to_h rescue {}
end

#revenue_per_productObject



102
103
104
105
106
107
108
# File 'lib/shopify_dashboard_plus/report.rb', line 102

def revenue_per_product
  revenue_per_product = Hash.new(0.0)
  @line_items.each do |item|
    revenue_per_product[item.title] = revenue_per_product[item.title].plus(item.price)
  end
  revenue_per_product
end

#to_hObject



110
111
112
113
114
115
116
# File 'lib/shopify_dashboard_plus/report.rb', line 110

def to_h
  {
    :revenue_per_country => revenue_per_country,
    :revenue_per_product => revenue_per_product,
    :revenue_per_price_point => revenue_per_price_point,
  }
end