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
Showing
31 changed files
with
172 additions
and
160 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,96 @@ | ||
module Spree | ||
class GiftCardsController < BaseController | ||
helper 'spree/admin/base' | ||
#before_filter :authenticate_user!, :only => :new | ||
def new | ||
find_gift_card_variants | ||
@gift_card = GiftCard.new | ||
#@gift_card.sender_name = [current_user.fname || "", " ", current_user.lname || ""].join | ||
#@gift_card.sender_name = current_user.email | ||
@gift_card.cc_me = true | ||
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.line_item = line_item | ||
@gift_card.sender = current_user | ||
@gift_card.save | ||
redirect_to cart_path | ||
else | ||
find_gift_card_variants | ||
render :action => :new | ||
end | ||
end | ||
|
||
def edit | ||
@gift_card = GiftCard.find(params[:id]) | ||
access_forbidden unless @gift_card && @gift_card.sender == current_user | ||
end | ||
|
||
def update | ||
@gift_card = GiftCard.find(params[:id]) | ||
access_forbidden unless @gift_card && @gift_card.sender == current_user && !@gift_card.is_received? | ||
params[:gift_card].delete(:variant_id) | ||
if @gift_card.update_attributes(params[:gift_card]) | ||
OrderMailer.gift_card_email(@gift_card, @gift_card.line_item.order).deliver if @gift_card.sent_at.present? | ||
flash[:notice] = t("spree_gift_card.messages.successfully_updated") | ||
redirect_to account_url | ||
else | ||
render :action => :edit | ||
end | ||
end | ||
|
||
def activate | ||
@gift_card = GiftCard.find_by_token(params[:id]) | ||
if @gift_card.is_received | ||
flash[:error] = t("gift_card_messages.cant_activate") | ||
redirect_to root_url | ||
return | ||
end | ||
|
||
if current_user && !current_user.anonymous? | ||
if @gift_card.register(current_user) | ||
flash[:notice] = t("spree_gift_card.messages.activated") | ||
else | ||
flash[:error] = t("spree_gift_card.messages.register_error") | ||
end | ||
else | ||
session[:gift_card] = @gift_card.token | ||
flash[:notice] = t("spree_gift_card.messages.authorization_required") | ||
end | ||
redirect_to root_url | ||
end | ||
|
||
def preview | ||
@gift_card = GiftCard.new(:email => params[:email], :name => params[:name], :sender_name => params[:sender_name], :variant_id => params[:variant_id]) | ||
end | ||
|
||
def confirm | ||
@gift_card = GiftCard.find_by_token(params[:id]) | ||
if @gift_card.is_received | ||
flash[:error] = t("gift_card_messages.cant_activate") | ||
redirect_to root_url | ||
return | ||
end | ||
|
||
if !current_user || current_user.anonymous? | ||
session[:gift_card] = @gift_card.token | ||
flash[:notice] = t("spree_gift_card.messages.authorization_required") | ||
redirect_to root_url | ||
else | ||
session[:gift_card] = nil | ||
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 | ||
end |
2 changes: 1 addition & 1 deletion
2
...ers/user_sessions_controller_decorator.rb → ...ree/user_sessions_controller_decorator.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
2 changes: 1 addition & 1 deletion
2
...controllers/users_controller_decorator.rb → ...llers/spree/users_controller_decorator.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
2 changes: 1 addition & 1 deletion
2
app/mailers/order_mailer_decorator.rb → app/mailers/spree/order_mailer_decorator.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
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
2 changes: 1 addition & 1 deletion
2
app/models/order_decorator.rb → app/models/spree/order_decorator.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
2 changes: 1 addition & 1 deletion
2
app/models/product_decorator.rb → app/models/spree/product_decorator.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
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,6 @@ | ||
Deface::Override.new(:virtual_path => "spree/layouts/spree_application", | ||
:name => "converted_sidebar_164157054", | ||
:insert_after => "[data-hook='sidebar'], #sidebar[data-hook]", | ||
:text => " | ||
<%= link_to t(\"spree_gift_card.buy_gift_card\"), new_gift_card_path, :class => 'button' %> | ||
") |
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,4 @@ | ||
Deface::Override.new(:virtual_path => "spree/admin/products/_form", | ||
:name => "converted_admin_product_form_right_637624031", | ||
:insert_after => "#admin_product_form_right[data-hook], [data-hook='admin_product_form_right']", | ||
:partial => "spree/admin/products/gift_card_fields") |
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 @@ | ||
Deface::Override.new(:virtual_path => "users/show", | ||
:name => "converted_account_my_orders_408295644", | ||
:insert_after => "[data-hook='account_my_orders'], #account_my_orders[data-hook]", | ||
:partial => "users/gift_cards", | ||
:disabled => false) |
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
4 changes: 2 additions & 2 deletions
4
...8115306_add_gift_card_attr_to_products.rb → ...8115306_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
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,15 @@ | ||
class AddSenderNameToGiftCard < ActiveRecord::Migration | ||
def self.up | ||
add_column :spree_gift_cards, :sender_name, :string | ||
add_column :spree_gift_cards, :recipient_id, :int | ||
rename_column :spree_gift_cards, :user_id, :sender_id | ||
add_column :spree_gift_cards, :store_credits_id, :int | ||
end | ||
|
||
def self.down | ||
remove_column :spree_gift_cards, :sender_name | ||
remove_column :spree_gift_cards, :recipient_id | ||
rename_column :spree_gift_cards, :sender_id, :user_id | ||
remove_column :spree_gift_cards, :store_credits_id | ||
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,9 @@ | ||
class FixNamingIssueWithSc < ActiveRecord::Migration | ||
def self.up | ||
rename_column :spree_gift_cards, :store_credits_id, :store_credit_id | ||
end | ||
|
||
def self.down | ||
rename_column :spree_gift_cards, :store_credit_id, :store_credit2_id | ||
end | ||
end |
4 changes: 2 additions & 2 deletions
4
...20111215184935_add_cc_me_to_gift_cards.rb → ...20111215184935_add_cc_me_to_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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
class AddCcMeToGiftCards < ActiveRecord::Migration | ||
def self.up | ||
add_column :gift_cards, :cc_me, :boolean | ||
add_column :spree_gift_cards, :cc_me, :boolean | ||
end | ||
|
||
def self.down | ||
remove_column :gift_cards, :cc_me | ||
remove_column :spree_gift_cards, :cc_me | ||
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
if Product.where(:is_gift_card => true).count == 0 | ||
if Spree::Product.where(:is_gift_card => true).count == 0 | ||
puts "\tCreating default gift card..." | ||
product = Product.new(:name => "Gift Card", :is_gift_card => true, :price => 0) | ||
option_type = OptionType.new(:name => "is-gift-card", :presentation => "Gift Card") | ||
option_type.option_values << OptionValue.new(:name => "true") | ||
product = Spree::Product.new(:name => "Gift Card", :is_gift_card => true, :price => 0) | ||
option_type = Spree::OptionType.new(:name => "is-gift-card", :presentation => "Gift Card") | ||
option_type.option_values << Spree::OptionValue.new(:name => "true") | ||
product.option_types << option_type | ||
product.variants = [25, 50, 75, 100].map{|amount| Variant.new(:price => amount)} | ||
product.variants = [25, 50, 75, 100].map{|amount| Spree::Variant.new(:price => amount)} | ||
product.variants.map{|v| v.option_values << option_type.option_values} | ||
product.save | ||
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
Oops, something went wrong.