spree_last_address 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in spree_last_address.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Redistribution and use in source and binary forms, with or without modification,
2
+ are permitted provided that the following conditions are met:
3
+
4
+ * Redistributions of source code must retain the above copyright notice,
5
+ this list of conditions and the following disclaimer.
6
+ * Redistributions in binary form must reproduce the above copyright notice,
7
+ this list of conditions and the following disclaimer in the documentation
8
+ and/or other materials provided with the distribution.
9
+ * Neither the name of the Rails Dog LLC nor the names of its
10
+ contributors may be used to endorse or promote products derived from this
11
+ software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,34 @@
1
+ Last Address extension for Spree
2
+ ================================
3
+
4
+ During checkout, causes the address to be prefilled with the address from their most recent order or
5
+ the user’s saved address (if available).
6
+
7
+ This relieves the customer of having to type in his address again on a second order. (The
8
+ unnecessary typing make them more likely to bounce instead of completing the order.)
9
+
10
+ If your app allows a user to set and edit their "preferred" or "default" address (as reflected by
11
+ `user.bill_address`/`user.ship_address`), and the user has set a preferred address for their
12
+ account, that address will take priority and be used instead of the address from their most recent
13
+ order. (Similar to [spree-default-addresses](https://github.com/swistak/spree-default-addresses).)
14
+
15
+ As of Spree 1.2, the `belongs_to :bill_address` and `belongs_to :ship_address` associations are
16
+ provided for the `Spree::User` model by the spree_auth_devise gem . If those associations are not
17
+ available or if the user doesn't have a saved address (which will be the case unless you've provided
18
+ a way in your app to set an address), then it will just use the address from user's most recent
19
+ order.
20
+
21
+ Installation
22
+ =============
23
+
24
+ Just put this in your Gemfile:
25
+
26
+ gem 'spree_last_address', :git => "git://github.com/TylerRick/spree_last_address.git"
27
+
28
+ Contributors
29
+ ============
30
+
31
+ * kenscotthlebek
32
+ * TylerRick
33
+
34
+ Copyright (c) 2010 [Torsten Rüger], released under the New BSD License
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,6 @@
1
+ "1.3.x" => { :branch => "master" }
2
+ "1.2.x" => { :branch => "master" }
3
+ "1.1.x" => { :branch => "master" }
4
+ "1.0.x" => { :branch => "master" }
5
+ "0.70.x" => { :ref => "fab7efd6c813dd4accc86ebcf2293fc34a13c89d" }
6
+ "0.60.x" => { :ref => "fab7efd6c813dd4accc86ebcf2293fc34a13c89d" }
@@ -0,0 +1,15 @@
1
+ module Spree
2
+ CheckoutController.class_eval do
3
+
4
+ private
5
+
6
+ def before_address
7
+ return if @order.bill_address or @order.ship_address
8
+ last_used_bill_address, last_used_ship_address = SpreeLastAddress.find_last_used_addresses(@order.email)
9
+ preferred_bill_address, preferred_ship_address = current_user.bill_address, current_user.ship_address if current_user.respond_to?(:bill_address) && current_user.respond_to?(:ship_address)
10
+ @order.bill_address ||= preferred_bill_address || last_used_bill_address || Address.default
11
+ @order.ship_address ||= preferred_ship_address || last_used_ship_address || Address.default
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ require "spree_last_address/version"
2
+
3
+ module SpreeLastAddress
4
+ class Engine < Rails::Engine
5
+
6
+ config.autoload_paths += %W(#{config.root}/lib)
7
+
8
+ def self.activate
9
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
10
+ Rails.env.production? ? require(c) : load(c)
11
+ end
12
+ end
13
+
14
+ config.to_prepare &method(:activate).to_proc
15
+ end
16
+
17
+ class << self
18
+ def find_last_used_addresses(email)
19
+ past = Spree::Order.order("id desc").where(:email => email).where("state != 'cart'").limit(8)
20
+ if order = past.detect(&:bill_address)
21
+ bill_address = order.bill_address.clone if order.bill_address
22
+ ship_address = order.ship_address.clone if order.ship_address
23
+ end
24
+ #puts "Found address= #{bill_address} "
25
+ return bill_address , ship_address
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ module SpreeLastAddress
2
+ def self.version
3
+ '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ namespace :spree_last_address do
2
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ Rake::Task['spree_last_address:install:migrations'].invoke
5
+ Rake::Task['spree_last_address:install:assets'].invoke
6
+ end
7
+
8
+ namespace :install do
9
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
10
+ task :migrations do
11
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
12
+ destination = File.join(Rails.root, 'db')
13
+ Spree::FileUtilz.mirror_files(source, destination)
14
+ end
15
+
16
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
17
+ task :assets do
18
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
19
+ destination = File.join(Rails.root, 'public')
20
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
21
+ Spree::FileUtilz.mirror_files(source, destination)
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1 @@
1
+ # add custom rake tasks here
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "spree_last_address/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'spree_last_address'
7
+ s.version = SpreeLastAddress.version
8
+ s.summary = "Prefill address with last-used address"
9
+ s.description = "During checkout, causes the address to be prefilled with the address from their most recent order or the user's saved address."
10
+
11
+ s.authors = ['Tyler Rick', 'Torsten Rüger']
12
+ s.email = 'tyler.rick@k3integrations.com'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+
17
+ s.require_paths = ["lib"]
18
+ s.platform = Gem::Platform::RUBY
19
+
20
+ s.add_dependency('spree_core', '~> 1.0')
21
+
22
+ # Soft requirement if using Spree > 1.2, since spree_auth_devise is now what provides
23
+ # user.bill_address association:
24
+ #s.add_development_dependency('spree_auth_devise', '~> 1.2')
25
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_last_address
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tyler Rick
9
+ - Torsten Rüger
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-02-04 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: spree_core
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '1.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.0'
31
+ description: During checkout, causes the address to be prefilled with the address
32
+ from their most recent order or the user's saved address.
33
+ email: tyler.rick@k3integrations.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - Versionfile
44
+ - app/controllers/spree/checkout_controller_decorator.rb
45
+ - lib/spree_last_address.rb
46
+ - lib/spree_last_address/version.rb
47
+ - lib/tasks/install.rake
48
+ - lib/tasks/spree_last_address.rake
49
+ - spree_last_address.gemspec
50
+ homepage:
51
+ licenses: []
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.25
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Prefill address with last-used address
74
+ test_files: []