This Spree extension allows you to mark some products as featured, for example to display them on the homepage.
It integrates with Spree admin backend to allow you to change the featured state of each product both on the products listing page and the product edit form.
Add spree_featured to your Gemfile:
gem 'spree_featured', github: 'johannboutet/spree_featured', branch: '3-0-stable'
Bundle your dependencies and run the installation generator:
bundle
bundle exec rails g spree_featured:install
This will add a featured
column to all products that defaults t false
.
On the products listing page, a Featured column is added before the actions column. It shows a switch reflecting the featured state of the product.
When a switch is toggled, an Ajax request is sent to the Spree Api to update the corresponding product.
If the current admin user doesn't have an Api key associated with his account, the switch toggle event simply submits the form to the normal update route. Therefore, the user is redirected to the product edit page. To avoid being redirected every time you change a switch, make sure the admin user you are using has an Api key.
A checkbox is also added to the product edit page, under the Description text area.
This extension adds a only_featured
search scope to the Product model so that you can retrieve featured products easily.
# home_controller_decorator.rb
module Spree
HomeController.class_eval do
def index
@products = Product.only_featured
end
end
end
First bundle your dependencies, then run rake
. rake
will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using rake test_app
.
bundle
bundle exec rake
When testing your applications integration with this extension you may use it's factories. Simply add this require statement to your spec_helper:
require 'spree_featured/factories'
Copyright (c) 2015 Johann Boutet, released under the New BSD License