Storefront
This section covers the Rails storefront which was extracted to spree_frontend
ruby gem.
Styling with SASS variables
Spree 4 under the hood uses Bootstrap 4 for easy theming with some additional Spree-specific SASS variables.
To make those changes live you need to update SCSS variable files located in your project at app/assets/stylesheets/spree/frontend/variables/variables.scss
.
Header
primary-background value but you can replace it with any other value in the variables.scss file.
font-color value but you can replace it with any other value in the variables.scss file.
Footer
_**primary-background and allows you to change the footer color. See a white and a blue example below.
font-color and allows you to change the footer font color. See black and blue font examples below.
Meganav menu
primary-background value but you can replace it with any other value in the variables.scss file.
_**font-color value but you can replace it with any other value in the variables.scss file.
Background
$primary-background - the main background color across the whole site. There are two examples below, of the white and the black backgrounds. Please note that you can also use an image as a background.
$secondary-background - the second background color present across the whole site with examples attached below.
_**primary-background. Please see two examples below.
_**secondary-background. By default, it is set with a $font-color value but you can replace it with any other value in the variables.scss file.
Border color
$global-border-style - this affects the border and separator color throughout the whole site
Fonts
$font-family - this sets the font family used across your site. By default, it is in Sans Serif but you can replace it with any other value in the variables.scss file. Check out these font families you might use.
Input fields
$input-background - this allows you to set a color for all input field backgrounds across the site. See two examples of a white and a yellow backround below.
$second-global-border - this allows you to set a color for all input field borders across the whole site. See an example below with red input field borders.
Primary color
Home page
$primary-color variable changes
- The color of the SHOP NOW button on the main hero image
- The color of the Summer 2019 text and READ MORE button
- The color of the NEW COLLECTION and SUMMER SALE headers inside the categories section
Search results
$primary-color variable changes
- The color of the No results icon
Mega Menu
$primary-color variable changes
- The color of NEW COLLECTION and SUMMER SALE headers inside the banners
PDP
$primary-color variable changes
- The color of the IN STOCK text
- The color of the ADD TO CART button
Cart Page
$primary-color variable changes
- The color of the Trash delete icon for removing items from the cart
- The color of the CHECKOUT button
Cart pop-up
$primary-color variable changes
- The color of the CHECKOUT and VIEW CART buttons
Cart - empty
$primary-color variable changes
- The color of the CONTINUE SHOPPING button
- The color of the Empty cart icon
Checkout - Registration Step
$primary-color variable changes
- The color of the LOG IN, SIGN UP and CONTINUE AS A GUEST buttons
Checkout - Address step
$primary-color variable changes
- The color of the SAVE AND CONTINUE button (this element remains the same across the whole checkout process)
- The color of the Edit icon
Checkout - Payment step
$primary-color variable changes
- The color of the APPLY button
Checkout - Confirm step
$primary-color variable changes
- The color of the PLACE ORDER button
Sign-in page
$primary-color variable changes
The color of the LOG IN and SIGN UP buttons
Sign up page
$primary-color variable changes
- The color of the SIGN UP and LOG IN buttons
My account page
$primary-color variable changes
- The color of the Edit and Trash icons
Edit account page
$primary-color variable changes
- The color of the UPDATE button
Pop-ups
$primary-color variable changes
- The color of the CANCEL and OK buttons
Secondary color
PLP
$secondary-color variable changes
- The color of the chosen color border variant
- The color of the chosen size border variant
- The color of the chosen length border variant
- The color of the chosen price border variant
PDP
$secondary-color variable changes
- The color of the chosen color border variant
- The color of the chosen size border variant
- The color of the chosen length border variant
- The color of the chosen image border
Pop-ups
$secondary-color variable changes
- The color of the Add to bag successfully icon
Log-in and Sign-in page
$secondary-color variable changes
- The color of the Remember me checkbox
- The color of the input: focus
Checkout
$secondary-color variable changes
- The color of individual steps (box, name step, and guideline) - this element remains the same across the whole checkout process
Checkout - Address step
$secondary-color variable changes
- The color of the Use shipping address checkbox
Checkout - Delivery step
$secondary-color variable changes
- The color of delivery type radio buttons
Checkout - Payment step
$secondary-color variable changes
- The color of payment type radio buttons
- The color of payment card radio buttons
Order confirmation page
$secondary-color variable changes
- The color of the successful checkmark icon
Grid breakpoints
Grid breakpoint variable allows you to slightly change element sizes on various devices. These changes are mostly to images and their scale ratio. Feel free to learn more from the Bootstrap manual, though we don’t recommend changing these values unless you really need to.
Rounding for components
$enable-rounded - Enable rounding for components.
Possible values: true or false
“True” example
“False” example
Shadows for components
$enable-shadows - Enable shadow for components
Possible values: true or false
Gradient for components
$enable-gradients - Enable gradient for components
$enable-gradients - Enable gradient for components
Templates
Importing
You can import all templates from spree frontend into your application using this command (in your application root directory):
All of those views will be added to your app/views
directory under spree
folder. You can modify them as you wish.
Assets
Spree’s Asset Pipeline
Spree applications include an app/assets
directory. We’ve taken this one step further by subdividing each top level asset directory (images, JavaScript files, stylesheets) into frontend
and backend
directories. This is designed to keep assets from the frontend and backend from conflicting with each other.
A typical assets directory for a Spree application will look like:
Spree also generates four top level manifests (all.css & all.js, see above) that require all the core extension’s and site specific stylesheets / JavaScript files.
How core extensions (engines) manage assets
All core engines have been updated to provide four asset manifests that are responsible for bundling up all the JavaScript files and stylesheets required for that engine.
For example, Spree provides the following manifests:
These manifests are included by default by the relevant all.css or all.js in the host Spree application. For example, vendor/assets/javascripts/spree/backend/all.js
includes:
External JavaScript libraries, stylesheets and images have also been relocated into vendor/assets.
Managing your application’s assets
Assets that customize your Spree store should go inside the appropriate directories inside vendor/assets/images/spree
, vendor/assets/javascripts/spree
, or vendor/assets/stylesheets/spree
. This is done so that these assets do not interfere with other parts of your application.
Overriding Spree’s assets
Overriding or replacing any of Spree’s internal assets is even easier than before. It’s recommended to attempt to replace as little as possible in a given JavaScript or stylesheet file to help ease future upgrade work required.
The methods listed below will work for both applications, extensions and themes with one noticeable difference: Extension & theme asset files will not be automatically included (see above for instructions on how to include asset files from your extensions / themes).
Overriding individual CSS styles
Say for example you want to replace the following CSS snippet:
You can now just create a new stylesheet inside your_app/vendor/assets/stylesheets/spree/frontend/
and include the following CSS:
The frontend/all.css
manifest will automatically include foo.css
and it will actually include both definitions with the one from foo.css
being included last, hence it will be the rule applied.
Overriding entire CSS files
To replace an entire stylesheet as provided by Spree you simply need to create a file with the same name and save it to the corresponding path within your application’s or extension’s vendor/assets/stylesheets
directory.
For example, to replace spree/frontend/all.css
you would save the replacement to your_app/vendor/assets/stylesheets/spree/frontend/all.css
.
This same method can also be used to override stylesheets provided by third-party extensions.
Overriding individual JavaScript functions
A similar approach can be used for JavaScript functions. For example, if you wanted to override the show_variant_images
method:
Again, just create a new JavaScript file inside your_app/vendor/assets/javascripts/spree/frontend
and include the new method definition:
The resulting frontend/all.js
would include both methods, with the latter being the one executed on request.
Overriding entire JavaScript files
To replace an entire JavaScript file as provided by Spree you simply need to create a file with the same name and save it to the corresponding path within your application’s or extension’s app/assets/javascripts
directory.
For example, to replace spree/frontend/all.js
you would save the replacement to your_app/vendor/assets/javascripts/spree/frontend/all.js
.
This same method can be used to override JavaScript files provided by third-party extensions.
SEO recommendations
Sitemap
We highly recommend adding a sitemap to your site. It might affect how Google bot crawls your store pages. There is an official extension called Spree Sitemap for that exact purpose.
- Per region, language or currency
- Click the Edit button (indicated with a pencil icon) for the right store
- Enter a title, keywords, and description values for the store homepage
- Click the Update button at the bottom of the page
To set the title, meta keywords, and description for each store category page (PLP), in the admin panel:
- Go to Products > Taxonomies
- Go into the Categories list by pressing the Edit button (pencil icon)
- Pick the category you’d like to edit by right-clicking (control + click on a Mac) a child in the tree to access the menu for adding, deleting or sorting a child.
- Click the Edit link for that category
- Replace the default values for title, meta keywords, and description with your own
- Click the Update button at the bottom of the page
You’ll have to edit every category and subcategory to your liking in a similar fashion.
To set the title, meta keywords and description for each product page (PDP), in the admin panel:
- Go to Products > Products
- In the product list pick the right one by pressing the Edit button (pencil icon)
- While in the Details tab, scroll down and input your values for the title, meta keywords, and description
- Click the Update button at the bottom of the page
Social sharing and search preview
The new Spree UX has the following social sharing features implemented:
- Facebook sharing with Open Graph tags to enable an attractive page preview
- Google visibility with structured data using Schema.org with JSON-DL
Feel free to test the Open Graph tags implementation and the also test the Schema.org implementation for your store.
Was this page helpful?