{% hint style="warning" %}
This section covers the Rails storefront which was extracted to spree_frontend
ruby gem.
For new projects, we recommend using Storefront API to build your own storefront or using existing integrations with Next.js or Vue Storefront. {% endhint %}
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-background - header background color variable with 2 examples: white and blue one. By default, this is set with a $primary-background value but you can replace it with any other value in the variables.scss file.
$header-font-color- Header font color. By default set with $font-color value but you can replace it with any other value in the variables.scss file.
$footer-background - a variable that overrides $primary-background and allows you to change the footer color. See a white and a blue example below.
$footer-font-color - a variable that overrides $font-color and allows you to change the footer font color. See black and blue font examples below.
$meganav-background - a variable that allows you to change the mega nav menu background color. By default the meganav menu is set to a $primary-background value but you can replace it with any other value in the variables.scss file.
$meganav-font-color - a font color variable in the mega nav menu. By default the mega nav font color is set to a $font-color value but you can replace it with any other value in the variables.scss file.
$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.
$font-color - this variable affects all fonts on the $primary-background. Please see two examples below.
$secondary-font-color - this affects all fonts on $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.
$global-border-style - this affects the border and separator color throughout the whole site
$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-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 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
$primary-color variable changes
- The color of the No results icon
$primary-color variable changes
- The color of NEW COLLECTION and SUMMER SALE headers inside the banners
$primary-color variable changes
- The color of the IN STOCK text
- The color of the ADD TO CART button
$primary-color variable changes
- The color of the Trash delete icon for removing items from the cart
- The color of the CHECKOUT button
$primary-color variable changes
- The color of the CHECKOUT and VIEW CART buttons
$primary-color variable changes
- The color of the CONTINUE SHOPPING button
- The color of the Empty cart icon
$primary-color variable changes
- The color of the LOG IN, SIGN UP and CONTINUE AS A GUEST buttons
$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
$primary-color variable changes
- The color of the APPLY button
$primary-color variable changes
- The color of the PLACE ORDER button
$primary-color variable changes
The color of the LOG IN and SIGN UP buttons
$primary-color variable changes
- The color of the SIGN UP and LOG IN buttons
$primary-color variable changes
- The color of the Edit and Trash icons
$primary-color variable changes
- The color of the UPDATE button
$primary-color variable changes
- The color of the CANCEL and OK buttons
$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
$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
$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
$secondary-color variable changes
- The color of individual steps (box, name step, and guideline) - this element remains the same across the whole checkout process
$secondary-color variable changes
- The color of the Use shipping address checkbox
$secondary-color variable changes
- The color of delivery type radio buttons
$secondary-color variable changes
- The color of payment type radio buttons
- The color of payment card radio buttons
$secondary-color variable changes
- The color of the successful checkmark icon
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.
$enable-rounded - Enable rounding for components.
Possible values: true or false
“True” example
“False” example
$enable-shadows - Enable shadow for components
Possible values: true or false
$enable-gradients - Enable gradient for components
$enable-gradients - Enable gradient for components
You can import all templates from spree frontend into your application using this command (in your application root directory):
rails g spree:frontend:copy_storefront
All of those views will be added to your app/views
directory under spree
folder. You can modify them as you wish.
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:
app
|-- assets
|-- images
| |-- spree
| |-- frontend
| |-- backend
|-- javascripts
| |-- spree
| |-- frontend
| | |-- all.js
| |-- backend
| |-- all.js
|-- stylesheets
| |-- spree
| |-- frontend
| | |-- all.css
| |-- backend
| |-- all.css
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.
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:
vendor
|-- assets
|-- javascripts
| |-- spree
| |-- frontend
| | |-- all.js
| |-- backend
| |-- all.js
|-- stylesheets
| |-- spree
| |-- frontend
| | |-- all.css
| |-- backend
| |-- all.css
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:
//= require spree/backend
//= require_tree .
External JavaScript libraries, stylesheets and images have also been relocated into vendor/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 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).
Say for example you want to replace the following CSS snippet:
/* spree/app/assets/stylesheets/spree/frontend/screen.css */
div#footer {
clear: both;
}
You can now just create a new stylesheet inside your_app/vendor/assets/stylesheets/spree/frontend/
and include the following CSS:
/* vendor/assets/stylesheets/spree/frontend/foo.css */
div#footer {
clear: none;
border: 1px solid red;
}
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.
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.
A similar approach can be used for JavaScript functions. For example, if you wanted to override the show_variant_images
method:
// spree/app/assets/javascripts/spree/frontend/product.js
var show_variant_images = function(variant_id) {
$('li.vtmb').hide();
$('li.vtmb-' + variant_id).show();
var currentThumb = $('#' +
$("#main-image").data('selectedThumbId'));
// if currently selected thumb does not belong to current variant,
// nor to common images,
// hide it and select the first available thumb instead.
if(!currentThumb.hasClass('vtmb-' + variant_id) &&
!currentThumb.hasClass('tmb-all')) {
var thumb = $($('ul.thumbnails li:visible').eq(0));
var newImg = thumb.find('a').attr('href');
$('ul.thumbnails li').removeClass('selected');
thumb.addClass('selected');
$('#main-image img').attr('src', newImg);
$("#main-image").data('selectedThumb', newImg);
$("#main-image").data('selectedThumbId', thumb.attr('id'));
}
}
Again, just create a new JavaScript file inside your_app/vendor/assets/javascripts/spree/frontend
and include the new method definition:
// your_app/vendor/assets/javascripts/spree/frontend/foo.js
var show_variant_images = function(variant_id) {
alert('hello world');
}
The resulting frontend/all.js
would include both methods, with the latter being the one executed on request.
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.
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
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.