Class: SpreeCmCommissioner::Routes::FindPopular

Inherits:
Object
  • Object
show all
Defined in:
app/finders/spree_cm_commissioner/routes/find_popular.rb

Instance Method Summary collapse

Constructor Details

#initialize(vendor: nil, tenant: nil, route_type: nil, limit: 20) ⇒ FindPopular

Returns a new instance of FindPopular.



10
11
12
13
14
15
# File 'app/finders/spree_cm_commissioner/routes/find_popular.rb', line 10

def initialize(vendor: nil, tenant: nil, route_type: nil, limit: 20)
  @vendor = vendor
  @tenant = tenant
  @route_type = route_type
  @limit = limit.to_i
end

Instance Method Details

#executeObject



17
18
19
20
21
22
23
# File 'app/finders/spree_cm_commissioner/routes/find_popular.rb', line 17

def execute
  scope = SpreeCmCommissioner::Route.includes(:origin_place, :destination_place, :route_photos)
  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