forked from JDutil/spree_gift_card
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Showing
24 changed files
with
321 additions
and
81 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
source 'http://rubygems.org' | ||
gem 'spree_core', path: '~/spree/core' | ||
# Remove after Spree 1.1.4 | ||
gem 'spree_core', github: 'spree/spree', branch: '1-1-stable'#path: '~/spree/core' | ||
gemspec |
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
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,52 @@ | ||
Spree::CheckoutController.class_eval do | ||
|
||
# TODO Apply gift code in a before filter if possible to avoid overriding the update method for easier upgrades? | ||
def update | ||
if @order.update_attributes(object_params) | ||
fire_event('spree.checkout.update') | ||
|
||
if defined?(Spree::Promo) and @order.coupon_code.present? | ||
event_name = "spree.checkout.coupon_code_added" | ||
if Spree::Promotion.exists?(:code => @order.coupon_code, | ||
:event_name => event_name) | ||
|
||
fire_event(event_name, :coupon_code => @order.coupon_code) | ||
# If it doesn't exist, raise an error! | ||
# Giving them another chance to enter a valid coupon code | ||
else | ||
flash[:error] = t(:promotion_not_found) | ||
render :edit and return | ||
end | ||
end | ||
|
||
if @order.gift_code.present? | ||
if gift_card = Spree::GiftCard.find_by_code(@order.gift_code) and gift_card.order_activatable?(@order) | ||
fire_event('spree.checkout.gift_code_added', :gift_code => @order.gift_code) | ||
gift_card.apply(@order) | ||
else | ||
flash[:error] = t(:gift_code_not_found) | ||
render :edit and return | ||
end | ||
end | ||
|
||
if @order.next | ||
state_callback(:after) | ||
else | ||
flash[:error] = t(:payment_processing_failed) | ||
respond_with(@order, :location => checkout_state_path(@order.state)) | ||
return | ||
end | ||
|
||
if @order.state == 'complete' || @order.completed? | ||
flash.notice = t(:order_processed_successfully) | ||
flash[:commerce_tracking] = 'nothing special' | ||
respond_with(@order, :location => completion_route) | ||
else | ||
respond_with(@order, :location => checkout_state_path(@order.state)) | ||
end | ||
else | ||
respond_with(@order) { |format| format.html { render :edit } } | ||
end | ||
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
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
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 @@ | ||
Spree::ProductsController.class_eval do | ||
|
||
before_filter :redirect_gift_card, only: :show | ||
|
||
private | ||
|
||
def redirect_gift_card | ||
redirect_to new_gift_card_path and return false if @product.is_gift_card? | ||
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,5 @@ | ||
module Spree | ||
def self.table_name_prefix | ||
'spree_' | ||
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,13 @@ | ||
module Spree | ||
class Calculator::GiftCard < Calculator | ||
|
||
def self.description | ||
'Gift Card Calculator' | ||
end | ||
|
||
def compute(order, gift_card) | ||
# Ensure a negative amount which does not exceed the sum of the order's item_total, ship_total, and tax_total. | ||
[(order.item_total + order.ship_total + order.tax_total), gift_card.current_value].min * -1 | ||
end | ||
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
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,8 @@ | ||
class Spree::GiftCardTransaction < ActiveRecord::Base | ||
belongs_to :gift_card | ||
belongs_to :order | ||
|
||
validates :amount, presence: true | ||
validates :gift_card, presence: true | ||
validates :order, presence: true | ||
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,7 @@ | ||
Spree::LineItem.class_eval do | ||
|
||
has_one :gift_card | ||
|
||
validates :gift_card, presence: { if: Proc.new{ |item| item.product.is_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
7 changes: 7 additions & 0 deletions
7
app/overrides/spree/checkout/_payment/_gift_code_field.html.erb.deface
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,7 @@ | ||
<!-- insert_after '#payment-methods' | ||
original '196c020541e91ab34bec98a975e606f0305ebb2b' --> | ||
|
||
<p class='field' data-hook='gift_code'> | ||
<%= form.label :gift_code %><br /> | ||
<%= form.text_field :gift_code, value: nil %> | ||
</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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<p>Hi <%= @gift_card.name %>,</p> | ||
<p><%= @gift_card.note %></p> | ||
<p>To use your <%= number_to_currency @gift_card.price %> Gift Card enter the following Gift Code during checkout: <%= @gift_card.token %></p> | ||
<p>To use your <%= number_to_currency @gift_card.price %> Gift Card enter the following Gift Code during checkout: <%= @gift_card.code %></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
10 changes: 10 additions & 0 deletions
10
db/migrate/20121017183422_create_spree_gift_card_transactions.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,10 @@ | ||
class CreateSpreeGiftCardTransactions < ActiveRecord::Migration | ||
def change | ||
create_table :spree_gift_card_transactions do |t| | ||
t.decimal :amount, scale: 2 | ||
t.belongs_to :gift_card | ||
t.belongs_to :order | ||
t.timestamps | ||
end | ||
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
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,7 @@ | ||
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. | ||
|
||
ENGINE_ROOT = File.expand_path('../..', __FILE__) | ||
ENGINE_PATH = File.expand_path('../../lib/spree_gift_card/engine', __FILE__) | ||
|
||
require 'rails/all' | ||
require 'rails/engine/commands' |
Oops, something went wrong.