Adds a featured option to Spree products.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Johann Boutet 47663aae75 Fix bug with translations. 6 years ago
app Fix bug with translations. 6 years ago
bin Initial commit. 6 years ago
config Fix bug with translations. 6 years ago
db/migrate Initial commit. 6 years ago
docs Add documentation. 6 years ago
lib Initial commit. 6 years ago
spec Initial commit. 6 years ago
.gitignore Initial commit. 6 years ago
.rspec Initial commit. 6 years ago
Gemfile Initial commit. 6 years ago
LICENSE Initial commit. 6 years ago
README.md Add search scope for featured products. 6 years ago
Rakefile Initial commit. 6 years ago
spree_featured.gemspec Add documentation. 6 years ago

README.md

SpreeFeatured Extension

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.

Installation

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.

Admin Backend

Products Listing Page

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.

Admin switches

Ajax Api calls

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.

Product Edit Page

A checkbox is also added to the product edit page, under the Description text area.

Frontend Usage

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

Testing

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 © 2015 Johann Boutet, released under the New BSD License