forked from senjutsuka/spree-gift-cards
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dab826a
Showing
22 changed files
with
330 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
\#* | ||
*~ | ||
.#* | ||
.DS_Store | ||
.idea | ||
.project | ||
tmp | ||
nbproject | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
* Neither the name of the Rails Dog LLC nor the names of its | ||
contributors may be used to endorse or promote products derived from this | ||
software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
SpreeGiftCards | ||
============== | ||
|
||
Introduction goes here. | ||
|
||
|
||
Example | ||
======= | ||
|
||
Example goes here. | ||
|
||
|
||
Copyright (c) 2010 [name of extension creator], released under the New BSD License |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'rubygems' | ||
require 'rake' | ||
require 'rake/testtask' | ||
require 'rake/packagetask' | ||
require 'rake/gempackagetask' | ||
|
||
spec = eval(File.read('spree_gift_cards.gemspec')) | ||
|
||
Rake::GemPackageTask.new(spec) do |p| | ||
p.gem_spec = spec | ||
end | ||
|
||
desc "Release to gemcutter" | ||
task :release => :package do | ||
require 'rake/gemcutter' | ||
Rake::Gemcutter::Tasks.new(spec).define | ||
Rake::Task['gem:push'].invoke | ||
end | ||
|
||
desc "Default Task" | ||
task :default => [ :spec ] | ||
|
||
require 'rspec/core/rake_task' | ||
RSpec::Core::RakeTask.new | ||
|
||
require 'cucumber/rake/task' | ||
Cucumber::Rake::Task.new do |t| | ||
t.cucumber_opts = %w{--format pretty} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class GiftCardsController < Spree::BaseController | ||
helper 'admin/base' | ||
def new | ||
find_gift_card_variants | ||
@gift_card = GiftCard.new | ||
end | ||
|
||
def create | ||
@gift_card = GiftCard.new(params[:gift_card]) | ||
if @gift_card.save | ||
@order = current_order(true) | ||
line_item = @order.add_variant(@gift_card.variant, 1) | ||
@gift_card.update_attributes(:line_item => line_item, :user => current_user) | ||
redirect_to cart_path | ||
else | ||
find_gift_card_variants | ||
render :action => :new | ||
end | ||
end | ||
|
||
private | ||
|
||
def find_gift_card_variants | ||
gift_card_product_ids = Product.not_deleted.where(["is_gift_card = ?", true]).map(&:id) | ||
@gift_card_variants = Variant.where(["price > 0 AND product_id IN (?)", gift_card_product_ids]).order("price") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class GiftCard < ActiveRecord::Base | ||
belongs_to :variant | ||
belongs_to :line_item | ||
belongs_to :user | ||
validates :email, :presence => true | ||
validates :name, :presence => true | ||
|
||
before_create :generate_token | ||
|
||
private | ||
|
||
def generate_token | ||
self.token = Digest::SHA1.hexdigest([Time.now, rand].join) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
LineItem.class_eval do | ||
has_one :gift_card | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Product.class_eval do | ||
|
||
scope :gift_cards, where(["products.is_gift_card = ?", true]) | ||
scope :not_gift_cards, where(["products.is_gift_card = ?", false]) | ||
|
||
scope :active, lambda { |*args| | ||
not_deleted.not_gift_cards.available(args.first) | ||
} | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<p> | ||
<%= f.check_box(:is_gift_card) %> <%= f.label :is_gift_card, t("is_gift_card")%> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<h1><%= t(:gift_cards) %></h1> | ||
<%= render "shared/error_messages", :target => @gift_card %> | ||
<%= form_for @gift_card do |f| %> | ||
<p> | ||
<% @gift_card_variants.each do |card| %> | ||
<%= f.radio_button :variant_id, card.id %><%= number_to_currency(card.price) %> | ||
<% end %> | ||
</p> | ||
<%= f.field_container :email do %> | ||
<%= f.label :email, t("email") %> <span class="required">*</span><br /> | ||
<%= f.text_field :email %> | ||
<% end %> | ||
<%= f.field_container :name do %> | ||
<%= f.label :name, t("name") %> <span class="required">*</span><br /> | ||
<%= f.text_field :name %> | ||
<% end %> | ||
<%= f.field_container :note do %> | ||
<%= f.label :note, t("note") %><br /> | ||
<%= f.text_area :note, :rows => 10 %> | ||
<% end %> | ||
<button type='submit' class='large primary'> | ||
<%= image_tag('/images/add-to-cart.png') + ' ' + t('add_to_cart') %> | ||
</button> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<% if line_item.gift_card %> | ||
<h4><%= t(:gift_card) %> <%= number_to_currency(variant.price) %> for | ||
<%= line_item.gift_card.name %> (<%= line_item.gift_card.email %>)</h4> | ||
<p> | ||
<%= truncate(line_item.gift_card.note, :length => 100, :omission => "...") %> | ||
</p> | ||
<% else %> | ||
<h4><%= link_to variant.product.name, product_path(variant.product) %></h4> | ||
<%= variant_options variant %> | ||
<%= truncate(variant.product.description, :length => 100, :omission => "...") %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
development: | ||
adapter: sqlite3 | ||
database: db/cucumber.sqlite3 | ||
pool: 5 | ||
timeout: 5000 | ||
|
||
test: | ||
adapter: sqlite3 | ||
database: db/test.sqlite3 | ||
pool: 5 | ||
timeout: 5000 | ||
|
||
cucumber: | ||
adapter: sqlite3 | ||
database: db/cucumber.sqlite3 | ||
pool: 5 | ||
timeout: 5000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
TestApp::Application.configure do | ||
# Settings specified here will take precedence over those in config/environment.rb | ||
|
||
# The test environment is used exclusively to run your application's | ||
# test suite. You never need to work with it otherwise. Remember that | ||
# your test database is "scratch space" for the test suite and is wiped | ||
# and recreated between test runs. Don't rely on the data there! | ||
config.cache_classes = true | ||
|
||
# Log error messages when you accidentally call methods on nil. | ||
config.whiny_nils = true | ||
|
||
# Show full error reports and disable caching | ||
config.consider_all_requests_local = true | ||
config.action_controller.perform_caching = false | ||
|
||
# Raise exceptions instead of rendering exception templates | ||
config.action_dispatch.show_exceptions = false | ||
|
||
# Disable request forgery protection in test environment | ||
config.action_controller.allow_forgery_protection = false | ||
|
||
# Tell Action Mailer not to deliver emails to the real world. | ||
# The :test delivery method accumulates sent emails in the | ||
# ActionMailer::Base.deliveries array. | ||
config.action_mailer.delivery_method = :test | ||
|
||
# Use SQL instead of Active Record's schema dumper when creating the test database. | ||
# This is necessary if your schema can't be completely dumped by the schema dumper, | ||
# like if you have constraints or database-specific column types | ||
# config.active_record.schema_format = :sql | ||
|
||
# Print deprecation notices to the stderr | ||
config.active_support.deprecation = :stderr | ||
|
||
config.action_mailer.default_url_options = { :host => 'testapp.com' } | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
en: | ||
buy_gift_card: "Buy gift card" | ||
gift_card: "Gift card" | ||
gift_cards: "Gift cards" | ||
is_gift_card: "is gift card" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Rails.application.routes.draw do | ||
resources :gift_cards | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module SpreeGiftCards | ||
module Generators | ||
class InstallGenerator < Rails::Generators::Base | ||
source_root File.expand_path("../../templates", __FILE__) | ||
|
||
desc "Configures your Rails application for use with spree_gift_cards" | ||
|
||
def copy_migrations | ||
directory "db" | ||
end | ||
|
||
end | ||
end | ||
end | ||
|
13 changes: 13 additions & 0 deletions
13
lib/generators/templates/db/migrate/20101008115306_add_gift_card_attr_to_products.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class AddGiftCardAttrToProducts < ActiveRecord::Migration | ||
def self.up | ||
change_table(:products) do |t| | ||
t.column :is_gift_card, :boolean, :default => false, :null => false | ||
end | ||
end | ||
|
||
def self.down | ||
change_table(:products) do |t| | ||
t.remove :is_gift_card | ||
end | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
lib/generators/templates/db/migrate/20101011103850_create_gift_cards.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class CreateGiftCards < ActiveRecord::Migration | ||
def self.up | ||
create_table :gift_cards do |t| | ||
t.integer :variant_id, :null => false | ||
t.integer :line_item_id | ||
t.integer :user_id | ||
t.string :email, :null => false | ||
t.string :name | ||
t.text :note | ||
t.string :token, :null => false | ||
t.boolean :is_received, :default => false, :null => false | ||
t.datetime :sent_at | ||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :gift_cards | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'spree_core' | ||
require 'spree_gift_cards_hooks' | ||
|
||
module SpreeGiftCards | ||
class Engine < Rails::Engine | ||
|
||
config.autoload_paths += %W(#{config.root}/lib) | ||
|
||
def self.activate | ||
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c| | ||
Rails.env == "production" ? require(c) : load(c) | ||
end | ||
end | ||
|
||
config.to_prepare &method(:activate).to_proc | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class SpreeGiftCardsHooks < Spree::ThemeSupport::HookListener | ||
insert_after :admin_product_form_right , "admin/products/gift_card_fields" | ||
|
||
insert_after :sidebar do | ||
%( | ||
<%= link_to t("buy_gift_card"), new_gift_card_path, :class => 'button' %> | ||
) | ||
end | ||
|
||
replace :cart_item_description, "orders/line_item_description" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# add custom rake tasks here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Gem::Specification.new do |s| | ||
s.platform = Gem::Platform::RUBY | ||
s.name = 'spree_gift_cards' | ||
s.version = '0.30.0.beta2' | ||
s.summary = 'Add gem summary here' | ||
#s.description = 'Add (optional) gem description here' | ||
s.required_ruby_version = '>= 1.8.7' | ||
|
||
s.author = 'Roman Smirnov' | ||
s.email = '[email protected]' | ||
# s.homepage = 'http://www.rubyonrails.org' | ||
# s.rubyforge_project = 'actionmailer' | ||
|
||
s.files = Dir['CHANGELOG', 'README.md', 'LICENSE', 'lib/**/*', 'app/**/*'] | ||
s.require_path = 'lib' | ||
s.requirements << 'none' | ||
|
||
s.has_rdoc = true | ||
|
||
s.add_dependency('spree_core', '>= 0.30.0.beta2') | ||
s.add_dependency('spree_auth', '>= 0.30.0.beta2') | ||
s.add_dependency('spree_store_credits', '>= 0.30.0.beta2') | ||
end |