Class: SpreeCmCommissioner::Routes::FindPopular
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Routes::FindPopular
- Defined in:
- app/finders/spree_cm_commissioner/routes/find_popular.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(vendor: nil, tenant: nil, route_type: nil, limit: 20, include_route_prices: false) ⇒ FindPopular
constructor
A new instance of FindPopular.
Constructor Details
#initialize(vendor: nil, tenant: nil, route_type: nil, limit: 20, include_route_prices: false) ⇒ FindPopular
Returns a new instance of FindPopular.
21 22 23 24 25 26 27 |
# File 'app/finders/spree_cm_commissioner/routes/find_popular.rb', line 21 def initialize(vendor: nil, tenant: nil, route_type: nil, limit: 20, include_route_prices: false) @vendor = vendor @tenant = tenant @route_type = route_type @limit = limit.to_i @include_route_prices = include_route_prices end |
Instance Method Details
#execute ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'app/finders/spree_cm_commissioner/routes/find_popular.rb', line 29 def execute associations = %i[origin_place destination_place route_photos] associations << { route_prices: :price } if include_route_prices scope = SpreeCmCommissioner::Route.includes(*associations) scope = scope.where(vendor_id: vendor.id) if vendor.present? scope = scope.where(tenant_id: tenant.id) if tenant.present? scope = scope.where(route_type: route_type.to_s) if route_type.present? scope.order(fulfilled_order_count: :desc, order_count: :desc).limit(limit) end |