Skip to content

Commit

Permalink
Merge git://github.com/schof/spree
Browse files Browse the repository at this point in the history
Conflicts:

	.gitignore
	app/models/product.rb
	app/views/admin/products/_menu.html.erb
	db/sample/products.yml
  • Loading branch information
sonny committed Jul 28, 2008
2 parents 7a11398 + cea0689 commit b001b8a
Show file tree
Hide file tree
Showing 1,059 changed files with 15,970 additions and 50,078 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ spree_dev
spree_test
tmp
vendor/rails
coverage/*
var

23 changes: 21 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,27 @@ Spree is a complete open source commerce solution for Ruby on Rails.
It was developed by Sean Schofield under the original name of Rails
Cart before changing its name to Spree.

QUICK START
===========
QUICK START (Running the Source)
================================

1. Clone the git repo

git clone git://github.com/schof/spree.git spree
2. Install the gem dependencies

rake gems:install
3. Bootstrap the database (run the migrations, create admin account, optionally load sample data.)

rake db:bootstrap

4. Start the server

script/server

QUICK START (Running the Gem)
=============================

1. Install spree Gem

Expand Down
22 changes: 4 additions & 18 deletions app/controllers/account_controller.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
class AccountController < Spree::BaseController
before_filter :login_from_cookie

layout 'admin'

def index
redirect_to(:action => 'signup') unless logged_in? || User.count > 0
redirect_to(signup_path) unless logged_in? || User.count > 0
end

def login
return unless request.post?
self.current_user = User.authenticate(params[:login], params[:password])
self.current_user = User.authenticate(params[:email], params[:password])
if logged_in?
if params[:remember_me] == "1"
self.current_user.remember_me
cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at }
end
redirect_back_or_default(:controller => 'store', :action => 'index')
redirect_back_or_default(products_path)
flash.now[:notice] = "Logged in successfully"
else
flash.now[:error] = "Login authentication failed."
end
end

def signup
@user = User.new(params[:user])
return unless request.post?
@user.save!
self.current_user = @user
redirect_back_or_default(:controller => '/account', :action => 'index')
flash[:notice] = "Thanks for signing up!"
rescue ActiveRecord::RecordInvalid
flash[:error] = "Problem creating user account."
render :action => 'signup'
end
end

def logout
self.current_user.forget_me if logged_in?
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/admin/base_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# this class was inspired (heavily) from the mephisto admin architecture

class Admin::BaseController < Spree::BaseController
helper :search
layout 'admin'
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/admin/configurations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Admin::ConfigurationsController < Admin::BaseController

before_filter :initialize_extension_links, :only => :index

protected

def initialize_extension_links
@extension_links = []
end
end
14 changes: 14 additions & 0 deletions app/controllers/admin/mail_settings_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Admin::MailSettingsController < Admin::BaseController

def update
Spree::Config.set(params[:preferences])
Spree::Preferences::MailSettings.init

respond_to do |format|
format.html {
redirect_to admin_mail_settings_path
}
end
end

end
4 changes: 2 additions & 2 deletions app/controllers/admin/option_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def edit
end
end

def delete
Option.delete(params[:id])
def destroy
OptionType.destroy(params[:id])
redirect_to :action => 'index'
end

Expand Down
144 changes: 76 additions & 68 deletions app/controllers/admin/orders_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class Admin::OrdersController < Admin::BaseController

before_filter :initialize_txn_partials

in_place_edit_for :address, :firstname
in_place_edit_for :address, :lastname
in_place_edit_for :address, :address1
Expand Down Expand Up @@ -195,77 +197,83 @@ def delete
end

private
def gateway_capture(order)
authorization = find_authorization(order)
gw = payment_gateway
response = gw.capture(order.total * 100, authorization.response_code, Order.minimal_gateway_options(order))
return unless response.success?
order.credit_card.txns << Txn.new(
:amount => order.total,
:response_code => response.authorization,
:txn_type => Txn::TxnType::CAPTURE
)
order.save
response
end

def gateway_void(order)
authorization = find_authorization(order)
gw = payment_gateway
response = gw.void(authorization.response_code, Order.minimal_gateway_options(order))
return unless response.success?
order.credit_card.txns << Txn.new(
:amount => order.total,
:response_code => response.authorization,
:txn_type => Txn::TxnType::VOID
)
order.save
response

# Allows extensions to add new forms of payment to provide their own display of stransactions
def initialize_txn_partials
@txn_partials = []
end

def gateway_capture(order)
authorization = find_authorization(order)
gw = payment_gateway
response = gw.capture(order.total * 100, authorization.response_code, Order.minimal_gateway_options(order))
return unless response.success?
order.credit_card.txns << CreditCardTxn.new(
:amount => order.total,
:response_code => response.authorization,
:txn_type => CreditCardTxn::TxnType::CAPTURE
)
order.save
response
end

def gateway_void(order)
authorization = find_authorization(order)
gw = payment_gateway
response = gw.void(authorization.response_code, Order.minimal_gateway_options(order))
return unless response.success?
order.credit_card.txns << CreditCardTxn.new(
:amount => order.total,
:response_code => response.authorization,
:txn_type => CreditCardTxn::TxnType::VOID
)
order.save
response
end

def gateway_credit(order)
authorization = find_authorization(order)
gw = payment_gateway
response = gw.credit(order.total, authorization.response_code, Order.minimal_gateway_options(order))
return unless response.success?
order.credit_card.txns << CreditCardTxn.new(
:amount => order.total,
:response_code => response.authorization,
:txn_type => CreditCardTxn::TxnType::CREDIT
)
order.save
response
end

def find_authorization(order)
#find the transaction associated with the original authorization/capture
cc = order.credit_card
cc.txns.find(:first,
:conditions => ["txn_type = ? or txn_type = ?", CreditCardTxn::TxnType::AUTHORIZE, CreditCardTxn::TxnType::CAPTURE],
:order => 'created_at DESC')
end

def build_conditions(p)
c = []
if not @search.start.blank?
c << "(orders.created_at between :start and :stop)"
p.merge! :start => @search.start.to_date
@search.stop = Date.today + 1 if @search.stop.blank?
p.merge! :stop => @search.stop.to_date + 1.day
end

def gateway_credit(order)
authorization = find_authorization(order)
gw = payment_gateway
response = gw.credit(order.total, authorization.response_code, Order.minimal_gateway_options(order))
return unless response.success?
order.credit_card.txns << Txn.new(
:amount => order.total,
:response_code => response.authorization,
:txn_type => Txn::TxnType::CREDIT
)
order.save
response
unless @search.order_num.blank?
c << "number like :order_num"
p.merge! :order_num => @search.order_num + "%"
end

def find_authorization(order)
#find the transaction associated with the original authorization/capture
cc = order.credit_card
cc.txns.find(:first,
:conditions => ["txn_type = ? or txn_type = ?", Txn::TxnType::AUTHORIZE, Txn::TxnType::CAPTURE],
:order => 'created_at DESC')
unless @search.customer.blank?
c << "(firstname like :customer or lastname like :customer)"
p.merge! :customer => @search.customer + "%"
end

def build_conditions(p)
c = []
if not @search.start.blank?
c << "(orders.created_at between :start and :stop)"
p.merge! :start => @search.start.to_date
@search.stop = Date.today + 1 if @search.stop.blank?
p.merge! :stop => @search.stop.to_date + 1.day
end
unless @search.order_num.blank?
c << "number like :order_num"
p.merge! :order_num => @search.order_num + "%"
end
unless @search.customer.blank?
c << "(firstname like :customer or lastname like :customer)"
p.merge! :customer => @search.customer + "%"
end
if @search.status
c << "status = :status"
p.merge! :status => @search.status
end
(c.to_sentence :skip_last_comma=>true).gsub(",", " and ")
if @search.status
c << "status = :status"
p.merge! :status => @search.status
end
(c.to_sentence :skip_last_comma=>true).gsub(",", " and ")
end

end
23 changes: 12 additions & 11 deletions app/controllers/admin/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def index
end

def show
@product = Product.find(params[:id])
@product = Product.find_by_param(params[:id])
end

def new
Expand Down Expand Up @@ -55,7 +55,7 @@ def new
def edit
if request.post?
load_data
@product = Product.find(params[:id])
@product = Product.find_by_param(params[:id])
category_id = params[:category]
@product.category = (category_id.blank? ? nil : Category.find(params[:category]))

Expand Down Expand Up @@ -100,22 +100,22 @@ def edit
flash.now[:error] = 'Problem updating product.'
end
else
@product = Product.find(params[:id])
@product = Product.find_by_param(params[:id])
load_data
@selected_category = @product.category.id if @product.category
end
end

def destroy
flash[:notice] = 'Product was successfully deleted.'
@product = Product.find(params[:id])
@product = Product.find_by_param(params[:id])
@product.destroy
redirect_to :action => 'index'
end

#AJAX support method
def add_option_type
@product = Product.find(params[:id])
@product = Product.find_by_param(params[:id])
pot = ProductOptionType.new(:product => @product, :option_type => OptionType.find(params[:option_type_id]))
@product.selected_options << pot
@product.save
Expand All @@ -127,15 +127,15 @@ def add_option_type
#AJAX support method
def remove_option_type
ProductOptionType.delete(params[:product_option_type_id])
@product = Product.find(params[:id])
@product = Product.find_by_param(params[:id])
render :partial => 'option_types',
:locals => {:product => @product},
:layout => false
end

#AJAX method
def new_variant
@product = Product.find(params[:id])
@product = Product.find_by_param(params[:id])
@variant = Variant.new
render :partial => 'new_variant',
:locals => {:product => @product},
Expand All @@ -144,7 +144,7 @@ def new_variant

#AJAX method
def delete_variant
@product = Product.find(params[:id])
@product = Product.find_by_param(params[:id])
Variant.destroy(params[:variant_id])
flash.now[:notice] = 'Variant successfully removed.'
render :partial => 'variants',
Expand Down Expand Up @@ -174,7 +174,7 @@ def remove_property_value

#AJAX method
def add_property_value
@product = Product.find(params[:id])
@product = Product.find_by_param(params[:id])
@property_value = PropertyValue.new
render :partial => 'add_property_value', :locals => { :product => @product }
end
Expand All @@ -186,14 +186,14 @@ def add_property_value_view
render :nothing => true
return
end
@product = Product.find(params[:id])
@product = Product.find_by_param(params[:id])
render({ :partial => "add_property_value_view_#{params[:view]}",
:locals => { :product => @product } })
end

#AJAX method
def add_property_value_view_prototype_list
@product = Product.find(params[:id])
@product = Product.find_by_param(params[:id])
@prototype = Prototype.find(params[:prototype_id])
render({ :partial => "add_property_value_view_prototype_list",
:locals => { :product => @product, :prototype => @prototype } })
Expand All @@ -203,6 +203,7 @@ def add_property_value_view_prototype_list
def load_data
@all_categories = Category.find(:all, :order=>"name")
@all_categories.unshift Category.new(:name => "<None>")
@tax_categories = TaxCategory.find(:all, :order=>"name")
end

private
Expand Down
Loading

0 comments on commit b001b8a

Please sign in to comment.