Class: Spree::Base

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Core::Permalinks, RansackableAttributes
Defined in:
app/models/spree/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Core::Permalinks

#generate_permalink, #save_permalink

Class Method Details

.display_includesObject

Provides a scope that should be included any time products are fetched with the intention of displaying to the user.

Allows individual stores to include any active record scopes or joins when products are displayed.



67
68
69
# File 'app/models/spree/base.rb', line 67

def self.display_includes
  where(nil)
end

.page(num) ⇒ Object



51
52
53
54
55
56
57
# File 'app/models/spree/base.rb', line 51

def self.page(num)
  Spree::Deprecation.warn \
    "Redefining Spree::Base.page for a different kaminari page name is better done inside " \
    "your own app. This will be removed from future versions of solidus."

  send Kaminari.config.page_method_name, num
end

.preference(*args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/spree/base.rb', line 9

def self.preference(*args)
  Spree::Deprecation.warn <<~WARN
    #{name} has a `preferences` column, but does not explicitly (de)serialize this column.
    In order to make #{name} work with future versions of Solidus (and Rails), please add the
    following line to your class:
    ```
    class #{name}
      include Spree::Preferences::Persistable
      ...
    end
    ```
  WARN
  include Spree::Preferences::Persistable
  preference(*args)
end

Instance Method Details

#preferencesObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/spree/base.rb', line 25

def preferences
  value = read_attribute(:preferences)
  if !value.is_a?(Hash)
    Spree::Deprecation.warn <<~WARN
      #{self.class.name} has a `preferences` column, but does not explicitly (de)serialize this column.
      In order to make #{self.class.name} work with future versions of Solidus (and Rails), please add the
      following lines to your class:
      ```
      class #{self.class.name}
        include Spree::Preferences::Persistable
        ...
      end
      ```
    WARN
    self.class.include Spree::Preferences::Persistable

    ActiveRecord::Type::Serialized.new(
      ActiveRecord::Type::Text.new,
      ActiveRecord::Coders::YAMLColumn.new(:preferences, Hash)
    ).deserialize(value)
  else
    value
  end
end