Class: Spree::CollectionRules::AvailableOn

Inherits:
Spree::CollectionRule show all
Defined in:
app/models/spree/collection_rules/available_on.rb

Constant Summary

Constants inherited from Spree::CollectionRule

Spree::CollectionRule::MATCH_POLICIES

Instance Method Summary collapse

Methods included from TypeLabels

#human_description, #human_name

Instance Method Details

#apply(scope) ⇒ Object

value is the number of days; matches products created/available within that window.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/models/spree/collection_rules/available_on.rb', line 7

def apply(scope)
  timezone = collection.store.preferred_timezone
  date = value.to_i.days.ago.beginning_of_day.in_time_zone(timezone)

  if match_policy == 'is_equal_to'
    scope.where(['spree_products.created_at >= ?', date]).or(
      scope.where(['spree_products.available_on >= ?', date])
    )
  else
    scope
  end
end