Class: Spree::Base

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

Direct Known Subclasses

Address, Adjustment, AdjustmentReason, Asset, Calculator, Carton, Classification, Country, CustomerReturn, InventoryUnit, LegacyUser, LineItem, LineItemAction, LogEntry, OptionType, OptionValue, OptionValuesVariant, Order, OrderMutex, OrderPromotion, OrderStockLocation, Payment, PaymentCaptureEvent, PaymentMethod, PaymentSource, Preference, Price, Product, ProductOptionType, ProductPromotionRule, ProductProperty, Promotion, PromotionAction, PromotionCategory, PromotionCode, PromotionRule, PromotionRuleTaxon, PromotionRuleUser, Property, Refund, RefundReason, Reimbursement, Reimbursement::Credit, ReimbursementType, ReturnAuthorization, ReturnItem, ReturnReason, Role, RoleUser, Shipment, ShippingCategory, ShippingMethod, ShippingMethodCategory, ShippingMethodStockLocation, ShippingMethodZone, ShippingRate, State, StateChange, StockItem, StockLocation, StockMovement, StockTransfer, Store, StoreCreditCategory, StoreCreditEvent, StoreCreditType, StoreCreditUpdateReason, StorePaymentMethod, TaxCategory, TaxRate, Taxon, Taxonomy, TransferItem, UnitCancel, UserAddress, UserStockLocation, Variant, VariantPropertyRule, VariantPropertyRuleCondition, VariantPropertyRuleValue, Zone, ZoneMember

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Preferences::Preferable

#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Class Method Details

+ (Object) display_includes

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.



35
36
37
# File 'app/models/spree/base.rb', line 35

def self.display_includes
  where(nil)
end

+ (Object) page(num)



23
24
25
# File 'app/models/spree/base.rb', line 23

def self.page(num)
  send Kaminari.config.page_method_name, num
end

+ (Object) preference(*args)

Only run preference initialization on models which requires it. Improves performance of record initialization slightly.



15
16
17
18
19
20
# File 'app/models/spree/base.rb', line 15

def self.preference(*args)
  # after_initialize can be called multiple times with the same symbol, it
  # will only be called once on initialization.
  after_initialize :initialize_preference_defaults
  super
end

Instance Method Details

- (Object) initialize_preference_defaults



7
8
9
10
11
# File 'app/models/spree/base.rb', line 7

def initialize_preference_defaults
  if has_attribute?(:preferences)
    self.preferences = default_preferences.merge(preferences)
  end
end