Class: Workarea::Admin::Insights::ProductViewModel
- Inherits:
-
ApplicationViewModel
- Object
- ApplicationViewModel
- Workarea::Admin::Insights::ProductViewModel
show all
- Includes:
- InsightsDetails
- Defined in:
- app/view_models/workarea/admin/insights/product_view_model.rb
Instance Method Summary
collapse
#current_period, #ends_at, #previous_ends_at, #previous_period, #previous_starts_at, #starts_at
Instance Method Details
#average_price ⇒ Object
39
40
41
42
|
# File 'app/view_models/workarea/admin/insights/product_view_model.rb', line 39
def average_price
return nil if orders.zero?
(merchandise - discounts) / units_sold
end
|
#average_price_percent_change ⇒ Object
49
50
51
52
|
# File 'app/view_models/workarea/admin/insights/product_view_model.rb', line 49
def average_price_percent_change
return nil if previous_average_price.blank?
calculate_percent_change(previous_average_price, average_price)
end
|
#feed ⇒ Object
13
14
15
16
17
|
# File 'app/view_models/workarea/admin/insights/product_view_model.rb', line 13
def feed
@feed ||= InsightViewModel.wrap(
Workarea::Insights::Base.by_product(model.id).to_a
)
end
|
#previous_average_price ⇒ Object
44
45
46
47
|
# File 'app/view_models/workarea/admin/insights/product_view_model.rb', line 44
def previous_average_price
return nil if previous_orders.zero?
(previous_merchandise - previous_discounts) / previous_units_sold
end
|
#skus ⇒ Object
27
28
29
|
# File 'app/view_models/workarea/admin/insights/product_view_model.rb', line 27
def skus
@skus ||= skus_report.results.map { |r| OpenStruct.new(r) }
end
|
#skus_report ⇒ Object
31
32
33
34
35
36
37
|
# File 'app/view_models/workarea/admin/insights/product_view_model.rb', line 31
def skus_report
@skus_report ||= Workarea::Reports::SalesBySku.new(
skus: model.skus,
starts_at: starts_at,
ends_at: ends_at
)
end
|
#top? ⇒ Boolean
19
20
21
|
# File 'app/view_models/workarea/admin/insights/product_view_model.rb', line 19
def top?
Workarea::Insights::TopProducts.current.include?(product_id: model.id)
end
|
#trending? ⇒ Boolean
23
24
25
|
# File 'app/view_models/workarea/admin/insights/product_view_model.rb', line 23
def trending?
Workarea::Insights::TrendingProducts.current.include?(product_id: model.id)
end
|