Getting started
Customizing Spree
Use Cases
- Multi-Tenant
Upgrading
- Quickstart
- Upgrade Guides
Contributing
Security
Advanced
Storefront Helper Methods
Here you can find a list of helper methods provided by Spree that are available in the Storefront that you can use in every template.
The list is incomplete. We’re working on it!
current_currency
Returns the currently selected currency. By default in the Storefront this will be store.default_currency
. This can be changed in the Settings -> Store Defaults
page.
<%= current_currency %>
will return
USD
current_locale
Returns the currently selected locale. By default in the Storefront this will be store.default_locale
. This can be changed in the Settings -> Store Defaults
page. If there are multiple locales available, it will return the locale that is currently selected by the user.
<%= current_locale %>
Locale also affects the storefront URLs. For example, if the default locale is en
and the user selects fr
, the URL will be /fr/products/123
.
current_order
The order number
Example: R123456789
The total amount of the order Example: 99.99
Formatted total with currency Example: “$99.99”
Sum of all line item amounts pre-tax Example: 89.99
Formatted item total with currency Example: “$89.99”
Sum of all adjustments Example: -10.00
Formatted adjustment total with currency Example: ”-$10.00”
Sum of all tax amounts Example: 13.25
Formatted tax total with currency Example: “$13.25”
Sum of shipment amounts Example: 10.00
Formatted shipment total with currency Example: “$10.00”
Sum of all promotion adjustments Example: -15.00
Formatted promotion total with currency Example: ”-$15.00”
Sum of included tax amounts Example: 8.25
Sum of additional tax amounts Example: 5.00
Sum of completed payment amounts Example: 99.99
Current order state
Example: cart
Customer email address
Example: [email protected]
Associated user ID Example: 123
Associated user object
User ID Example: 123
User email address
Example: [email protected]
User first name
Example: John
User last name
Example: Doe
Default billing address object
Address ID Example: 456
Address line 1
Example: 123 Main St
Address line 2
Example: Apt 1
City
Example: Anytown
Zipcode
Example: 12345
State name, used when the country doesn’t require a state object
Example: Some Province
Returns either state.name (if state is present) or state_name
Example: California
or Some Province
Country name
Example: United States
Country ISO code
Example: US
Country object
Country ID Example: 1
Country name
Example: United States
Country ISO3 code
Example: USA
Country ISO code
Example: US
Country ISO name
Example: UNITED STATES
Whether states are required for this country
Example: true
Whether zipcodes are required for this country
Example: true
Default shipping address object
Address ID Example: 456
Address line 1
Example: 123 Main St
Address line 2
Example: Apt 1
City
Example: Anytown
Zipcode
Example: 12345
State name, used when the country doesn’t require a state object
Example: Some Province
Returns either state.name (if state is present) or state_name
Example: California
or Some Province
Country name
Example: United States
Country ISO code
Example: US
Country object
Country ID Example: 1
Country name
Example: United States
Country ISO3 code
Example: USA
Country ISO code
Example: US
Country ISO name
Example: UNITED STATES
Whether states are required for this country
Example: true
Whether zipcodes are required for this country
Example: true
User tags (tags are used manageable by store admins) Example:
["vip", "wholesale"]
When the order was completed (placed and paid). For orders in cart
state, this will be nil
.
Example: 2023-06-15 13:45:00
Billing address ID Example: 456
Billing address object
Address ID Example: 456
Address line 1
Example: 123 Main St
Address line 2
Example: Apt 1
City
Example: Anytown
Zipcode
Example: 12345
State name, used when the country doesn’t require a state object
Example: Some Province
Returns either state.name (if state is present) or state_name
Example: California
or Some Province
Country name
Example: United States
Country ISO code
Example: US
Country object
Country ID Example: 1
Country name
Example: United States
Country ISO3 code
Example: USA
Country ISO code
Example: US
Country ISO name
Example: UNITED STATES
Whether states are required for this country
Example: true
Whether zipcodes are required for this country
Example: true
Shipping address ID Example: 457
Shipping address object
Address ID Example: 456
Address line 1
Example: 123 Main St
Address line 2
Example: Apt 1
City
Example: Anytown
Zipcode
Example: 12345
State name, used when the country doesn’t require a state object
Example: Some Province
Returns either state.name (if state is present) or state_name
Example: California
or Some Province
Country name
Example: United States
Country ISO code
Example: US
Country object
Country ID Example: 1
Country name
Example: United States
Country ISO3 code
Example: USA
Country ISO code
Example: US
Country ISO name
Example: UNITED STATES
Whether states are required for this country
Example: true
Whether zipcodes are required for this country
Example: true
Payment state (balance_due, credit_owed, failed, paid, void)
Example: paid
Shipment state (backorder, canceled, partial, pending, ready, shipped)
Example: shipped
Order currency
Example: USD
Associated store ID Example: 1
Line items in the order
Line item ID Example: 123
Quantity of the variant ordered Example: 2
Unit price of the variant when ordered Example: 29.99
Formatted unit price with currency Example: “$29.99”
Total price for this line item (quantity * price) Example: 59.98
Formatted total price with currency Example: “$59.98”
Sum of all adjustments for this line item Example: -5.00
Formatted adjustment total with currency Example: ”-$5.00”
Sum of additional tax amounts Example: 4.50
Sum of included tax amounts Example: 2.75
Sum of promotion adjustments Example: -10.00
Formatted promotion total with currency Example: ”-$10.00”
Associated order ID Example: 456
Associated product variant
Variant ID Example: 123
Stock Keeping Unit - unique identifier for the variant Example: “ABC-123”
Name of the variant (inherited from product) Example: “Basic T-Shirt”
Formatted string of option values Example: “Size: Large, Color: Blue”
Full descriptive name including master status or options Example: “Basic T-Shirt - Size: Large, Color: Blue”
Base price of the variant Example: 29.99
Formatted price with currency Example: “$29.99”
Weight of the variant Example: 1.5
Height of the variant Example: 10.0
Width of the variant Example: 5.0
Depth of the variant Example: 2.0
Whether this is the master variant of the product Example: false
Display order position Example: 1
Whether inventory tracking is enabled for this variant Example: true
Whether the variant is available for purchase (not discontinued and product is available) Example: true
Whether the variant currently has stock available Example: true
ID of the associated tax category Example: 1
Cost price of the variant Example: 15.00
Currency of the cost price Example: “USD”
ID of the associated product Example: 456
Currency of the line item Example: “USD”
Returns the current order object. If no order is found, it will return nil
.
Order is automatically created when a user adds a product to the cart.
current_store
Store name Example: “My Store”
Store URL
Example: https://mystore.com
Unique store identifier
Example: my-store
Email address used for sending emails
Example: [email protected]
Default store currency
Example: USD
List of supported currencies
Example: USD,EUR,GBP
Default store locale
Example: en
List of supported locales
Example: en,es,fr
Default country ID
Example: 1
Default country
Country ID Example: 1
Country name
Example: United States
Country ISO3 code
Example: USA
Country ISO code
Example: US
Country ISO name
Example: UNITED STATES
Whether states are required for this country
Example: true
Whether zipcodes are required for this country
Example: true
Checkout zone ID
Example: 2
SEO title
Example: My Amazing Store
Meta description for SEO
Example: The best products at the best prices
Returns the current store Spree::Store instance.
current_theme
Theme ID Example: 1
Theme name
Example: Winter Sale Theme
Checkout sidebar text color
Example: #000000
Custom font code
Example: @import url('https://fonts.googleapis.com/css2?family=Inter&display=swap');
Font family
Example: Inter
Font size scale
Example: 100
Header font family
Example: Inter
Header font size scale
Example: 100
Headings uppercase
Example: true
Button border thickness
Example: 1
Button border opacity
Example: 100
Button border radius
Example: 100
Button shadow opacity
Example: 0
Button shadow horizontal offset
Example: 0
Button shadow vertical offset
Example: 4
Button shadow blur
Example: 5
Input border thickness
Example: 1
Input border opacity
Example: 100
Input border radius
Example: 8
Input shadow opacity
Example: 0
Input shadow horizontal offset
Example: 0
Input shadow vertical offset
Example: 4
Input shadow blur
Example: 5
Border width
Example: 1
Border radius
Example: 6
Border shadow opacity
Example: 0
Border shadow horizontal offset
Example: 0
Border shadow vertical offset
Example: 4
Border shadow blur
Example: 5
Product listing image height
Example: 300
Product listing image width
Example: 300
Product listing image height mobile
Example: 190
Product listing image width mobile
Example: 190
Primary color
Example: #000000
Accent color
Example: #F0EFE9
Danger color
Example: #C73528
Neutral color
Example: #999999
Background color
Example: #FFFFFF
Text color
Example: #000000
Success color
Example: #00C773
Button background color
Example: #000000
Button text color
Example: #ffffff
Button hover background color
Example: #000000
Button hover text color
Example: #ffffff
Button border color
Example: #000000
Border color
Example: #E9E7DC
Sidebar border color
Example: #E9E7DC
Secondary button background color
Example: #000000
Secondary button text color
Example: #ffffff
Secondary button hover background color
Example: #000000
Secondary button hover text color
Example: #ffffff
Input text color
Example: #6b7280
Input background color
Example: #ffffff
Input border color
Example: #000000
Input focus border color
Example: #000000
Input focus background color
Example: #ffffff
Input focus text color
Example: #000000
Checkout sidebar background color
Example: #f3f4f6
Checkout divider background color
Example: #f3f4f6
Checkout sidebar text color
Example: #000000
Returns the current theme Spree::Theme instance.
local_time
Displays a time in the user’s timezone in a human readable format (based on the browser’s timezone).
<%= local_time(order.sent_to_erp_at) %>
Provided by local_time gem.
supported_currencies
Returns the list of supported currencies for the current store as an array of strings.
<%= supported_currencies %>
will return
["USD", "EUR"]
try_spree_current_user
User ID Example: 123
User email address
Example: [email protected]
User first name
Example: John
User last name
Example: Doe
Default billing address object
Address ID Example: 456
Address line 1
Example: 123 Main St
Address line 2
Example: Apt 1
City
Example: Anytown
Zipcode
Example: 12345
State name, used when the country doesn’t require a state object
Example: Some Province
Returns either state.name (if state is present) or state_name
Example: California
or Some Province
Country name
Example: United States
Country ISO code
Example: US
Country object
Country ID Example: 1
Country name
Example: United States
Country ISO3 code
Example: USA
Country ISO code
Example: US
Country ISO name
Example: UNITED STATES
Whether states are required for this country
Example: true
Whether zipcodes are required for this country
Example: true
Default shipping address object
Address ID Example: 456
Address line 1
Example: 123 Main St
Address line 2
Example: Apt 1
City
Example: Anytown
Zipcode
Example: 12345
State name, used when the country doesn’t require a state object
Example: Some Province
Returns either state.name (if state is present) or state_name
Example: California
or Some Province
Country name
Example: United States
Country ISO code
Example: US
Country object
Country ID Example: 1
Country name
Example: United States
Country ISO3 code
Example: USA
Country ISO code
Example: US
Country ISO name
Example: UNITED STATES
Whether states are required for this country
Example: true
Whether zipcodes are required for this country
Example: true
User tags (tags are used manageable by store admins) Example:
["vip", "wholesale"]
Returns the current user object (class depends on the Spree.admin_user_class
configuration). If the user is not signed in, it will return nil
.
If you want to check if the user is signed in, you can use the following:
<%= try_spree_current_user.present? %>