solidus_bank_transfer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +26 -0
- data/README.md +63 -0
- data/Rakefile +32 -0
- data/app/assets/javascripts/spree/backend/solidus_bank_transfer.js +2 -0
- data/app/assets/javascripts/spree/frontend/solidus_bank_transfer.js +2 -0
- data/app/assets/stylesheets/spree/backend/solidus_bank_transfer.css +4 -0
- data/app/assets/stylesheets/spree/frontend/solidus_bank_transfer.css +4 -0
- data/app/models/spree/payment_method/bank_transfer.rb +46 -0
- data/app/views/spree/checkout/payment/_banktransfer.html.erb +16 -0
- data/app/views/spree/order_mailer/_bank_transfer_details.html.erb +23 -0
- data/app/views/spree/orders/_bank_transfer_details.html.erb +22 -0
- data/config/locales/en.yml +14 -0
- data/config/locales/it.yml +14 -0
- data/config/routes.rb +5 -0
- data/lib/generators/solidus_bank_transfer/install/install_generator.rb +32 -0
- data/lib/solidus_bank_transfer.rb +4 -0
- data/lib/solidus_bank_transfer/engine.rb +26 -0
- data/lib/solidus_bank_transfer/factories.rb +17 -0
- data/lib/solidus_bank_transfer/version.rb +5 -0
- data/spec/dummy/README.md +24 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/app/assets/javascripts/cable.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +33 -0
- data/spec/dummy/bin/update +28 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/config/application.rb +54 -0
- data/spec/dummy/config/boot.rb +6 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/credentials.yml.enc +1 -0
- data/spec/dummy/config/database.yml +21 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +61 -0
- data/spec/dummy/config/environments/production.rb +94 -0
- data/spec/dummy/config/environments/test.rb +33 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/assets.rb +12 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/spree.rb +52 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/master.key +1 -0
- data/spec/dummy/config/routes.rb +9 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/db/migrate/20190822070920_create_active_storage_tables.active_storage.rb +27 -0
- data/spec/dummy/db/migrate/20190822070921_solidus_one_four.spree.rb +1103 -0
- data/spec/dummy/db/migrate/20190822070922_create_spree_wallet_payment_sources.spree.rb +28 -0
- data/spec/dummy/db/migrate/20190822070923_migrate_credit_cards_to_wallet_payment_sources.spree.rb +30 -0
- data/spec/dummy/db/migrate/20190822070924_remove_is_default_from_prices.spree.rb +8 -0
- data/spec/dummy/db/migrate/20190822070925_remove_currency_from_line_items.spree.rb +8 -0
- data/spec/dummy/db/migrate/20190822070926_add_available_to_columns_and_remove_display_on_from_payment_methods.spree.rb +31 -0
- data/spec/dummy/db/migrate/20190822070927_create_spree_promotion_code_batch.spree.rb +39 -0
- data/spec/dummy/db/migrate/20190822070928_add_available_to_users_and_remove_display_on_from_shipping_methods.spree.rb +23 -0
- data/spec/dummy/db/migrate/20190822070929_add_index_to_spree_payments_number.spree.rb +8 -0
- data/spec/dummy/db/migrate/20190822070930_remove_spree_store_credits_column.spree.rb +8 -0
- data/spec/dummy/db/migrate/20190822070931_add_lft_and_rgt_indexes_to_taxons.spree.rb +9 -0
- data/spec/dummy/db/migrate/20190822070932_remove_order_id_from_inventory_units.spree.rb +31 -0
- data/spec/dummy/db/migrate/20190822070933_transform_tax_rate_category_relation.spree.rb +51 -0
- data/spec/dummy/db/migrate/20190822070934_add_roles_unique_constraints.spree.rb +9 -0
- data/spec/dummy/db/migrate/20190822070935_add_time_range_to_tax_rate.spree.rb +9 -0
- data/spec/dummy/db/migrate/20190822070936_rename_bogus_gateways.spree.rb +19 -0
- data/spec/dummy/db/migrate/20190822070937_remove_default_tax_from_spree_zones.spree.rb +8 -0
- data/spec/dummy/db/migrate/20190822070938_create_promotion_rule_stores.spree.rb +13 -0
- data/spec/dummy/db/migrate/20190822070939_create_store_shipping_methods.spree.rb +13 -0
- data/spec/dummy/db/migrate/20190822070940_add_available_locales_to_stores.spree.rb +10 -0
- data/spec/dummy/db/migrate/20190822070941_add_amount_remaining_to_store_credit_events.spree.rb +62 -0
- data/spec/dummy/db/migrate/20190822070942_add_join_characters_to_promotion_code_batch.spree.rb +12 -0
- data/spec/dummy/db/migrate/20190822070943_create_spree_store_credit_reasons_table.spree.rb +56 -0
- data/spec/dummy/db/migrate/20190822070944_remove_code_from_spree_promotions.spree.rb +43 -0
- data/spec/dummy/db/migrate/20190822070945_drop_spree_store_credit_update_reasons.spree.rb +20 -0
- data/spec/dummy/db/migrate/20190822070946_add_api_key_to_spree_users.spree_api.rb +10 -0
- data/spec/dummy/db/migrate/20190822070947_resize_api_key_field.spree_api.rb +10 -0
- data/spec/dummy/db/migrate/20190822070948_rename_api_key_to_spree_api_key.spree_api.rb +10 -0
- data/spec/dummy/db/migrate/20190822070949_add_index_to_user_spree_api_key.spree_api.rb +10 -0
- data/spec/dummy/db/migrate/20190822070950_create_users.solidus_auth.rb +30 -0
- data/spec/dummy/db/migrate/20190822070951_rename_columns_for_devise.solidus_auth.rb +38 -0
- data/spec/dummy/db/migrate/20190822070952_convert_user_remember_field.solidus_auth.rb +12 -0
- data/spec/dummy/db/migrate/20190822070953_add_reset_password_sent_at_to_spree_users.solidus_auth.rb +9 -0
- data/spec/dummy/db/migrate/20190822070954_make_users_email_index_unique.solidus_auth.rb +10 -0
- data/spec/dummy/db/migrate/20190822070955_add_deleted_at_to_users.solidus_auth.rb +7 -0
- data/spec/dummy/db/migrate/20190822070956_add_confirmable_to_users.solidus_auth.rb +8 -0
- data/spec/dummy/db/schema.rb +1194 -0
- data/spec/dummy/db/seeds.rb +10 -0
- data/spec/dummy/log/test.log +1058 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/development_secret.txt +1 -0
- data/spec/dummy/vendor/assets/javascripts/spree/backend/all.js +11 -0
- data/spec/dummy/vendor/assets/javascripts/spree/frontend/all.js +11 -0
- data/spec/dummy/vendor/assets/stylesheets/spree/backend/all.css +10 -0
- data/spec/dummy/vendor/assets/stylesheets/spree/frontend/all.css +10 -0
- data/spec/models/spree/payment_method/bank_transfer_spec.rb +146 -0
- data/spec/spec_helper.rb +89 -0
- metadata +429 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This migration comes from spree (originally 20160420044191)
|
3
|
+
|
4
|
+
class CreateSpreeWalletPaymentSources < ActiveRecord::Migration[4.2]
|
5
|
+
def change
|
6
|
+
return if table_exists?(:spree_wallet_payment_sources)
|
7
|
+
|
8
|
+
create_table :spree_wallet_payment_sources do |t|
|
9
|
+
t.references(
|
10
|
+
:user,
|
11
|
+
foreign_key: { to_table: Spree.user_class.table_name },
|
12
|
+
index: true,
|
13
|
+
null: false,
|
14
|
+
)
|
15
|
+
t.references :payment_source, polymorphic: true, null: false
|
16
|
+
t.boolean :default, default: false, null: false
|
17
|
+
|
18
|
+
t.timestamps null: false, precision: 6
|
19
|
+
end
|
20
|
+
|
21
|
+
add_index(
|
22
|
+
:spree_wallet_payment_sources,
|
23
|
+
[:user_id, :payment_source_id, :payment_source_type],
|
24
|
+
unique: true,
|
25
|
+
name: 'index_spree_wallet_payment_sources_on_source_and_user',
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
data/spec/dummy/db/migrate/20190822070923_migrate_credit_cards_to_wallet_payment_sources.spree.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This migration comes from spree (originally 20160420181916)
|
3
|
+
|
4
|
+
class MigrateCreditCardsToWalletPaymentSources < ActiveRecord::Migration[4.2]
|
5
|
+
class CreditCard < ActiveRecord::Base
|
6
|
+
self.table_name = 'spree_credit_cards'
|
7
|
+
end
|
8
|
+
class WalletPaymentSource < ActiveRecord::Base
|
9
|
+
self.table_name = 'spree_wallet_payment_sources'
|
10
|
+
end
|
11
|
+
|
12
|
+
def up
|
13
|
+
credit_cards = CreditCard.
|
14
|
+
where.not(gateway_customer_profile_id: nil).
|
15
|
+
where.not(user_id: nil)
|
16
|
+
|
17
|
+
credit_cards.find_each do |credit_card|
|
18
|
+
WalletPaymentSource.find_or_create_by!(
|
19
|
+
user_id: credit_card.user_id,
|
20
|
+
payment_source_id: credit_card.id,
|
21
|
+
payment_source_type: 'Spree::CreditCard'
|
22
|
+
) do |wallet_source|
|
23
|
+
wallet_source.default = credit_card.default
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def down
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This migration comes from spree (originally 20161014221052)
|
3
|
+
|
4
|
+
class AddAvailableToColumnsAndRemoveDisplayOnFromPaymentMethods < ActiveRecord::Migration[5.0]
|
5
|
+
def up
|
6
|
+
add_column(:spree_payment_methods, :available_to_users, :boolean, default: true)
|
7
|
+
add_column(:spree_payment_methods, :available_to_admin, :boolean, default: true)
|
8
|
+
execute("UPDATE spree_payment_methods "\
|
9
|
+
"SET available_to_users=#{quoted_false} "\
|
10
|
+
"WHERE NOT (display_on='front_end' OR display_on='' OR display_on IS NULL)")
|
11
|
+
execute("UPDATE spree_payment_methods "\
|
12
|
+
"SET available_to_admin=#{quoted_false} "\
|
13
|
+
"WHERE NOT (display_on='back_end' OR display_on='' OR display_on IS NULL)")
|
14
|
+
remove_column(:spree_payment_methods, :display_on)
|
15
|
+
end
|
16
|
+
|
17
|
+
def down
|
18
|
+
add_column(:spree_payment_methods, :display_on, :string)
|
19
|
+
execute("UPDATE spree_payment_methods "\
|
20
|
+
"SET display_on='' "\
|
21
|
+
"WHERE (available_to_users=#{quoted_true} AND available_to_admin=#{quoted_true})")
|
22
|
+
execute("UPDATE spree_payment_methods "\
|
23
|
+
"SET display_on='front_end' "\
|
24
|
+
"WHERE (available_to_users=#{quoted_true} AND NOT available_to_admin=#{quoted_true})")
|
25
|
+
execute("UPDATE spree_payment_methods "\
|
26
|
+
"SET display_on='back_end' "\
|
27
|
+
"WHERE (available_to_admin=#{quoted_true} AND NOT available_to_users=#{quoted_true})")
|
28
|
+
remove_column(:spree_payment_methods, :available_to_users)
|
29
|
+
remove_column(:spree_payment_methods, :available_to_admin)
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This migration comes from spree (originally 20161017102621)
|
3
|
+
|
4
|
+
class CreateSpreePromotionCodeBatch < ActiveRecord::Migration[5.0]
|
5
|
+
def change
|
6
|
+
create_table :spree_promotion_code_batches do |t|
|
7
|
+
t.references :promotion, null: false, index: true
|
8
|
+
t.string :base_code, null: false
|
9
|
+
t.integer :number_of_codes, null: false
|
10
|
+
t.string :email
|
11
|
+
t.string :error
|
12
|
+
t.string :state, default: "pending"
|
13
|
+
t.timestamps precision: 6
|
14
|
+
end
|
15
|
+
|
16
|
+
add_foreign_key(
|
17
|
+
:spree_promotion_code_batches,
|
18
|
+
:spree_promotions,
|
19
|
+
column: :promotion_id
|
20
|
+
)
|
21
|
+
|
22
|
+
add_column(
|
23
|
+
:spree_promotion_codes,
|
24
|
+
:promotion_code_batch_id,
|
25
|
+
:integer
|
26
|
+
)
|
27
|
+
|
28
|
+
add_foreign_key(
|
29
|
+
:spree_promotion_codes,
|
30
|
+
:spree_promotion_code_batches,
|
31
|
+
column: :promotion_code_batch_id
|
32
|
+
)
|
33
|
+
|
34
|
+
add_index(
|
35
|
+
:spree_promotion_codes,
|
36
|
+
:promotion_code_batch_id
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This migration comes from spree (originally 20161123154034)
|
3
|
+
|
4
|
+
class AddAvailableToUsersAndRemoveDisplayOnFromShippingMethods < ActiveRecord::Migration[5.0]
|
5
|
+
def up
|
6
|
+
add_column(:spree_shipping_methods, :available_to_users, :boolean, default: true)
|
7
|
+
execute("UPDATE spree_shipping_methods "\
|
8
|
+
"SET available_to_users=#{quoted_false} "\
|
9
|
+
"WHERE display_on='back_end'")
|
10
|
+
remove_column(:spree_shipping_methods, :display_on)
|
11
|
+
end
|
12
|
+
|
13
|
+
def down
|
14
|
+
add_column(:spree_shipping_methods, :display_on, :string)
|
15
|
+
execute("UPDATE spree_shipping_methods "\
|
16
|
+
"SET display_on='both' "\
|
17
|
+
"WHERE (available_to_users=#{quoted_true})")
|
18
|
+
execute("UPDATE spree_shipping_methods "\
|
19
|
+
"SET display_on='back_end' "\
|
20
|
+
"WHERE (available_to_users=#{quoted_false})")
|
21
|
+
remove_column(:spree_shipping_methods, :available_to_users)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This migration comes from spree (originally 20170319191942)
|
3
|
+
|
4
|
+
class RemoveOrderIdFromInventoryUnits < ActiveRecord::Migration[5.0]
|
5
|
+
class InconsistentInventoryUnitError < StandardError; end
|
6
|
+
|
7
|
+
class InventoryUnit < ActiveRecord::Base
|
8
|
+
self.table_name = "spree_inventory_units"
|
9
|
+
belongs_to :shipment
|
10
|
+
end
|
11
|
+
|
12
|
+
class Shipment < ActiveRecord::Base
|
13
|
+
self.table_name = "spree_shipments"
|
14
|
+
has_many :inventory_units
|
15
|
+
end
|
16
|
+
|
17
|
+
def up
|
18
|
+
if InventoryUnit.
|
19
|
+
joins(:shipment).
|
20
|
+
where.not(
|
21
|
+
'spree_inventory_units.order_id = spree_shipments.order_id'
|
22
|
+
).exists?
|
23
|
+
raise InconsistentInventoryUnitError, "You have inventory units with inconsistent order references. Please fix those before running this migration"
|
24
|
+
end
|
25
|
+
remove_column :spree_inventory_units, :order_id
|
26
|
+
end
|
27
|
+
|
28
|
+
def down
|
29
|
+
add_reference :spree_inventory_units, :order, index: true
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This migration comes from spree (originally 20170412103617)
|
3
|
+
|
4
|
+
class TransformTaxRateCategoryRelation < ActiveRecord::Migration[5.0]
|
5
|
+
class TaxRate < ActiveRecord::Base
|
6
|
+
self.table_name = "spree_tax_rates"
|
7
|
+
end
|
8
|
+
|
9
|
+
class TaxRateTaxCategory < ActiveRecord::Base
|
10
|
+
self.table_name = "spree_tax_rate_tax_categories"
|
11
|
+
end
|
12
|
+
|
13
|
+
def up
|
14
|
+
create_table :spree_tax_rate_tax_categories do |t|
|
15
|
+
t.integer :tax_category_id, index: true, null: false
|
16
|
+
t.integer :tax_rate_id, index: true, null: false
|
17
|
+
end
|
18
|
+
|
19
|
+
add_foreign_key :spree_tax_rate_tax_categories, :spree_tax_categories, column: :tax_category_id
|
20
|
+
add_foreign_key :spree_tax_rate_tax_categories, :spree_tax_rates, column: :tax_rate_id
|
21
|
+
|
22
|
+
TaxRate.where.not(tax_category_id: nil).find_each do |tax_rate|
|
23
|
+
TaxRateTaxCategory.create!(
|
24
|
+
tax_rate_id: tax_rate.id,
|
25
|
+
tax_category_id: tax_rate.tax_category_id
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
remove_column :spree_tax_rates, :tax_category_id
|
30
|
+
end
|
31
|
+
|
32
|
+
def down
|
33
|
+
add_column :spree_tax_rates, :tax_category_id, :integer, index: true
|
34
|
+
add_foreign_key :spree_tax_rates, :spree_tax_categories, column: :tax_category_id
|
35
|
+
|
36
|
+
TaxRate.find_each do |tax_rate|
|
37
|
+
tax_category_ids = TaxRateTaxCategory.where(tax_rate_id: tax_rate.id).pluck(:tax_category_id)
|
38
|
+
|
39
|
+
tax_category_ids.each_with_index do |category_id, i|
|
40
|
+
if i.zero?
|
41
|
+
tax_rate.update!(tax_category_id: category_id)
|
42
|
+
else
|
43
|
+
new_tax_rate = tax_rate.dup
|
44
|
+
new_tax_rate.update!(tax_category_id: category_id)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
drop_table :spree_tax_rate_tax_categories
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This migration comes from spree (originally 20170422134804)
|
3
|
+
|
4
|
+
class AddRolesUniqueConstraints < ActiveRecord::Migration[5.0]
|
5
|
+
def change
|
6
|
+
add_index :spree_roles, :name, unique: true
|
7
|
+
add_index :spree_roles_users, [:user_id, :role_id], unique: true
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This migration comes from spree (originally 20170522143442)
|
3
|
+
|
4
|
+
class AddTimeRangeToTaxRate < ActiveRecord::Migration[5.0]
|
5
|
+
def change
|
6
|
+
add_column :spree_tax_rates, :starts_at, :datetime
|
7
|
+
add_column :spree_tax_rates, :expires_at, :datetime
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This migration comes from spree (originally 20170608074534)
|
3
|
+
|
4
|
+
class RenameBogusGateways < ActiveRecord::Migration[5.0]
|
5
|
+
# This migration was only performing a data migration useful updating to
|
6
|
+
# Solidus v2.3.
|
7
|
+
# Once the update is done, this is no more required to run so we can clean
|
8
|
+
# this file to just be a noop.
|
9
|
+
# For more info on the original content see:
|
10
|
+
# https://github.com/solidusio/solidus/pull/2001
|
11
|
+
|
12
|
+
def up
|
13
|
+
# no-op
|
14
|
+
end
|
15
|
+
|
16
|
+
def down
|
17
|
+
# no-op
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This migration comes from spree (originally 20180202190713)
|
3
|
+
|
4
|
+
class CreatePromotionRuleStores < ActiveRecord::Migration[5.1]
|
5
|
+
def change
|
6
|
+
create_table :spree_promotion_rules_stores do |t|
|
7
|
+
t.references :store, null: false
|
8
|
+
t.references :promotion_rule, null: false
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This migration comes from spree (originally 20180202222641)
|
3
|
+
|
4
|
+
class CreateStoreShippingMethods < ActiveRecord::Migration[5.1]
|
5
|
+
def change
|
6
|
+
create_table :spree_store_shipping_methods do |t|
|
7
|
+
t.references :store, null: false
|
8
|
+
t.references :shipping_method, null: false
|
9
|
+
|
10
|
+
t.timestamps precision: 6
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This migration comes from spree (originally 20180313220213)
|
3
|
+
|
4
|
+
class AddAvailableLocalesToStores < ActiveRecord::Migration[5.1]
|
5
|
+
def change
|
6
|
+
change_table :spree_stores do |t|
|
7
|
+
t.column :available_locales, :string
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/spec/dummy/db/migrate/20190822070941_add_amount_remaining_to_store_credit_events.spree.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This migration comes from spree (originally 20180322142651)
|
3
|
+
|
4
|
+
class AddAmountRemainingToStoreCreditEvents < ActiveRecord::Migration[5.0]
|
5
|
+
class StoreCredit < ActiveRecord::Base
|
6
|
+
self.table_name = 'spree_store_credits'
|
7
|
+
has_many :store_credit_events
|
8
|
+
|
9
|
+
VOID_ACTION = 'void'
|
10
|
+
CREDIT_ACTION = 'credit'
|
11
|
+
CAPTURE_ACTION = 'capture'
|
12
|
+
ELIGIBLE_ACTION = 'eligible'
|
13
|
+
AUTHORIZE_ACTION = 'authorize'
|
14
|
+
ALLOCATION_ACTION = 'allocation'
|
15
|
+
ADJUSTMENT_ACTION = 'adjustment'
|
16
|
+
INVALIDATE_ACTION = 'invalidate'
|
17
|
+
end
|
18
|
+
|
19
|
+
class StoreCreditEvent < ActiveRecord::Base
|
20
|
+
self.table_name = "spree_store_credit_events"
|
21
|
+
belongs_to :store_credit
|
22
|
+
|
23
|
+
scope :chronological, -> { order(:created_at) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def up
|
27
|
+
add_column :spree_store_credit_events, :amount_remaining, :decimal, precision: 8, scale: 2, default: nil, null: true
|
28
|
+
|
29
|
+
StoreCredit.includes(:store_credit_events).find_each do |credit|
|
30
|
+
credit_amount = credit.amount
|
31
|
+
|
32
|
+
credit.store_credit_events.chronological.each do |event|
|
33
|
+
case event.action
|
34
|
+
when StoreCredit::ALLOCATION_ACTION,
|
35
|
+
StoreCredit::ELIGIBLE_ACTION,
|
36
|
+
StoreCredit::CAPTURE_ACTION
|
37
|
+
# These actions do not change the amount_remaining so the previous
|
38
|
+
# amount available is used (either the credit's amount or the
|
39
|
+
# amount_remaining coming from the event right before this one).
|
40
|
+
credit_amount
|
41
|
+
when StoreCredit::AUTHORIZE_ACTION,
|
42
|
+
StoreCredit::INVALIDATE_ACTION
|
43
|
+
# These actions remove the amount from the available credit amount.
|
44
|
+
credit_amount -= event.amount
|
45
|
+
when StoreCredit::ADJUSTMENT_ACTION,
|
46
|
+
StoreCredit::CREDIT_ACTION,
|
47
|
+
StoreCredit::VOID_ACTION
|
48
|
+
# These actions add the amount to the available credit amount. For
|
49
|
+
# ADJUSTMENT_ACTION the event's amount could be negative (so it could
|
50
|
+
# end up subtracting the amount).
|
51
|
+
credit_amount += event.amount
|
52
|
+
end
|
53
|
+
|
54
|
+
event.update_attribute(:amount_remaining, credit_amount)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def down
|
60
|
+
remove_column :spree_store_credit_events, :amount_remaining
|
61
|
+
end
|
62
|
+
end
|