solidus_core 1.0.0.pre2 → 1.0.0.pre3
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.
Potentially problematic release.
This version of solidus_core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/models/spree/ability.rb +52 -29
- data/app/models/spree/address.rb +1 -0
- data/app/models/spree/app_configuration.rb +8 -2
- data/app/models/spree/base.rb +3 -1
- data/app/models/spree/credit_card.rb +3 -0
- data/app/models/spree/gateway.rb +1 -1
- data/app/models/spree/gateway/bogus.rb +0 -4
- data/app/models/spree/order.rb +2 -2
- data/app/models/spree/payment_method.rb +2 -0
- data/app/models/spree/permission_sets/base.rb +14 -1
- data/app/models/spree/permission_sets/restricted_transfer_management.rb +35 -0
- data/app/models/spree/permission_sets/user_management.rb +1 -0
- data/app/models/spree/preferences/static_model_preferences.rb +47 -0
- data/app/models/spree/preferences/statically_configurable.rb +37 -0
- data/app/models/spree/product.rb +9 -0
- data/app/models/spree/promotion/rules/nth_order.rb +45 -0
- data/app/models/spree/shipment.rb +0 -2
- data/app/models/spree/store.rb +2 -2
- data/app/models/spree/variant.rb +10 -2
- data/config/locales/en.yml +7 -2
- data/db/migrate/20140309023735_migrate_old_preferences.rb +35 -7
- data/db/migrate/20140410150358_correct_some_polymorphic_index_and_add_more_missing.rb +23 -26
- data/db/migrate/20141101231208_fix_adjustment_order_presence.rb +1 -1
- data/db/migrate/20150506181611_create_spree_store_credit_payment_method.rb +5 -1
- data/db/migrate/20150616204659_add_preference_source_to_spree_payment_methods.rb +5 -0
- data/db/migrate/20150629175931_add_address_id_to_credit_card.rb +5 -0
- data/db/migrate/20150630175644_copy_order_bill_address_to_credit_card.rb +12 -0
- data/db/migrate/20150723224133_remove_unnecessary_indexes.rb +72 -0
- data/db/migrate/20150724163716_remove_state_lock_version_from_order.rb +11 -0
- data/lib/generators/spree/install/templates/config/initializers/spree.rb +12 -0
- data/lib/spree/core.rb +1 -0
- data/lib/spree/core/controller_helpers/store.rb +8 -2
- data/lib/spree/core/controller_helpers/strong_parameters.rb +12 -0
- data/lib/spree/core/current_store.rb +26 -0
- data/lib/spree/core/engine.rb +1 -0
- data/lib/spree/core/importer/order.rb +1 -0
- data/lib/spree/permitted_attributes.rb +5 -0
- data/lib/spree/testing_support/factories/payment_factory.rb +1 -1
- data/lib/spree/testing_support/order_walkthrough.rb +4 -1
- data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +117 -0
- metadata +13 -3
- data/db/migrate/20141021194502_add_state_lock_version_to_order.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c8aa521a33c27c10cdec65089ae5d044c1aa62e
|
4
|
+
data.tar.gz: c5b6055ae2ce9a0050d2fa9a1afdf938df77cca5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38bf62e7f2f12a3da4b897b6b144faf9a5bece9d80fd7fa321e70277ddd1b16b44c9dc7c490b196459100ad246903826c43e4e7162d77ce4d9e30802b6120912
|
7
|
+
data.tar.gz: b7247c74c10e6a276f20c20127073b958004f1177e75a6e0e5913eb19001d25fce59bdb923273ae8d288a7e6b2bb93c856539d2073c3e31dbcb97c81c0d590bd
|
data/app/models/spree/ability.rb
CHANGED
@@ -10,6 +10,8 @@ module Spree
|
|
10
10
|
class_attribute :abilities
|
11
11
|
self.abilities = Set.new
|
12
12
|
|
13
|
+
attr_reader :user
|
14
|
+
|
13
15
|
# Allows us to go beyond the standard cancan initialize method which makes it difficult for engines to
|
14
16
|
# modify the default +Ability+ of an application. The +ability+ argument must be a class that includes
|
15
17
|
# the +CanCan::Ability+ module. The registered ability should behave properly as a stand-alone class
|
@@ -22,8 +24,19 @@ module Spree
|
|
22
24
|
self.abilities.delete(ability)
|
23
25
|
end
|
24
26
|
|
25
|
-
def initialize(
|
26
|
-
|
27
|
+
def initialize(current_user)
|
28
|
+
@user = current_user || Spree.user_class.new
|
29
|
+
|
30
|
+
alias_actions
|
31
|
+
grant_default_permissions
|
32
|
+
register_extension_abilities
|
33
|
+
activate_permission_sets
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def alias_actions
|
39
|
+
clear_aliased_actions
|
27
40
|
|
28
41
|
# override cancan default aliasing (we don't want to differentiate between read and index)
|
29
42
|
alias_action :delete, to: :destroy
|
@@ -32,44 +45,54 @@ module Spree
|
|
32
45
|
alias_action :new_action, to: :create
|
33
46
|
alias_action :show, to: :read
|
34
47
|
alias_action :index, :read, to: :display
|
48
|
+
end
|
35
49
|
|
36
|
-
|
37
|
-
user
|
38
|
-
|
50
|
+
def grant_default_permissions
|
51
|
+
# if the user is a "super user" give them full permissions, otherwise give them the permissions
|
52
|
+
# required to checkout and use the frontend.
|
39
53
|
if user.respond_to?(:has_spree_role?) && user.has_spree_role?('admin')
|
40
54
|
can :manage, :all
|
41
55
|
else
|
42
|
-
|
43
|
-
can :display, OptionType
|
44
|
-
can :display, OptionValue
|
45
|
-
can :create, Order
|
46
|
-
can [:read, :update], Order do |order, token|
|
47
|
-
order.user == user || order.guest_token && token == order.guest_token
|
48
|
-
end
|
49
|
-
can :create, ReturnAuthorization do |return_authorization|
|
50
|
-
return_authorization.order.user == user
|
51
|
-
end
|
52
|
-
can :display, CreditCard, user_id: user.id
|
53
|
-
can :display, Product
|
54
|
-
can :display, ProductProperty
|
55
|
-
can :display, Property
|
56
|
-
can :create, Spree.user_class
|
57
|
-
can [:read, :update, :destroy], Spree.user_class, id: user.id
|
58
|
-
can :display, State
|
59
|
-
can :display, StockItem, stock_location: { active: true }
|
60
|
-
can :display, StockLocation, active: true
|
61
|
-
can :display, Taxon
|
62
|
-
can :display, Taxonomy
|
63
|
-
can [:display, :view_out_of_stock], Variant
|
64
|
-
can :display, Zone
|
56
|
+
grant_generic_user_permissions
|
65
57
|
end
|
58
|
+
end
|
66
59
|
|
67
|
-
|
60
|
+
def grant_generic_user_permissions
|
61
|
+
can :display, Country
|
62
|
+
can :display, OptionType
|
63
|
+
can :display, OptionValue
|
64
|
+
can :create, Order
|
65
|
+
can [:read, :update], Order do |order, token|
|
66
|
+
order.user == user || order.guest_token && token == order.guest_token
|
67
|
+
end
|
68
|
+
can :create, ReturnAuthorization do |return_authorization|
|
69
|
+
return_authorization.order.user == user
|
70
|
+
end
|
71
|
+
can [:display, :update], CreditCard, user_id: user.id
|
72
|
+
can :display, Product
|
73
|
+
can :display, ProductProperty
|
74
|
+
can :display, Property
|
75
|
+
can :create, Spree.user_class
|
76
|
+
can [:read, :update, :destroy], Spree.user_class, id: user.id
|
77
|
+
can :display, State
|
78
|
+
can :display, StockItem, stock_location: { active: true }
|
79
|
+
can :display, StockLocation, active: true
|
80
|
+
can :display, Taxon
|
81
|
+
can :display, Taxonomy
|
82
|
+
can [:display, :view_out_of_stock], Variant
|
83
|
+
can :display, Zone
|
84
|
+
end
|
85
|
+
|
86
|
+
# Before, this was the only way to extend this ability. Permission sets have been added since.
|
87
|
+
# It is recommended to use them instead for extension purposes if possible.
|
88
|
+
def register_extension_abilities
|
68
89
|
Ability.abilities.each do |clazz|
|
69
90
|
ability = clazz.send(:new, user)
|
70
91
|
@rules = rules + ability.send(:rules)
|
71
92
|
end
|
93
|
+
end
|
72
94
|
|
95
|
+
def activate_permission_sets
|
73
96
|
Spree::RoleConfiguration.instance.activate_permissions! self, user
|
74
97
|
end
|
75
98
|
end
|
data/app/models/spree/address.rb
CHANGED
@@ -7,6 +7,7 @@ module Spree
|
|
7
7
|
|
8
8
|
has_many :shipments, inverse_of: :address
|
9
9
|
has_many :cartons, inverse_of: :address
|
10
|
+
has_many :credit_cards, inverse_of: :address
|
10
11
|
|
11
12
|
validates :firstname, :lastname, :address1, :city, :country, presence: true
|
12
13
|
validates :zipcode, presence: true, if: :require_zipcode?
|
@@ -128,6 +128,11 @@ module Spree
|
|
128
128
|
# @return [String] URL of logo used on frontend (default: +'logo/solidus_logo.png'+)
|
129
129
|
preference :logo, :string, default: 'logo/solidus_logo.png'
|
130
130
|
|
131
|
+
# @!attribute [rw] order_bill_address_used
|
132
|
+
# @return [Boolean] Use the order's bill address, as opposed to storing
|
133
|
+
# bill addresses on payment sources. (default: +true+)
|
134
|
+
preference :order_bill_address_used, :boolean, default: true
|
135
|
+
|
131
136
|
# @!attribute [rw] order_capturing_time_window
|
132
137
|
# @return [Integer] the number of days to look back for fully-shipped/cancelled orders in order to charge for them
|
133
138
|
preference :order_capturing_time_window, :integer, default: 14
|
@@ -220,12 +225,13 @@ module Spree
|
|
220
225
|
preference :credit_to_new_allocation, :boolean, default: false
|
221
226
|
|
222
227
|
# searcher_class allows spree extension writers to provide their own Search class
|
228
|
+
attr_writer :searcher_class
|
223
229
|
def searcher_class
|
224
230
|
@searcher_class ||= Spree::Core::Search::Base
|
225
231
|
end
|
226
232
|
|
227
|
-
def
|
228
|
-
@
|
233
|
+
def static_model_preferences
|
234
|
+
@static_model_preferences ||= Spree::Preferences::StaticModelPreferences.new
|
229
235
|
end
|
230
236
|
|
231
237
|
# all the following can be deprecated when store prefs are no longer supported
|
data/app/models/spree/base.rb
CHANGED
@@ -2,7 +2,9 @@ class Spree::Base < ActiveRecord::Base
|
|
2
2
|
include Spree::Preferences::Preferable
|
3
3
|
serialize :preferences, Hash
|
4
4
|
after_initialize do
|
5
|
-
|
5
|
+
if has_attribute?(:preferences)
|
6
|
+
self.preferences = default_preferences.merge(preferences)
|
7
|
+
end
|
6
8
|
end
|
7
9
|
|
8
10
|
if Kaminari.config.page_method_name != :page
|
@@ -2,12 +2,15 @@ module Spree
|
|
2
2
|
class CreditCard < Spree::Base
|
3
3
|
belongs_to :payment_method
|
4
4
|
belongs_to :user, class_name: Spree.user_class, foreign_key: 'user_id'
|
5
|
+
belongs_to :address, inverse_of: :credit_cards
|
5
6
|
has_many :payments, as: :source
|
6
7
|
|
7
8
|
before_save :set_last_digits
|
8
9
|
|
9
10
|
after_save :ensure_one_default
|
10
11
|
|
12
|
+
accepts_nested_attributes_for :address
|
13
|
+
|
11
14
|
attr_accessor :encrypted_data,
|
12
15
|
:number,
|
13
16
|
:imported,
|
data/app/models/spree/gateway.rb
CHANGED
data/app/models/spree/order.rb
CHANGED
@@ -256,8 +256,6 @@ module Spree
|
|
256
256
|
self.class.unscoped.where(id: id).update_all(attrs_to_set)
|
257
257
|
end
|
258
258
|
|
259
|
-
attrs_to_set[:ship_address_attributes] = user.ship_address.attributes.except('id', 'updated_at', 'created_at') if user.try(:ship_address)
|
260
|
-
attrs_to_set[:bill_address_attributes] = user.bill_address.attributes.except('id', 'updated_at', 'created_at') if user.try(:bill_address)
|
261
259
|
assign_attributes(attrs_to_set)
|
262
260
|
end
|
263
261
|
|
@@ -551,6 +549,8 @@ module Spree
|
|
551
549
|
end
|
552
550
|
|
553
551
|
def restart_checkout_flow
|
552
|
+
return if self.state == 'cart'
|
553
|
+
|
554
554
|
self.update_columns(
|
555
555
|
state: 'cart',
|
556
556
|
updated_at: Time.now,
|
@@ -11,6 +11,8 @@ module Spree
|
|
11
11
|
has_many :payments, class_name: "Spree::Payment", inverse_of: :payment_method
|
12
12
|
has_many :credit_cards, class_name: "Spree::CreditCard"
|
13
13
|
|
14
|
+
include Spree::Preferences::StaticallyConfigurable
|
15
|
+
|
14
16
|
def self.providers
|
15
17
|
Rails.application.config.spree.payment_methods
|
16
18
|
end
|
@@ -1,17 +1,30 @@
|
|
1
1
|
module Spree
|
2
2
|
module PermissionSets
|
3
|
+
# This is the base class used for crafting permission sets.
|
4
|
+
#
|
5
|
+
# This is used by {Spree::RoleConfiguration} when adding custom behavior to {Spree::Ability}.
|
6
|
+
# See one of the subclasses for example structure such as {Spree::PermissionSets::UserDisplay}
|
7
|
+
#
|
8
|
+
# @see Spree::RoleConfiguration
|
9
|
+
# @see Spree::PermissionSets
|
3
10
|
class Base
|
11
|
+
# @param ability [CanCan::Ability]
|
12
|
+
# The ability that will be extended with the current permission set.
|
13
|
+
# The ability passed in must respond to #user
|
4
14
|
def initialize ability
|
5
15
|
@ability = ability
|
6
16
|
end
|
7
17
|
|
18
|
+
# Activate permissions on the ability. Put your can and cannot statements here.
|
19
|
+
# Must be overriden by subclasses
|
8
20
|
def activate!
|
9
21
|
raise NotImplementedError.new
|
10
22
|
end
|
11
23
|
|
12
24
|
private
|
13
25
|
|
14
|
-
|
26
|
+
attr_reader :ability
|
27
|
+
delegate :can, :cannot, :user, to: :ability
|
15
28
|
end
|
16
29
|
end
|
17
30
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Spree
|
2
|
+
module PermissionSets
|
3
|
+
# This is a permission set that offers an alternative to {StockManagement}.
|
4
|
+
#
|
5
|
+
# Instead of allowing management access for all stock transfers and items, only allow
|
6
|
+
# the management of stock transfers for locations the user is associated with.
|
7
|
+
#
|
8
|
+
# Users can be associated with stock locations via the admin user interface.
|
9
|
+
#
|
10
|
+
# @see Spree::PermissionSets::Base
|
11
|
+
class RestrictedTransferManagement < PermissionSets::Base
|
12
|
+
def activate!
|
13
|
+
can [:display, :admin], Spree::StockItem
|
14
|
+
can [:display, :admin], Spree::StockTransfer
|
15
|
+
|
16
|
+
if user.stock_locations.any?
|
17
|
+
can :transfer, Spree::StockLocation, id: location_ids
|
18
|
+
can :update, Spree::StockItem, stock_location_id: location_ids
|
19
|
+
can :manage, Spree::StockTransfer, source_location_id: location_ids, destination_location_id: location_ids
|
20
|
+
can :manage, Spree::TransferItem, stock_transfer: {
|
21
|
+
source_location_id: location_ids,
|
22
|
+
destination_location_id: location_ids
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def location_ids
|
30
|
+
# either source_location_id or destination_location_id can be nil.
|
31
|
+
@ids ||= user.stock_locations.pluck(:id) + [nil]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Spree
|
2
|
+
module Preferences
|
3
|
+
class StaticModelPreferences
|
4
|
+
class Definition
|
5
|
+
attr_reader :preferences
|
6
|
+
|
7
|
+
def initialize(klass, hash)
|
8
|
+
hash = hash.symbolize_keys
|
9
|
+
hash.keys.each do |key|
|
10
|
+
if !klass.defined_preferences.include?(key)
|
11
|
+
raise "Preference #{key.inspect} is not defined on #{klass}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
@preferences = hash
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch(key, &block)
|
18
|
+
@preferences.fetch(key, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def []=(key, value)
|
22
|
+
# ignores assignment
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_hash
|
26
|
+
@preferences.deep_dup
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize
|
31
|
+
@store = Hash.new do |h,klass|
|
32
|
+
h[klass] = {}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def add(klass, name, preferences)
|
37
|
+
# We use class name instead of class to allow reloading in dev
|
38
|
+
raise "Static model preference '#{name}' on #{klass} is already defined" if @store[klass.to_s][name]
|
39
|
+
@store[klass.to_s][name] = Definition.new(klass, preferences)
|
40
|
+
end
|
41
|
+
|
42
|
+
def for_class(klass)
|
43
|
+
@store[klass.to_s]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Spree
|
2
|
+
module Preferences
|
3
|
+
module StaticallyConfigurable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
class_methods do
|
7
|
+
def preference_sources
|
8
|
+
Spree::Config.static_model_preferences.for_class(self)
|
9
|
+
end
|
10
|
+
|
11
|
+
def available_preference_sources
|
12
|
+
preference_sources.keys
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# override assignment to cast empty string to nil
|
17
|
+
def preference_source=(val)
|
18
|
+
super(val.presence)
|
19
|
+
end
|
20
|
+
|
21
|
+
def preferences
|
22
|
+
if respond_to?(:preference_source) && preference_source
|
23
|
+
self.class.preference_sources[preference_source] || {}
|
24
|
+
else
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def preferences=(val)
|
30
|
+
if respond_to?(:preference_source) && preference_source
|
31
|
+
else
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/app/models/spree/product.rb
CHANGED
@@ -237,6 +237,15 @@ module Spree
|
|
237
237
|
super || variants_including_master.with_deleted.where(is_master: true).first
|
238
238
|
end
|
239
239
|
|
240
|
+
# Image that can be used for the product.
|
241
|
+
#
|
242
|
+
# Will first search for images on the product, then those belonging to the
|
243
|
+
# variants. If all else fails, will return a new image object.
|
244
|
+
# @return [Spree::Image] the image to display
|
245
|
+
def display_image
|
246
|
+
images.first || variant_images.first || Spree::Image.new
|
247
|
+
end
|
248
|
+
|
240
249
|
private
|
241
250
|
|
242
251
|
def add_associations_from_prototype
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Spree
|
2
|
+
class Promotion
|
3
|
+
module Rules
|
4
|
+
class NthOrder < PromotionRule
|
5
|
+
preference :nth_order, :integer, default: 2
|
6
|
+
# It does not make sense to have this apply to the first order using preferred_nth_order == 1
|
7
|
+
# Instead we could use the first_order rule
|
8
|
+
validates :preferred_nth_order, numericality: { only_integer: true, greater_than: 1 }
|
9
|
+
|
10
|
+
# This promotion is applicable to orders only.
|
11
|
+
def applicable?(promotable)
|
12
|
+
promotable.is_a?(Spree::Order)
|
13
|
+
end
|
14
|
+
|
15
|
+
# This is never eligible if the order does not have a user, and that user does not have any previous completed orders.
|
16
|
+
#
|
17
|
+
# Use the first order rule if you want a promotion to be applied to the first order for a user.
|
18
|
+
# @param order [Spree::Order]
|
19
|
+
# @option options
|
20
|
+
def eligible?(order, options = {})
|
21
|
+
return false unless order.user
|
22
|
+
|
23
|
+
nth_order?(order)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def completed_order_count order
|
29
|
+
order.
|
30
|
+
user.
|
31
|
+
orders.
|
32
|
+
complete.
|
33
|
+
where(Spree::Order.arel_table[:completed_at].lt(order.completed_at || Time.now)).
|
34
|
+
count
|
35
|
+
end
|
36
|
+
|
37
|
+
def nth_order? order
|
38
|
+
count = completed_order_count(order) + 1
|
39
|
+
count == preferred_nth_order
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -2,8 +2,6 @@ require 'ostruct'
|
|
2
2
|
|
3
3
|
module Spree
|
4
4
|
class Shipment < Spree::Base
|
5
|
-
belongs_to :order, class_name: 'Spree::Order', touch: true, inverse_of: :shipments
|
6
|
-
|
7
5
|
belongs_to :order, class_name: 'Spree::Order', touch: true, inverse_of: :shipments
|
8
6
|
belongs_to :address, class_name: 'Spree::Address', inverse_of: :shipments
|
9
7
|
belongs_to :stock_location, class_name: 'Spree::StockLocation'
|
data/app/models/spree/store.rb
CHANGED
@@ -10,8 +10,8 @@ module Spree
|
|
10
10
|
|
11
11
|
scope :by_url, lambda { |url| where("url like ?", "%#{url}%") }
|
12
12
|
|
13
|
-
def self.current(
|
14
|
-
current_store =
|
13
|
+
def self.current(store_key = nil)
|
14
|
+
current_store = Store.find_by(code: store_key) || Store.by_url(store_key).first
|
15
15
|
current_store || Store.default
|
16
16
|
end
|
17
17
|
|
data/app/models/spree/variant.rb
CHANGED
@@ -304,8 +304,16 @@ module Spree
|
|
304
304
|
self.track_inventory? && Spree::Config.track_inventory_levels
|
305
305
|
end
|
306
306
|
|
307
|
-
|
308
|
-
|
307
|
+
# Image that can be used for the variant.
|
308
|
+
#
|
309
|
+
# Will first search for images on the variant. If it doesn't find any,
|
310
|
+
# it'll fallback to any variant image (unless +fallback+ is +false+) or to
|
311
|
+
# a new {Spree::Image}.
|
312
|
+
# @param fallback [Boolean] whether or not we should fallback to an image
|
313
|
+
# not from this variant
|
314
|
+
# @return [Spree::Image] the image to display
|
315
|
+
def display_image(fallback: true)
|
316
|
+
images.first || (fallback && product.variant_images.first) || Spree::Image.new
|
309
317
|
end
|
310
318
|
|
311
319
|
private
|
data/config/locales/en.yml
CHANGED
@@ -570,7 +570,7 @@ en:
|
|
570
570
|
both: Both
|
571
571
|
calculated_reimbursements: Calculated Reimbursements
|
572
572
|
calculator: Calculator
|
573
|
-
calculator_settings_warning: If you are changing the calculator type, you must save first before you can edit the calculator settings
|
573
|
+
calculator_settings_warning: If you are changing the calculator type or preference source, you must save first before you can edit the calculator settings
|
574
574
|
cancel: cancel
|
575
575
|
cancel_inventory: 'Cancel Inventory'
|
576
576
|
canceled: canceled
|
@@ -1042,7 +1042,6 @@ en:
|
|
1042
1042
|
order: Order
|
1043
1043
|
order_adjustments: Order adjustments
|
1044
1044
|
order_already_completed: Order is already completed
|
1045
|
-
order_already_updated: The order has already been updated.
|
1046
1045
|
order_approved: Order approved
|
1047
1046
|
order_canceled: Order canceled
|
1048
1047
|
order_completed: Order completed
|
@@ -1149,6 +1148,8 @@ en:
|
|
1149
1148
|
price: Price
|
1150
1149
|
price_range: Price Range
|
1151
1150
|
price_sack: Price Sack
|
1151
|
+
preference_source_none: '(custom)'
|
1152
|
+
preference_source_using: 'Using static preferences "%{name}"'
|
1152
1153
|
process: Process
|
1153
1154
|
product: Product
|
1154
1155
|
product_details: Product Details
|
@@ -1212,6 +1213,10 @@ en:
|
|
1212
1213
|
taxon:
|
1213
1214
|
description: Order includes products with specified taxon(s)
|
1214
1215
|
name: Taxon(s)
|
1216
|
+
nth_order:
|
1217
|
+
description: Apply a promotion to every nth order a user has completed.
|
1218
|
+
name: Nth Order
|
1219
|
+
form_text: "Apply this promotion on the users Nth order: "
|
1215
1220
|
promotions: Promotions
|
1216
1221
|
promotion_successfully_created: Promotion has been successfully created!
|
1217
1222
|
promotion_total_changed_before_complete: "One or more of the promotions on your order have become ineligible and were removed. Please check the new order amounts and try again."
|
@@ -1,8 +1,10 @@
|
|
1
1
|
class MigrateOldPreferences < ActiveRecord::Migration
|
2
|
+
disable_ddl_transaction!
|
3
|
+
|
2
4
|
def up
|
3
5
|
migrate_preferences(Spree::Calculator)
|
4
|
-
migrate_preferences(Spree::PaymentMethod)
|
5
6
|
migrate_preferences(Spree::PromotionRule)
|
7
|
+
migrate_preferences(Spree::PaymentMethod)
|
6
8
|
end
|
7
9
|
|
8
10
|
def down
|
@@ -11,13 +13,39 @@ class MigrateOldPreferences < ActiveRecord::Migration
|
|
11
13
|
private
|
12
14
|
def migrate_preferences klass
|
13
15
|
klass.reset_column_information
|
14
|
-
klass.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
klass.find_in_batches do |batch|
|
17
|
+
ActiveRecord::Base.transaction do
|
18
|
+
batch.each do |record|
|
19
|
+
keys = record.class.defined_preferences
|
20
|
+
|
21
|
+
# Batch load preferences for this record.
|
22
|
+
preferences = Hash[Spree::Preference.where(
|
23
|
+
key: keys.map{ |k| cache_key(record, k) }
|
24
|
+
).pluck(:key, :value)]
|
25
|
+
|
26
|
+
# Copy preferences to the record.
|
27
|
+
keys.each do |key|
|
28
|
+
value = preferences[cache_key(record, key)]
|
29
|
+
record.preferences[key] = value unless value.nil?
|
30
|
+
end
|
31
|
+
|
32
|
+
# Persist the preferences.
|
33
|
+
record.update_column(:preferences, record.preferences)
|
34
|
+
end
|
19
35
|
end
|
20
|
-
record.save!
|
21
36
|
end
|
22
37
|
end
|
38
|
+
|
39
|
+
def cache_key model, key
|
40
|
+
[
|
41
|
+
ENV["RAILS_CACHE_ID"],
|
42
|
+
class_underscore_cache[model.type],
|
43
|
+
key,
|
44
|
+
model.id
|
45
|
+
].compact.join("/")
|
46
|
+
end
|
47
|
+
|
48
|
+
def class_underscore_cache
|
49
|
+
@class_underscore_cache ||= Hash.new{ |h,k| h[k] = k.underscore }
|
50
|
+
end
|
23
51
|
end
|
@@ -2,65 +2,62 @@ class CorrectSomePolymorphicIndexAndAddMoreMissing < ActiveRecord::Migration
|
|
2
2
|
def change
|
3
3
|
add_index :spree_addresses, :country_id
|
4
4
|
add_index :spree_addresses, :state_id
|
5
|
+
|
5
6
|
remove_index :spree_adjustments, [:source_type, :source_id]
|
6
7
|
add_index :spree_adjustments, [:source_id, :source_type]
|
7
|
-
|
8
|
-
add_index :spree_gateways, :active
|
9
|
-
add_index :spree_gateways, :test_mode
|
8
|
+
|
10
9
|
add_index :spree_inventory_units, :return_authorization_id
|
11
|
-
|
10
|
+
|
12
11
|
add_index :spree_log_entries, [:source_id, :source_type]
|
12
|
+
|
13
13
|
add_index :spree_orders, :approver_id
|
14
|
-
add_index :spree_orders, :bill_address_id
|
15
|
-
add_index :spree_orders, :confirmation_delivered
|
16
|
-
add_index :spree_orders, :considered_risky
|
17
14
|
add_index :spree_orders, :created_by_id
|
18
15
|
add_index :spree_orders, :ship_address_id
|
19
|
-
add_index :spree_orders, :
|
16
|
+
add_index :spree_orders, :bill_address_id
|
17
|
+
add_index :spree_orders, :considered_risky
|
18
|
+
|
20
19
|
add_index :spree_orders_promotions, [:order_id, :promotion_id]
|
20
|
+
|
21
21
|
add_index :spree_payments, [:source_id, :source_type]
|
22
|
-
|
22
|
+
|
23
23
|
add_index :spree_product_option_types, :position
|
24
|
+
|
24
25
|
add_index :spree_product_properties, :position
|
25
26
|
add_index :spree_product_properties, :property_id
|
26
|
-
|
27
|
-
add_index :spree_products, :tax_category_id
|
27
|
+
|
28
28
|
add_index :spree_promotion_action_line_items, :promotion_action_id
|
29
29
|
add_index :spree_promotion_action_line_items, :variant_id
|
30
|
+
|
30
31
|
add_index :spree_promotion_rules, :promotion_id
|
32
|
+
|
31
33
|
add_index :spree_promotions, :advertise
|
34
|
+
|
32
35
|
add_index :spree_return_authorizations, :number
|
33
36
|
add_index :spree_return_authorizations, :order_id
|
34
37
|
add_index :spree_return_authorizations, :stock_location_id
|
38
|
+
|
35
39
|
add_index :spree_shipments, :address_id
|
36
|
-
|
40
|
+
|
37
41
|
add_index :spree_shipping_methods, :tax_category_id
|
38
|
-
|
39
|
-
add_index :spree_shipping_rates, :tax_rate_id
|
42
|
+
|
40
43
|
add_index :spree_state_changes, [:stateful_id, :stateful_type]
|
41
44
|
add_index :spree_state_changes, :user_id
|
42
|
-
|
43
|
-
add_index :spree_stock_locations, :active
|
44
|
-
add_index :spree_stock_locations, :backorderable_default
|
45
|
+
|
45
46
|
add_index :spree_stock_locations, :country_id
|
46
|
-
add_index :spree_stock_locations, :propagate_all_variants
|
47
47
|
add_index :spree_stock_locations, :state_id
|
48
|
-
|
49
|
-
add_index :spree_tax_categories, :is_default
|
48
|
+
|
50
49
|
add_index :spree_tax_rates, :deleted_at
|
51
|
-
add_index :spree_tax_rates, :included_in_price
|
52
|
-
add_index :spree_tax_rates, :show_rate_in_label
|
53
50
|
add_index :spree_tax_rates, :tax_category_id
|
54
51
|
add_index :spree_tax_rates, :zone_id
|
52
|
+
|
55
53
|
add_index :spree_taxonomies, :position
|
54
|
+
|
56
55
|
add_index :spree_taxons, :position
|
57
|
-
|
58
|
-
add_index :spree_variants, :deleted_at
|
59
|
-
add_index :spree_variants, :is_master
|
56
|
+
|
60
57
|
add_index :spree_variants, :position
|
61
58
|
add_index :spree_variants, :track_inventory
|
59
|
+
|
62
60
|
add_index :spree_zone_members, :zone_id
|
63
61
|
add_index :spree_zone_members, [:zoneable_id, :zoneable_type]
|
64
|
-
add_index :spree_zones, :default_tax
|
65
62
|
end
|
66
63
|
end
|
@@ -6,7 +6,7 @@ class FixAdjustmentOrderPresence < ActiveRecord::Migration
|
|
6
6
|
if adjustable.is_a? Spree::Order
|
7
7
|
adjustment.update_attributes!(order_id: adjustable.id)
|
8
8
|
else
|
9
|
-
adjustment.update_attributes!(
|
9
|
+
adjustment.update_attributes!(order_id: adjustable.order.id)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
class CreateSpreeStoreCreditPaymentMethod < ActiveRecord::Migration
|
2
|
+
class PaymentMethod < ActiveRecord::Base
|
3
|
+
self.table_name = 'spree_payment_methods'
|
4
|
+
self.inheritance_column = :_type_disabled
|
5
|
+
end
|
2
6
|
def up
|
3
|
-
|
7
|
+
PaymentMethod.create_with(
|
4
8
|
name: Spree.t("store_credit.store_credit"),
|
5
9
|
description: Spree.t("store_credit.store_credit"),
|
6
10
|
active: true,
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class CopyOrderBillAddressToCreditCard < ActiveRecord::Migration
|
2
|
+
# Prevent everything from running in one giant transaction in postrgres.
|
3
|
+
disable_ddl_transaction!
|
4
|
+
|
5
|
+
def up
|
6
|
+
Rake::Task["spree:migrations:copy_order_bill_address_to_credit_card:up"].invoke
|
7
|
+
end
|
8
|
+
|
9
|
+
def down
|
10
|
+
Rake::Task["spree:migrations:copy_order_bill_address_to_credit_card:down"].invoke
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# All of these indexes were originally added in
|
2
|
+
# 20140410150358_correct_some_polymorphic_index_and_add_more_missing.rb
|
3
|
+
# However, most are necessary and were removed from that migration. This
|
4
|
+
# migration deletes any of the indexes left around in stores using the
|
5
|
+
# out-dated version of that migration
|
6
|
+
class RemoveUnnecessaryIndexes < ActiveRecord::Migration
|
7
|
+
def up
|
8
|
+
safe_remove_index :spree_credit_cards, :address_id
|
9
|
+
safe_remove_index :spree_gateways, :active
|
10
|
+
safe_remove_index :spree_gateways, :test_mode
|
11
|
+
safe_remove_index :spree_inventory_units, :return_authorization_id
|
12
|
+
safe_remove_index :spree_line_items, :tax_category_id
|
13
|
+
safe_remove_index :spree_orders, :shipping_method_id
|
14
|
+
safe_remove_index :spree_orders, :confirmation_delivered
|
15
|
+
safe_remove_index :spree_prices, :deleted_at
|
16
|
+
safe_remove_index :spree_products, :shipping_category_id
|
17
|
+
safe_remove_index :spree_products, :tax_category_id
|
18
|
+
safe_remove_index :spree_shipping_methods, :deleted_at
|
19
|
+
safe_remove_index :spree_shipping_rates, :selected
|
20
|
+
safe_remove_index :spree_shipping_rates, :tax_rate_id
|
21
|
+
safe_remove_index :spree_stock_items, :backorderable
|
22
|
+
safe_remove_index :spree_stock_locations, :active
|
23
|
+
safe_remove_index :spree_stock_locations, :backorderable_default
|
24
|
+
safe_remove_index :spree_stock_locations, :propagate_all_variants
|
25
|
+
safe_remove_index :spree_tax_categories, :is_default
|
26
|
+
safe_remove_index :spree_tax_categories, :deleted_at
|
27
|
+
safe_remove_index :spree_tax_rates, :show_rate_in_label
|
28
|
+
safe_remove_index :spree_tax_rates, :included_in_price
|
29
|
+
safe_remove_index :spree_trackers, :active
|
30
|
+
safe_remove_index :spree_variants, :is_master
|
31
|
+
safe_remove_index :spree_variants, :deleted_at
|
32
|
+
safe_remove_index :spree_zones, :default_tax
|
33
|
+
end
|
34
|
+
|
35
|
+
def down
|
36
|
+
safe_add_index :spree_credit_cards, :address_id
|
37
|
+
safe_add_index :spree_gateways, :active
|
38
|
+
safe_add_index :spree_gateways, :test_mode
|
39
|
+
safe_add_index :spree_inventory_units, :return_authorization_id
|
40
|
+
safe_add_index :spree_line_items, :tax_category_id
|
41
|
+
safe_add_index :spree_orders, :shipping_method_id
|
42
|
+
safe_add_index :spree_orders, :confirmation_delivered
|
43
|
+
safe_add_index :spree_prices, :deleted_at
|
44
|
+
safe_add_index :spree_products, :shipping_category_id
|
45
|
+
safe_add_index :spree_products, :tax_category_id
|
46
|
+
safe_add_index :spree_shipping_methods, :deleted_at
|
47
|
+
safe_add_index :spree_shipping_rates, :selected
|
48
|
+
safe_add_index :spree_shipping_rates, :tax_rate_id
|
49
|
+
safe_add_index :spree_stock_items, :backorderable
|
50
|
+
safe_add_index :spree_stock_locations, :active
|
51
|
+
safe_add_index :spree_stock_locations, :backorderable_default
|
52
|
+
safe_add_index :spree_stock_locations, :propagate_all_variants
|
53
|
+
safe_add_index :spree_tax_categories, :is_default
|
54
|
+
safe_add_index :spree_tax_categories, :deleted_at
|
55
|
+
safe_add_index :spree_tax_rates, :show_rate_in_label
|
56
|
+
safe_add_index :spree_tax_rates, :included_in_price
|
57
|
+
safe_add_index :spree_trackers, :active
|
58
|
+
safe_add_index :spree_variants, :is_master
|
59
|
+
safe_add_index :spree_variants, :deleted_at
|
60
|
+
safe_add_index :spree_zones, :default_tax
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def safe_remove_index(table, column)
|
66
|
+
remove_index(table, column) if index_exists?(table, column)
|
67
|
+
end
|
68
|
+
|
69
|
+
def safe_add_index(table, column)
|
70
|
+
add_index(table, column) if column_exists?(table, column)
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class RemoveStateLockVersionFromOrder < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
if column_exists? :spree_orders, :state_lock_version
|
4
|
+
remove_column :spree_orders, :state_lock_version
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def down
|
9
|
+
add_column :spree_orders, :state_lock_version, :integer, default: 0, null: false
|
10
|
+
end
|
11
|
+
end
|
@@ -36,6 +36,18 @@ Spree.config do |config|
|
|
36
36
|
|
37
37
|
# Custom logo for the admin
|
38
38
|
# config.admin_interface_logo = "logo/solidus_logo.png"
|
39
|
+
|
40
|
+
# Gateway credentials can be configured statically here and referenced from
|
41
|
+
# the admin. They can also be fully configured from the admin.
|
42
|
+
#
|
43
|
+
# config.static_model_preferences.add(
|
44
|
+
# Spree::Gateway::StripeGateway,
|
45
|
+
# 'stripe_env_credentials',
|
46
|
+
# secret_key: ENV['STRIPE_SECRET_KEY'],
|
47
|
+
# publishable_key: ENV['STRIPE_PUBLISHABLE_KEY'],
|
48
|
+
# server: Rails.env.production? ? 'production' : 'test',
|
49
|
+
# test: !Rails.env.production?
|
50
|
+
# )
|
39
51
|
end
|
40
52
|
|
41
53
|
Spree.user_class = <%= (options[:user_class].blank? ? "Spree::LegacyUser" : options[:user_class]).inspect %>
|
data/lib/spree/core.rb
CHANGED
@@ -81,6 +81,7 @@ require 'spree/core/delegate_belongs_to'
|
|
81
81
|
require 'spree/core/importer'
|
82
82
|
require 'spree/core/permalinks'
|
83
83
|
require 'spree/core/product_duplicator'
|
84
|
+
require 'spree/core/current_store'
|
84
85
|
require 'spree/core/controller_helpers/auth'
|
85
86
|
require 'spree/core/controller_helpers/common'
|
86
87
|
require 'spree/core/controller_helpers/order'
|
@@ -4,13 +4,19 @@ module Spree
|
|
4
4
|
module Store
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
+
# @!attribute [rw] current_store_class
|
8
|
+
# @!scope class
|
9
|
+
# Extension point for overriding how the current store is chosen.
|
10
|
+
# Defaults to checking headers and server name
|
11
|
+
# @return [#store] class used to help find the current store
|
7
12
|
included do
|
13
|
+
class_attribute :current_store_class
|
14
|
+
self.current_store_class = Spree::Core::CurrentStore
|
8
15
|
|
9
16
|
def current_store
|
10
|
-
@current_store ||=
|
17
|
+
@current_store ||= current_store_class.new(request).store
|
11
18
|
end
|
12
19
|
helper_method :current_store
|
13
|
-
|
14
20
|
end
|
15
21
|
|
16
22
|
end
|
@@ -10,12 +10,24 @@ module Spree
|
|
10
10
|
to: :permitted_attributes,
|
11
11
|
prefix: :permitted
|
12
12
|
|
13
|
+
def permitted_credit_card_update_attributes
|
14
|
+
permitted_attributes.credit_card_update_attributes + [
|
15
|
+
address_attributes: permitted_address_attributes,
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
13
19
|
def permitted_payment_attributes
|
14
20
|
permitted_attributes.payment_attributes + [
|
15
21
|
source_attributes: permitted_source_attributes
|
16
22
|
]
|
17
23
|
end
|
18
24
|
|
25
|
+
def permitted_source_attributes
|
26
|
+
permitted_attributes.source_attributes + [
|
27
|
+
address_attributes: permitted_address_attributes,
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
19
31
|
def permitted_checkout_attributes
|
20
32
|
permitted_attributes.checkout_attributes + [
|
21
33
|
bill_address_attributes: permitted_address_attributes,
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Default class for deciding what the current store is, given an HTTP request
|
2
|
+
# This is an extension point used in Spree::Core::ControllerHelpers::Store
|
3
|
+
# Custom versions of this class must respond to a store instance method
|
4
|
+
module Spree
|
5
|
+
module Core
|
6
|
+
class CurrentStore
|
7
|
+
def initialize(request)
|
8
|
+
@request = request
|
9
|
+
end
|
10
|
+
|
11
|
+
# Chooses the current store based on a request.
|
12
|
+
# Checks request headers for HTTP_SPREE_STORE and falls back to
|
13
|
+
# looking up by the requesting server's name.
|
14
|
+
# @return [Spree::Store]
|
15
|
+
def store
|
16
|
+
Spree::Store.current(store_key)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def store_key
|
22
|
+
@request.headers['HTTP_SPREE_STORE'] || @request.env['SERVER_NAME']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/spree/core/engine.rb
CHANGED
@@ -6,6 +6,7 @@ module Spree
|
|
6
6
|
ATTRIBUTES = [
|
7
7
|
:address_attributes,
|
8
8
|
:checkout_attributes,
|
9
|
+
:credit_card_update_attributes,
|
9
10
|
:customer_return_attributes,
|
10
11
|
:image_attributes,
|
11
12
|
:inventory_unit_attributes,
|
@@ -44,6 +45,10 @@ module Spree
|
|
44
45
|
:coupon_code, :email, :shipping_method_id, :special_instructions, :use_billing
|
45
46
|
]
|
46
47
|
|
48
|
+
@@credit_card_update_attributes = [
|
49
|
+
:month, :year, :expiry, :first_name, :last_name, :name,
|
50
|
+
]
|
51
|
+
|
47
52
|
@@customer_return_attributes = [:stock_location_id, return_items_attributes: [:id, :inventory_unit_id, :return_authorization_id, :returned, :pre_tax_amount, :reception_status_event, :acceptance_status, :exchange_variant_id, :resellable]]
|
48
53
|
|
49
54
|
@@image_attributes = [:alt, :attachment, :position, :viewable_type, :viewable_id]
|
@@ -1,5 +1,5 @@
|
|
1
1
|
FactoryGirl.define do
|
2
|
-
factory :payment, class: Spree::Payment do
|
2
|
+
factory :payment, aliases: [:credit_card_payment], class: Spree::Payment do
|
3
3
|
amount 45.75
|
4
4
|
association(:payment_method, factory: :credit_card_payment_method)
|
5
5
|
association(:source, factory: :credit_card)
|
@@ -15,7 +15,10 @@ class OrderWalkthrough
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
order = Spree::Order.create!(
|
18
|
+
order = Spree::Order.create!(
|
19
|
+
email: "spree@example.com",
|
20
|
+
store: Spree::Store.first || FactoryGirl.create(:store)
|
21
|
+
)
|
19
22
|
add_line_item!(order)
|
20
23
|
order.next!
|
21
24
|
|
@@ -0,0 +1,117 @@
|
|
1
|
+
namespace 'spree:migrations:copy_order_bill_address_to_credit_card' do
|
2
|
+
# This copies the billing address from the order associated with a
|
3
|
+
# credit card's most recent payment to the credit card.
|
4
|
+
|
5
|
+
# Used in the migration CopyOrderBillAddressToCreditCard and made available as a
|
6
|
+
# rake task to allow running it a second time after deploying the new code, in
|
7
|
+
# case some order->credit card data was missed between the time that the
|
8
|
+
# migration was run and the application servers were restarted with the new
|
9
|
+
# code.
|
10
|
+
|
11
|
+
# This task should be safe to run multiple times.
|
12
|
+
|
13
|
+
task up: :environment do
|
14
|
+
puts "Copying order bill addresses to credit cards"
|
15
|
+
|
16
|
+
if Spree::CreditCard.connection.adapter_name =~ /postgres/i
|
17
|
+
postgres_copy
|
18
|
+
else
|
19
|
+
ruby_copy
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
task down: :environment do
|
24
|
+
Spree::CreditCard.update_all(address_id: nil)
|
25
|
+
end
|
26
|
+
|
27
|
+
def ruby_copy
|
28
|
+
scope = Spree::CreditCard.where(address_id: nil).includes(payments: :order)
|
29
|
+
|
30
|
+
scope.find_each(batch_size: 500) do |cc|
|
31
|
+
# remove payments that lack a bill address
|
32
|
+
payments = cc.payments.select { |p| p.order.bill_address_id }
|
33
|
+
|
34
|
+
payment = payments.sort_by do |p|
|
35
|
+
[
|
36
|
+
%w(failed invalid).include?(p.state) ? 0 : 1, # prioritize valid payments
|
37
|
+
p.created_at, # prioritize more recent payments
|
38
|
+
]
|
39
|
+
end.last
|
40
|
+
|
41
|
+
next if payment.nil?
|
42
|
+
|
43
|
+
cc.update_column(:address_id, payment.order.bill_address_id)
|
44
|
+
puts "Successfully associated billing address (#{payment.order.bill_address_id}) with credit card (#{cc.id})"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# This was 20x faster for us but the syntax is postgres-specific. I'm sure
|
49
|
+
# there are equivalent versions for other DBs if someone wants to write them.
|
50
|
+
# I took a quick stab at crafting a cross-db compatible version but it was
|
51
|
+
# slow.
|
52
|
+
def postgres_copy
|
53
|
+
batch_size = 10_000
|
54
|
+
|
55
|
+
puts "last id: #{last_credit_card_id}"
|
56
|
+
|
57
|
+
current_start_id = 1
|
58
|
+
|
59
|
+
while current_start_id <= last_credit_card_id
|
60
|
+
current_end_id = current_start_id + batch_size
|
61
|
+
puts "updating #{current_start_id} to #{current_end_id}"
|
62
|
+
|
63
|
+
# first try to find a valid payment for each credit card
|
64
|
+
Spree::CreditCard.connection.execute(
|
65
|
+
postgres_sql(
|
66
|
+
start_id: current_start_id,
|
67
|
+
end_id: current_end_id,
|
68
|
+
payment_state: "not in ('failed', 'invalid')",
|
69
|
+
)
|
70
|
+
)
|
71
|
+
|
72
|
+
# fall back to using invalid payments for each credit card
|
73
|
+
Spree::CreditCard.connection.execute(
|
74
|
+
postgres_sql(
|
75
|
+
start_id: current_start_id,
|
76
|
+
end_id: current_end_id,
|
77
|
+
payment_state: "in ('failed', 'invalid')",
|
78
|
+
)
|
79
|
+
)
|
80
|
+
|
81
|
+
current_start_id += batch_size
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def postgres_sql(start_id:, end_id:, payment_state:)
|
86
|
+
<<-SQL
|
87
|
+
update spree_credit_cards c
|
88
|
+
set address_id = o.bill_address_id
|
89
|
+
from spree_payments p
|
90
|
+
inner join spree_orders o
|
91
|
+
on o.id = p.order_id
|
92
|
+
and o.bill_address_id is not null
|
93
|
+
left join (
|
94
|
+
select p2.*
|
95
|
+
from spree_payments p2
|
96
|
+
inner join spree_orders o2
|
97
|
+
on o2.id = p2.order_id
|
98
|
+
and o2.bill_address_id is not null
|
99
|
+
) more_recent_payment
|
100
|
+
on more_recent_payment.source_id = p.source_id
|
101
|
+
and more_recent_payment.source_type = 'Spree::CreditCard'
|
102
|
+
and more_recent_payment.created_at > p.created_at
|
103
|
+
and more_recent_payment.state #{payment_state}
|
104
|
+
where c.address_id is null
|
105
|
+
and p.source_id = c.id
|
106
|
+
and p.source_type = 'Spree::CreditCard'
|
107
|
+
and p.state #{payment_state}
|
108
|
+
and more_recent_payment.id is null
|
109
|
+
and o.bill_address_id is not null
|
110
|
+
and c.id between #{start_id} and #{end_id}
|
111
|
+
SQL
|
112
|
+
end
|
113
|
+
|
114
|
+
def last_credit_card_id
|
115
|
+
Spree::CreditCard.last.try!(:id) || 0
|
116
|
+
end
|
117
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.pre3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Solidus Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemerchant
|
@@ -461,6 +461,7 @@ files:
|
|
461
461
|
- app/models/spree/permission_sets/promotion_display.rb
|
462
462
|
- app/models/spree/permission_sets/promotion_management.rb
|
463
463
|
- app/models/spree/permission_sets/report_display.rb
|
464
|
+
- app/models/spree/permission_sets/restricted_transfer_management.rb
|
464
465
|
- app/models/spree/permission_sets/stock_display.rb
|
465
466
|
- app/models/spree/permission_sets/stock_management.rb
|
466
467
|
- app/models/spree/permission_sets/user_display.rb
|
@@ -470,6 +471,8 @@ files:
|
|
470
471
|
- app/models/spree/preferences/preferable.rb
|
471
472
|
- app/models/spree/preferences/preferable_class_methods.rb
|
472
473
|
- app/models/spree/preferences/scoped_store.rb
|
474
|
+
- app/models/spree/preferences/static_model_preferences.rb
|
475
|
+
- app/models/spree/preferences/statically_configurable.rb
|
473
476
|
- app/models/spree/preferences/store.rb
|
474
477
|
- app/models/spree/price.rb
|
475
478
|
- app/models/spree/product.rb
|
@@ -484,6 +487,7 @@ files:
|
|
484
487
|
- app/models/spree/promotion/actions/free_shipping.rb
|
485
488
|
- app/models/spree/promotion/rules/first_order.rb
|
486
489
|
- app/models/spree/promotion/rules/item_total.rb
|
490
|
+
- app/models/spree/promotion/rules/nth_order.rb
|
487
491
|
- app/models/spree/promotion/rules/one_use_per_user.rb
|
488
492
|
- app/models/spree/promotion/rules/option_value.rb
|
489
493
|
- app/models/spree/promotion/rules/product.rb
|
@@ -794,7 +798,6 @@ files:
|
|
794
798
|
- db/migrate/20141007230328_add_cancel_audit_fields_to_spree_orders.rb
|
795
799
|
- db/migrate/20141009204607_add_store_id_to_orders.rb
|
796
800
|
- db/migrate/20141012083513_create_spree_taxons_prototypes.rb
|
797
|
-
- db/migrate/20141021194502_add_state_lock_version_to_order.rb
|
798
801
|
- db/migrate/20141023005240_add_counter_cache_from_spree_variants_to_spree_stock_items.rb
|
799
802
|
- db/migrate/20141101231208_fix_adjustment_order_presence.rb
|
800
803
|
- db/migrate/20141105213646_update_classifications_positions.rb
|
@@ -848,6 +851,7 @@ files:
|
|
848
851
|
- db/migrate/20150610182638_add_id_to_spree_option_values_variants.rb
|
849
852
|
- db/migrate/20150611200247_add_frontend_viewable_to_spree_orders.rb
|
850
853
|
- db/migrate/20150612205731_remove_spree_configurations.rb
|
854
|
+
- db/migrate/20150616204659_add_preference_source_to_spree_payment_methods.rb
|
851
855
|
- db/migrate/20150618191713_remove_credit_card_address_id.rb
|
852
856
|
- db/migrate/20150618212517_create_spree_store_credit_update_reasons.rb
|
853
857
|
- db/migrate/20150619160613_create_adjustment_reason.rb
|
@@ -856,6 +860,10 @@ files:
|
|
856
860
|
- db/migrate/20150623214058_seed_store_credit_update_reasons.rb
|
857
861
|
- db/migrate/20150626200816_remove_shipping_method_id_from_spree_orders.rb
|
858
862
|
- db/migrate/20150626214817_remove_counter_cache_from_spree_variants_to_spree_stock_items.rb
|
863
|
+
- db/migrate/20150629175931_add_address_id_to_credit_card.rb
|
864
|
+
- db/migrate/20150630175644_copy_order_bill_address_to_credit_card.rb
|
865
|
+
- db/migrate/20150723224133_remove_unnecessary_indexes.rb
|
866
|
+
- db/migrate/20150724163716_remove_state_lock_version_from_order.rb
|
859
867
|
- db/seeds.rb
|
860
868
|
- lib/generators/spree/custom_user/custom_user_generator.rb
|
861
869
|
- lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt
|
@@ -885,6 +893,7 @@ files:
|
|
885
893
|
- lib/spree/core/controller_helpers/search.rb
|
886
894
|
- lib/spree/core/controller_helpers/store.rb
|
887
895
|
- lib/spree/core/controller_helpers/strong_parameters.rb
|
896
|
+
- lib/spree/core/current_store.rb
|
888
897
|
- lib/spree/core/delegate_belongs_to.rb
|
889
898
|
- lib/spree/core/engine.rb
|
890
899
|
- lib/spree/core/environment.rb
|
@@ -985,6 +994,7 @@ files:
|
|
985
994
|
- lib/tasks/core.rake
|
986
995
|
- lib/tasks/email.rake
|
987
996
|
- lib/tasks/exchanges.rake
|
997
|
+
- lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake
|
988
998
|
- lib/tasks/migrations/copy_shipped_shipments_to_cartons.rake
|
989
999
|
- lib/tasks/order_capturing.rake
|
990
1000
|
- vendor/assets/javascripts/jquery-migrate-1.0.0.js
|