A simplified/stripped down version of the gem: github.com/ssimeonov/couponsgem
The original gem has controllers (that are not in an admin section), simple form (not always wanted), and sqlite (not always used). This version will just include the core functionality without an Admin interface.
If there was an admin interface, it should include methods to load a user, and authorize the admin user.
A gem (Rails 3 engine) that lets you generate coupon codes based on both a numeric (i.e. 113-22-3) and alpha mask (AA-AA-AA) through a web interface.
Coupons can be tied to up to 2 categories. For instance, a coupon can apply to both “product” and “tax”. Each category has a decimal amount, and a percentage that it can discount. The fixed amounts are applied first, then the percentage is applied.
After installing them gem, you can visit /coupons to generate coupons.
You can generate multiple coupons at a time. Each coupon can be set to be able to be redeemed X times
There are 2 methods that you can call. Coupons#apply which takes in array of {product : price } pairs. It will return a hash with the savings for each product, total savings, and grand total.
This is returned in JSON form (typically called from an AJAX call) and useful info is displayed to the user. The test/dummy has an example application which shows how it can be used.
There is the Coupons#redeem method which takes a coupon, as well as some metadata which is simply stored.
Both #redeem and #apply will throw the appropriate exception if there is a problem.
## Installation
gem ‘couponing’, git: ‘git@github.com:Sailias/couponsgem.git’, branch: ‘master’
Generate all the tables for Couponing
rails g couponing
## Usage
### Creating coupons
Create a controller to handle your coupons. It is easier to do it this way as you can made a controller behind your own authorization.
Eg. class Admin::CouponsController < Admin::BaseController
include the coupon CRUD module.
class Admin::CouponsController < Admin::BaseController
include Couponing::CrudControllerMethods
end
You will then have to copy and paste the views into your project.
### Redeeming coupons
Create a controller to handle redeeming coupons. This will probably be at the root of your project.
class CouponsController < ApplicationController
include Couponing::RedemptionControllerMethods def product_bag product = Product.find params[:product_id] { price: product.price, shipping: product.shipping, tax: product.calculate_tax } end
end
The product_bag method is used to pass a hash into the apply method the calculate the discounts from the coupon code. This method is called using AJAX and a JSON hash is passed back. The coupon discounts are not applied at this time, only caculated.