Model preferences allow you to easily extend Spree models with configuration options. Thanks to this you can store useful information on Spree models, eg.Documentation Index
Fetch the complete documentation index at: https://spreecommerce.org/docs/llms.txt
Use this file to discover all available pages before exploring further.
Defining Model Preferences
To define a model preference, you need to add them to your model class. Make sure to generate a migration to add thepreferences column to the table. This column will store the preferences in a serialized format.
language preference to the User model. The preference will be stored in the newly created preferences column of the spree_users table. You can add more preferences to the model in the same way.
Accessing Model Preferences
Once preferences have been defined for a model, they can be accessed either using the shortcut methods that are generated for each preference or the generic methods that are not specific to a particular preference.Shortcut Methods
There are several shortcut methods that are generated. They are shown below. Query methods:Remember to run
user.save after setting the preference value to save the changes to the database.Generic Methods
Each shortcut method is essentially a wrapper for the various generic methods shown below: Query method:Accessing All Preferences
You can get a hash of all stored preferences by accessing thepreferences helper:
Models with preferences
The following Spree models already have preferences defined:Spree::CalculatorSpree::GatewaySpree::PageBlockSpree::PageSectionSpree::PageSpree::PaymentMethodSpree::PromotionRuleSpree::StoreSpree::Theme

