solidus_drip 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +26 -0
  3. data/README.md +55 -0
  4. data/Rakefile +32 -0
  5. data/app/assets/javascripts/spree/frontend/solidus_drip.js.erb +11 -0
  6. data/app/decorators/models/solidus_drip/spree/order_decorator.rb +47 -0
  7. data/app/decorators/models/solidus_drip/spree/variant_decorator.rb +25 -0
  8. data/config/initializers/default_host.rb +9 -0
  9. data/config/initializers/update_hooks.rb +3 -0
  10. data/config/locales/en.yml +5 -0
  11. data/config/routes.rb +5 -0
  12. data/lib/generators/solidus_drip/install/install_generator.rb +28 -0
  13. data/lib/solidus_drip.rb +9 -0
  14. data/lib/solidus_drip/base.rb +31 -0
  15. data/lib/solidus_drip/engine.rb +22 -0
  16. data/lib/solidus_drip/factories.rb +8 -0
  17. data/lib/solidus_drip/shopper_activity.rb +6 -0
  18. data/lib/solidus_drip/shopper_activity/order.rb +138 -0
  19. data/lib/solidus_drip/shopper_activity/product.rb +54 -0
  20. data/lib/solidus_drip/version.rb +5 -0
  21. data/spec/dummy/README.md +24 -0
  22. data/spec/dummy/Rakefile +6 -0
  23. data/spec/dummy/app/assets/config/manifest.js +2 -0
  24. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  25. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  26. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  27. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  28. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  29. data/spec/dummy/app/javascript/channels/consumer.js +6 -0
  30. data/spec/dummy/app/javascript/channels/index.js +5 -0
  31. data/spec/dummy/app/javascript/packs/application.js +17 -0
  32. data/spec/dummy/app/jobs/application_job.rb +7 -0
  33. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  34. data/spec/dummy/app/models/application_record.rb +3 -0
  35. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  36. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  37. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  38. data/spec/dummy/bin/rails +4 -0
  39. data/spec/dummy/bin/rake +4 -0
  40. data/spec/dummy/bin/setup +36 -0
  41. data/spec/dummy/bin/yarn +11 -0
  42. data/spec/dummy/config.ru +5 -0
  43. data/spec/dummy/config/application.rb +59 -0
  44. data/spec/dummy/config/boot.rb +6 -0
  45. data/spec/dummy/config/cable.yml +10 -0
  46. data/spec/dummy/config/credentials.yml.enc +1 -0
  47. data/spec/dummy/config/database.yml +12 -0
  48. data/spec/dummy/config/environment.rb +5 -0
  49. data/spec/dummy/config/environments/development.rb +62 -0
  50. data/spec/dummy/config/environments/production.rb +112 -0
  51. data/spec/dummy/config/environments/test.rb +33 -0
  52. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  53. data/spec/dummy/config/initializers/assets.rb +14 -0
  54. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  55. data/spec/dummy/config/initializers/content_security_policy.rb +30 -0
  56. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  57. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  58. data/spec/dummy/config/initializers/inflections.rb +16 -0
  59. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  60. data/spec/dummy/config/initializers/spree.rb +71 -0
  61. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  62. data/spec/dummy/config/locales/en.yml +33 -0
  63. data/spec/dummy/config/master.key +1 -0
  64. data/spec/dummy/config/routes.rb +9 -0
  65. data/spec/dummy/config/storage.yml +34 -0
  66. data/spec/dummy/db/migrate/20191101230305_create_active_storage_tables.active_storage.rb +27 -0
  67. data/spec/dummy/db/migrate/20191101230306_create_action_mailbox_tables.action_mailbox.rb +14 -0
  68. data/spec/dummy/db/migrate/20191101230307_create_action_text_tables.action_text.rb +14 -0
  69. data/spec/dummy/db/migrate/20191101230308_solidus_one_four.spree.rb +1103 -0
  70. data/spec/dummy/db/migrate/20191101230309_create_spree_wallet_payment_sources.spree.rb +28 -0
  71. data/spec/dummy/db/migrate/20191101230310_migrate_credit_cards_to_wallet_payment_sources.spree.rb +30 -0
  72. data/spec/dummy/db/migrate/20191101230311_remove_is_default_from_prices.spree.rb +8 -0
  73. data/spec/dummy/db/migrate/20191101230312_remove_currency_from_line_items.spree.rb +8 -0
  74. data/spec/dummy/db/migrate/20191101230313_add_available_to_columns_and_remove_display_on_from_payment_methods.spree.rb +31 -0
  75. data/spec/dummy/db/migrate/20191101230314_create_spree_promotion_code_batch.spree.rb +39 -0
  76. data/spec/dummy/db/migrate/20191101230315_add_available_to_users_and_remove_display_on_from_shipping_methods.spree.rb +23 -0
  77. data/spec/dummy/db/migrate/20191101230316_add_index_to_spree_payments_number.spree.rb +8 -0
  78. data/spec/dummy/db/migrate/20191101230317_remove_spree_store_credits_column.spree.rb +8 -0
  79. data/spec/dummy/db/migrate/20191101230318_add_lft_and_rgt_indexes_to_taxons.spree.rb +9 -0
  80. data/spec/dummy/db/migrate/20191101230319_remove_order_id_from_inventory_units.spree.rb +31 -0
  81. data/spec/dummy/db/migrate/20191101230320_transform_tax_rate_category_relation.spree.rb +51 -0
  82. data/spec/dummy/db/migrate/20191101230321_add_roles_unique_constraints.spree.rb +9 -0
  83. data/spec/dummy/db/migrate/20191101230322_add_time_range_to_tax_rate.spree.rb +9 -0
  84. data/spec/dummy/db/migrate/20191101230323_rename_bogus_gateways.spree.rb +19 -0
  85. data/spec/dummy/db/migrate/20191101230324_remove_default_tax_from_spree_zones.spree.rb +8 -0
  86. data/spec/dummy/db/migrate/20191101230325_create_promotion_rule_stores.spree.rb +13 -0
  87. data/spec/dummy/db/migrate/20191101230326_create_store_shipping_methods.spree.rb +13 -0
  88. data/spec/dummy/db/migrate/20191101230327_add_available_locales_to_stores.spree.rb +10 -0
  89. data/spec/dummy/db/migrate/20191101230328_add_amount_remaining_to_store_credit_events.spree.rb +62 -0
  90. data/spec/dummy/db/migrate/20191101230329_add_join_characters_to_promotion_code_batch.spree.rb +12 -0
  91. data/spec/dummy/db/migrate/20191101230330_create_spree_store_credit_reasons_table.spree.rb +56 -0
  92. data/spec/dummy/db/migrate/20191101230331_remove_code_from_spree_promotions.spree.rb +43 -0
  93. data/spec/dummy/db/migrate/20191101230332_drop_spree_store_credit_update_reasons.spree.rb +20 -0
  94. data/spec/dummy/db/migrate/20191101230333_add_api_key_to_spree_users.spree_api.rb +10 -0
  95. data/spec/dummy/db/migrate/20191101230334_resize_api_key_field.spree_api.rb +10 -0
  96. data/spec/dummy/db/migrate/20191101230335_rename_api_key_to_spree_api_key.spree_api.rb +10 -0
  97. data/spec/dummy/db/migrate/20191101230336_add_index_to_user_spree_api_key.spree_api.rb +10 -0
  98. data/spec/dummy/db/migrate/20191101230337_create_users.solidus_auth.rb +32 -0
  99. data/spec/dummy/db/migrate/20191101230338_rename_columns_for_devise.solidus_auth.rb +40 -0
  100. data/spec/dummy/db/migrate/20191101230339_convert_user_remember_field.solidus_auth.rb +14 -0
  101. data/spec/dummy/db/migrate/20191101230340_add_reset_password_sent_at_to_spree_users.solidus_auth.rb +11 -0
  102. data/spec/dummy/db/migrate/20191101230341_make_users_email_index_unique.solidus_auth.rb +12 -0
  103. data/spec/dummy/db/migrate/20191101230342_add_deleted_at_to_users.solidus_auth.rb +9 -0
  104. data/spec/dummy/db/migrate/20191101230343_add_confirmable_to_users.solidus_auth.rb +10 -0
  105. data/spec/dummy/db/migrate/20191101230344_add_reset_password_token_index_to_spree_users.solidus_auth.rb +35 -0
  106. data/spec/dummy/db/schema.rb +1211 -0
  107. data/spec/dummy/db/seeds.rb +10 -0
  108. data/spec/dummy/db/solidus_test.sqlite3 +0 -0
  109. data/spec/dummy/log/test.log +12695 -0
  110. data/spec/dummy/package.json +11 -0
  111. data/spec/dummy/public/404.html +67 -0
  112. data/spec/dummy/public/422.html +67 -0
  113. data/spec/dummy/public/500.html +66 -0
  114. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  115. data/spec/dummy/public/apple-touch-icon.png +0 -0
  116. data/spec/dummy/public/favicon.ico +0 -0
  117. data/spec/dummy/tmp/development_secret.txt +1 -0
  118. data/spec/dummy/vendor/assets/javascripts/spree/backend/all.js +11 -0
  119. data/spec/dummy/vendor/assets/javascripts/spree/frontend/all.js +11 -0
  120. data/spec/dummy/vendor/assets/stylesheets/spree/backend/all.css +10 -0
  121. data/spec/dummy/vendor/assets/stylesheets/spree/frontend/all.css +10 -0
  122. data/spec/models/order_spec.rb +45 -0
  123. data/spec/models/variant_spec.rb +27 -0
  124. data/spec/spec_helper.rb +34 -0
  125. data/spec/support/stub_drip_responses.rb +13 -0
  126. metadata +495 -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
@@ -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,8 @@
1
+ # frozen_string_literal: true
2
+ # This migration comes from spree (originally 20160924135758)
3
+
4
+ class RemoveIsDefaultFromPrices < ActiveRecord::Migration[5.0]
5
+ def change
6
+ remove_column :spree_prices, :is_default, :boolean, default: true
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ # This migration comes from spree (originally 20161009141333)
3
+
4
+ class RemoveCurrencyFromLineItems < ActiveRecord::Migration[5.0]
5
+ def change
6
+ remove_column :spree_line_items, :currency, :string
7
+ end
8
+ 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,8 @@
1
+ # frozen_string_literal: true
2
+ # This migration comes from spree (originally 20161129035810)
3
+
4
+ class AddIndexToSpreePaymentsNumber < ActiveRecord::Migration[5.0]
5
+ def change
6
+ add_index 'spree_payments', ['number'], unique: true
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ # This migration comes from spree (originally 20170223235001)
3
+
4
+ class RemoveSpreeStoreCreditsColumn < ActiveRecord::Migration[5.0]
5
+ def change
6
+ remove_column :spree_store_credits, :spree_store_credits, :datetime
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ # This migration comes from spree (originally 20170317035819)
3
+
4
+ class AddLftAndRgtIndexesToTaxons < ActiveRecord::Migration[5.0]
5
+ def change
6
+ add_index :spree_taxons, :lft
7
+ add_index :spree_taxons, :rgt
8
+ end
9
+ 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,8 @@
1
+ # frozen_string_literal: true
2
+ # This migration comes from spree (originally 20170831201542)
3
+
4
+ class RemoveDefaultTaxFromSpreeZones < ActiveRecord::Migration[5.1]
5
+ def change
6
+ remove_column :spree_zones, :default_tax, :boolean, default: false
7
+ end
8
+ 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
@@ -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