Skip to content
This repository has been archived by the owner on Apr 17, 2020. It is now read-only.

Commit

Permalink
Updated to work with Spree 1.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
romul committed Apr 3, 2012
1 parent 1b5e3ae commit f6755ac
Show file tree
Hide file tree
Showing 26 changed files with 211 additions and 233 deletions.
3 changes: 1 addition & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
require 'rubygems'
require 'rake'
require 'rake/testtask'
require 'rake/packagetask'
require 'rake/gempackagetask'
require 'rubygems/package_task'

gemfile = File.expand_path('../spec/test_app/Gemfile', __FILE__)
if File.exists?(gemfile) && (%w(spec cucumber).include?(ARGV.first.to_s) || ARGV.size == 0)
Expand Down
73 changes: 0 additions & 73 deletions app/assets/javascripts/store/checkout.js

This file was deleted.

53 changes: 53 additions & 0 deletions app/assets/javascripts/store/spree_address_book.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
(function($) {
$(document).ready(function(){
if ($(".select_address").length) {
$('input#order_use_billing').unbind("click");
$(".inner").hide();
$(".inner input").prop("disabled", true);
$(".inner select").prop("disabled", true);
if ($('input#order_use_billing').is(':checked')) {
$("#shipping .select_address").hide();
}

$('input#order_use_billing').click(function() {
if ($(this).is(':checked')) {
$("#shipping .select_address").hide();
hide_address_form('shipping');
} else {
$("#shipping .select_address").show();
if ($("input[name='order[ship_address_id]']:checked").val() == '0') {
show_address_form('shipping');
}
}
});

$("input[name='order[bill_address_id]']:radio").change(function(){
if ($("input[name='order[bill_address_id]']:checked").val() == '0') {
show_address_form('billing');
} else {
hide_address_form('billing');
}
});

$("input[name='order[ship_address_id]']:radio").change(function(){
if ($("input[name='order[ship_address_id]']:checked").val() == '0') {
show_address_form('shipping');
} else {
hide_address_form('shipping');
}
});
}
});

function hide_address_form(address_type){
$("#" + address_type + " .inner").hide();
$("#" + address_type + " .inner input").prop("disabled", true);
$("#" + address_type + " .inner select").prop("disabled", true);
}

function show_address_form(address_type){
$("#" + address_type + " .inner").show();
$("#" + address_type + " .inner input").prop("disabled", false);
$("#" + address_type + " .inner select").prop("disabled", false);
}
})(jQuery);
12 changes: 12 additions & 0 deletions app/assets/stylesheets/store/spree_address_book.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
div.inner {
input[type=text], select { width: 80%; }
}

div#checkout #checkout_form_address {
#billing, #shipping {
.select_address label { float: none; }
input[type=radio] { width: auto; }
}
}

.hidden { display: none; }
2 changes: 1 addition & 1 deletion app/controllers/checkout_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CheckoutController.class_eval do
Spree::CheckoutController.class_eval do
after_filter :normalize_addresses, :only => :update
before_filter :set_addresses, :only => :update

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddressesController < Spree::BaseController
class Spree::AddressesController < Spree::BaseController
rescue_from ActiveRecord::RecordNotFound, :with => :render_404
load_and_authorize_resource

Expand Down
8 changes: 4 additions & 4 deletions app/helpers/checkout_helper_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CheckoutHelper.module_eval do
Spree::CheckoutHelper.module_eval do
def address_field(form, method, id_prefix = "b", &handler)
content_tag :p, :id => [id_prefix, method].join, :class => "field" do
content_tag :p, :id => [id_prefix, method].join('_'), :class => "field" do
if handler
handler.call
else
is_required = Address.required_fields.include?(method)
is_required = Spree::Address.required_fields.include?(method)
separator = is_required ? '<span class="req">*</span><br />' : '<br />'
form.label(method) + separator.html_safe +
form.text_field(method, :class => is_required ? 'required' : nil)
Expand All @@ -13,7 +13,7 @@ def address_field(form, method, id_prefix = "b", &handler)
end

def address_state(form, country)
country ||= Country.find(Spree::Config[:default_country_id])
country ||= Spree::Country.find(Spree::Config[:default_country_id])
have_states = !country.states.empty?
state_elements = [
form.collection_select(:state_id, country.states.order(:name),
Expand Down
8 changes: 4 additions & 4 deletions app/models/address_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Address.class_eval do
Spree::Address.class_eval do
belongs_to :user

def self.required_fields
validator = Address.validators.find{|v| v.kind_of?(ActiveModel::Validations::PresenceValidator)}
validator = Spree::Address.validators.find{|v| v.kind_of?(ActiveModel::Validations::PresenceValidator)}
validator ? validator.attributes : []
end

# can modify an address if it's not been used in an order
def editable?
new_record? || (shipments.empty? && (Order.where("bill_address_id = ?", self.id).count + Order.where("bill_address_id = ?", self.id).count <= 1) && Order.complete.where("bill_address_id = ? OR ship_address_id = ?", self.id, self.id).count == 0)
new_record? || (shipments.empty? && (Spree::Order.where("bill_address_id = ?", self.id).count + Spree::Order.where("bill_address_id = ?", self.id).count <= 1) && Spree::Order.complete.where("bill_address_id = ? OR ship_address_id = ?", self.id, self.id).count == 0)
end

def can_be_deleted?
shipments.empty? && Order.where("bill_address_id = ? OR ship_address_id = ?", self.id, self.id).count == 0
shipments.empty? && Spree::Order.where("bill_address_id = ? OR ship_address_id = ?", self.id, self.id).count == 0
end

def to_s
Expand Down
12 changes: 6 additions & 6 deletions app/models/order_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Order.class_eval do
Spree::Order.class_eval do
attr_accessible :bill_address_id, :ship_address_id
before_validation :clone_shipping_address, :if => "Spree::Config[:disable_bill_address]"
before_validation :clone_shipping_address, :if => "Spree::AddressBook::Config[:disable_bill_address]"

def clone_shipping_address
if self.ship_address
Expand All @@ -17,7 +17,7 @@ def clone_billing_address
end

def bill_address_id=(id)
address = Address.find(id)
address = Spree::Address.find(id)
if address && address.user_id == self.user_id
self["bill_address_id"] = address.id
self.bill_address.reload
Expand All @@ -31,7 +31,7 @@ def bill_address_attributes=(attributes)
end

def ship_address_id=(id)
address = Address.find(id)
address = Spree::Address.find(id)
if address && address.user_id == self.user_id
self["ship_address_id"] = address.id
self.ship_address.reload
Expand All @@ -49,7 +49,7 @@ def ship_address_attributes=(attributes)
def update_or_create_address(attributes)
address = nil
if attributes[:id]
address = Address.find(attributes[:id])
address = Spree::Address.find(attributes[:id])
if address && address.editable?
address.update_attributes(attributes)
else
Expand All @@ -58,7 +58,7 @@ def update_or_create_address(attributes)
end

if !attributes[:id]
address = Address.new(attributes)
address = Spree::Address.new(attributes)
address.save
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class AddressAbility
class Spree::AddressAbility
include CanCan::Ability

def initialize(user)
can :manage, Address do |address|
can :manage, Spree::Address do |address|
address.user == user
end
end
Expand Down
7 changes: 7 additions & 0 deletions app/models/spree/address_book_configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Spree
class AddressBookConfiguration < Preferences::Configuration
preference :disable_bill_address, :boolean, :default => false
preference :alternative_bill_address_phone, :boolean, :default => false
preference :alternative_ship_address_phone, :boolean, :default => false
end
end
2 changes: 1 addition & 1 deletion app/models/user_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
User.class_eval do
Spree::User.class_eval do
has_many :addresses, :conditions => {:deleted_at => nil}, :order => "updated_at DESC"
end
4 changes: 2 additions & 2 deletions app/overrides/views_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Deface::Override.new(
:virtual_path => "users/show",
:virtual_path => "spree/users/show",
:name => "address_book_account_my_orders",
:insert_after => "[data-hook='account_my_orders'], #account_my_orders[data-hook]",
:partial => "users/addresses",
:partial => "spree/users/addresses",
:disabled => false)
15 changes: 0 additions & 15 deletions app/views/addresses/_form.html.erb

This file was deleted.

85 changes: 0 additions & 85 deletions app/views/checkout/_address.html.erb

This file was deleted.

Loading

1 comment on commit f6755ac

@pirj
Copy link

@pirj pirj commented on f6755ac Apr 14, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Versionfile?

Please sign in to comment.