Skip to content

johannboutet/spree_featured

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Adds a featured option to Spree products.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published