docs/developer/customization/v4/storefront.mdx
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
$primary-color variable changes
$primary-color variable changes
$primary-color variable changes
$primary-color variable changes
$primary-color variable changes
$primary-color variable changes
$primary-color variable changes
$primary-color variable changes
$primary-color variable changes
$primary-color variable changes
$primary-color variable changes
The color of the LOG IN and SIGN UP buttons
$primary-color variable changes
$primary-color variable changes
$primary-color variable changes
$primary-color variable changes
$secondary-color variable changes
$secondary-color variable changes
$secondary-color variable changes
Log-in and Sign-in page
$secondary-color variable changes
$secondary-color variable changes
$secondary-color variable changes
$secondary-color variable changes
$secondary-color variable changes
$secondary-color variable changes
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.
To set the title, meta keywords, and description for each store category page (PLP), in the admin panel:
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:
The new Spree UX has the following social sharing features implemented:
Feel free to test the Open Graph tags implementation and the also test the Schema.org implementation for your store.