solidus_friendly_promotions 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +61 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +1 -0
  5. data/.github_changelog_generator +2 -0
  6. data/.gitignore +21 -0
  7. data/.rspec +2 -0
  8. data/.rubocop.yml +29 -0
  9. data/.rubocop_todo.yml +157 -0
  10. data/.standard.yml +4 -0
  11. data/CHANGELOG.md +1 -0
  12. data/Gemfile +42 -0
  13. data/LICENSE +26 -0
  14. data/MIGRATING.md +134 -0
  15. data/README.md +144 -0
  16. data/Rakefile +7 -0
  17. data/app/assets/config/solidus_friendly_promotions/manifest.js +7 -0
  18. data/app/controllers/solidus_friendly_promotions/admin/base_controller.rb +54 -0
  19. data/app/controllers/solidus_friendly_promotions/admin/promotion_actions_controller.rb +103 -0
  20. data/app/controllers/solidus_friendly_promotions/admin/promotion_categories_controller.rb +13 -0
  21. data/app/controllers/solidus_friendly_promotions/admin/promotion_code_batches_controller.rb +30 -0
  22. data/app/controllers/solidus_friendly_promotions/admin/promotion_codes_controller.rb +58 -0
  23. data/app/controllers/solidus_friendly_promotions/admin/promotion_rules_controller.rb +105 -0
  24. data/app/controllers/solidus_friendly_promotions/admin/promotions_controller.rb +64 -0
  25. data/app/decorators/models/solidus_friendly_promotions/adjustment_decorator.rb +26 -0
  26. data/app/decorators/models/solidus_friendly_promotions/line_item_decorator.rb +7 -0
  27. data/app/decorators/models/solidus_friendly_promotions/order_decorator.rb +42 -0
  28. data/app/decorators/models/solidus_friendly_promotions/order_recalculator_decorator.rb +13 -0
  29. data/app/decorators/models/solidus_friendly_promotions/shipment_decorator.rb +14 -0
  30. data/app/decorators/models/solidus_friendly_promotions/shipping_rate_decorator.rb +29 -0
  31. data/app/helpers/solidus_friendly_promotions/admin/promotion_actions_helper.rb +23 -0
  32. data/app/helpers/solidus_friendly_promotions/admin/promotion_rules_helper.rb +25 -0
  33. data/app/javascript/solidus_friendly_promotions/controllers/application.js +9 -0
  34. data/app/javascript/solidus_friendly_promotions/controllers/calculator_tiers_controller.js +37 -0
  35. data/app/javascript/solidus_friendly_promotions/controllers/flash_controller.js +10 -0
  36. data/app/javascript/solidus_friendly_promotions/controllers/index.js +8 -0
  37. data/app/javascript/solidus_friendly_promotions/controllers/product_option_values_controller.js +62 -0
  38. data/app/javascript/solidus_friendly_promotions/jquery/option_value_picker.js +44 -0
  39. data/app/javascript/solidus_friendly_promotions.js +12 -0
  40. data/app/jobs/solidus_friendly_promotions/promotion_code_batch_job.rb +26 -0
  41. data/app/mailers/solidus_friendly_promotions/promotion_code_batch_mailer.rb +15 -0
  42. data/app/models/concerns/solidus_friendly_promotions/discountable_amount.rb +21 -0
  43. data/app/models/concerns/solidus_friendly_promotions/rules/line_item_applicable_order_rule.rb +23 -0
  44. data/app/models/concerns/solidus_friendly_promotions/rules/line_item_level_rule.rb +15 -0
  45. data/app/models/concerns/solidus_friendly_promotions/rules/order_level_rule.rb +15 -0
  46. data/app/models/concerns/solidus_friendly_promotions/rules/shipment_level_rule.rb +15 -0
  47. data/app/models/solidus_friendly_promotions/actions/adjust_line_item.rb +15 -0
  48. data/app/models/solidus_friendly_promotions/actions/adjust_line_item_quantity_groups.rb +116 -0
  49. data/app/models/solidus_friendly_promotions/actions/adjust_shipment.rb +15 -0
  50. data/app/models/solidus_friendly_promotions/calculators/distributed_amount.rb +37 -0
  51. data/app/models/solidus_friendly_promotions/calculators/flat_rate.rb +21 -0
  52. data/app/models/solidus_friendly_promotions/calculators/flexi_rate.rb +24 -0
  53. data/app/models/solidus_friendly_promotions/calculators/percent.rb +17 -0
  54. data/app/models/solidus_friendly_promotions/calculators/tiered_flat_rate.rb +56 -0
  55. data/app/models/solidus_friendly_promotions/calculators/tiered_percent.rb +66 -0
  56. data/app/models/solidus_friendly_promotions/distributed_amounts_handler.rb +43 -0
  57. data/app/models/solidus_friendly_promotions/eligibility_result.rb +5 -0
  58. data/app/models/solidus_friendly_promotions/eligibility_results.rb +48 -0
  59. data/app/models/solidus_friendly_promotions/friendly_promotion_adjuster/choose_discounts.rb +21 -0
  60. data/app/models/solidus_friendly_promotions/friendly_promotion_adjuster/discount_order.rb +76 -0
  61. data/app/models/solidus_friendly_promotions/friendly_promotion_adjuster/load_promotions.rb +54 -0
  62. data/app/models/solidus_friendly_promotions/friendly_promotion_adjuster/persist_discounted_order.rb +81 -0
  63. data/app/models/solidus_friendly_promotions/friendly_promotion_adjuster.rb +25 -0
  64. data/app/models/solidus_friendly_promotions/item_discount.rb +21 -0
  65. data/app/models/solidus_friendly_promotions/migration_support/order_promotion_syncer.rb +54 -0
  66. data/app/models/solidus_friendly_promotions/order_promotion.rb +23 -0
  67. data/app/models/solidus_friendly_promotions/permission_sets/friendly_promotion_management.rb +15 -0
  68. data/app/models/solidus_friendly_promotions/products_promotion_rule.rb +8 -0
  69. data/app/models/solidus_friendly_promotions/promotion.rb +166 -0
  70. data/app/models/solidus_friendly_promotions/promotion_action.rb +73 -0
  71. data/app/models/solidus_friendly_promotions/promotion_category.rb +9 -0
  72. data/app/models/solidus_friendly_promotions/promotion_code/batch_builder.rb +72 -0
  73. data/app/models/solidus_friendly_promotions/promotion_code.rb +55 -0
  74. data/app/models/solidus_friendly_promotions/promotion_code_batch.rb +25 -0
  75. data/app/models/solidus_friendly_promotions/promotion_handler/coupon.rb +113 -0
  76. data/app/models/solidus_friendly_promotions/promotion_handler/page.rb +30 -0
  77. data/app/models/solidus_friendly_promotions/promotion_rule.rb +55 -0
  78. data/app/models/solidus_friendly_promotions/promotion_rules_store.rb +8 -0
  79. data/app/models/solidus_friendly_promotions/promotion_rules_taxon.rb +8 -0
  80. data/app/models/solidus_friendly_promotions/promotion_rules_user.rb +8 -0
  81. data/app/models/solidus_friendly_promotions/rules/discounted_item_total.rb +22 -0
  82. data/app/models/solidus_friendly_promotions/rules/first_order.rb +31 -0
  83. data/app/models/solidus_friendly_promotions/rules/first_repeat_purchase_since.rb +31 -0
  84. data/app/models/solidus_friendly_promotions/rules/item_total.rb +86 -0
  85. data/app/models/solidus_friendly_promotions/rules/line_item_option_value.rb +37 -0
  86. data/app/models/solidus_friendly_promotions/rules/line_item_product.rb +52 -0
  87. data/app/models/solidus_friendly_promotions/rules/line_item_taxon.rb +55 -0
  88. data/app/models/solidus_friendly_promotions/rules/minimum_quantity.rb +48 -0
  89. data/app/models/solidus_friendly_promotions/rules/nth_order.rb +40 -0
  90. data/app/models/solidus_friendly_promotions/rules/one_use_per_user.rb +25 -0
  91. data/app/models/solidus_friendly_promotions/rules/option_value.rb +28 -0
  92. data/app/models/solidus_friendly_promotions/rules/product.rb +85 -0
  93. data/app/models/solidus_friendly_promotions/rules/shipping_method.rb +19 -0
  94. data/app/models/solidus_friendly_promotions/rules/store.rb +26 -0
  95. data/app/models/solidus_friendly_promotions/rules/taxon.rb +98 -0
  96. data/app/models/solidus_friendly_promotions/rules/user.rb +35 -0
  97. data/app/models/solidus_friendly_promotions/rules/user_logged_in.rb +16 -0
  98. data/app/models/solidus_friendly_promotions/rules/user_role.rb +42 -0
  99. data/app/models/solidus_friendly_promotions/shipping_rate_discount.rb +11 -0
  100. data/app/models/solidus_friendly_promotions/simple_order_contents.rb +27 -0
  101. data/app/models/solidus_friendly_promotions.rb +7 -0
  102. data/app/views/solidus_friendly_promotions/admin/promotion_actions/_calculator_select.html.erb +16 -0
  103. data/app/views/solidus_friendly_promotions/admin/promotion_actions/_form.html.erb +3 -0
  104. data/app/views/solidus_friendly_promotions/admin/promotion_actions/_promotion_action.html.erb +29 -0
  105. data/app/views/solidus_friendly_promotions/admin/promotion_actions/_type_select.html.erb +14 -0
  106. data/app/views/solidus_friendly_promotions/admin/promotion_actions/actions/_adjust_line_item.html.erb +6 -0
  107. data/app/views/solidus_friendly_promotions/admin/promotion_actions/actions/_adjust_line_item_quantity_groups.html.erb +13 -0
  108. data/app/views/solidus_friendly_promotions/admin/promotion_actions/actions/_adjust_shipment.html.erb +6 -0
  109. data/app/views/solidus_friendly_promotions/admin/promotion_actions/actions/_calculator_fields.erb +8 -0
  110. data/app/views/solidus_friendly_promotions/admin/promotion_actions/calculators/_default_fields.html.erb +6 -0
  111. data/app/views/solidus_friendly_promotions/admin/promotion_actions/calculators/distributed_amount/_fields.html.erb +56 -0
  112. data/app/views/solidus_friendly_promotions/admin/promotion_actions/calculators/flat_rate/_fields.html.erb +6 -0
  113. data/app/views/solidus_friendly_promotions/admin/promotion_actions/calculators/tiered_flat_rate/_fields.html.erb +34 -0
  114. data/app/views/solidus_friendly_promotions/admin/promotion_actions/calculators/tiered_flat_rate/_tier_fields.html.erb +32 -0
  115. data/app/views/solidus_friendly_promotions/admin/promotion_actions/calculators/tiered_percent/_fields.html.erb +34 -0
  116. data/app/views/solidus_friendly_promotions/admin/promotion_actions/calculators/tiered_percent/_tier_fields.html.erb +32 -0
  117. data/app/views/solidus_friendly_promotions/admin/promotion_actions/edit.html.erb +23 -0
  118. data/app/views/solidus_friendly_promotions/admin/promotion_actions/new.html.erb +26 -0
  119. data/app/views/solidus_friendly_promotions/admin/promotion_categories/_form.html.erb +14 -0
  120. data/app/views/solidus_friendly_promotions/admin/promotion_categories/edit.html.erb +10 -0
  121. data/app/views/solidus_friendly_promotions/admin/promotion_categories/index.html.erb +47 -0
  122. data/app/views/solidus_friendly_promotions/admin/promotion_categories/new.html.erb +10 -0
  123. data/app/views/solidus_friendly_promotions/admin/promotion_codes/index.csv.ruby +8 -0
  124. data/app/views/solidus_friendly_promotions/admin/promotion_codes/index.html.erb +32 -0
  125. data/app/views/solidus_friendly_promotions/admin/promotion_codes/new.html.erb +31 -0
  126. data/app/views/solidus_friendly_promotions/admin/promotion_rules/_promotion_rule.html.erb +22 -0
  127. data/app/views/solidus_friendly_promotions/admin/promotion_rules/_type_select.html.erb +20 -0
  128. data/app/views/solidus_friendly_promotions/admin/promotion_rules/new.html.erb +24 -0
  129. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_first_order.html.erb +3 -0
  130. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_first_repeat_purchase_since.html.erb +6 -0
  131. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_item_total.html.erb +17 -0
  132. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_line_item_option_value.html.erb +25 -0
  133. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_line_item_product.html.erb +21 -0
  134. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_line_item_taxon.html.erb +17 -0
  135. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_minimum_quantity.html.erb +5 -0
  136. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_nth_order.html.erb +15 -0
  137. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_one_use_per_user.html.erb +3 -0
  138. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_option_value.html.erb +63 -0
  139. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_product.html.erb +44 -0
  140. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_shipping_method.html.erb +10 -0
  141. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_store.html.erb +9 -0
  142. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_taxon.html.erb +44 -0
  143. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_user.html.erb +7 -0
  144. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_user_logged_in.html.erb +3 -0
  145. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_user_role.html.erb +15 -0
  146. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/line_item_option_value/_option_value_fields.html.erb +17 -0
  147. data/app/views/solidus_friendly_promotions/admin/promotions/_activations_edit.html.erb +22 -0
  148. data/app/views/solidus_friendly_promotions/admin/promotions/_activations_new.html.erb +43 -0
  149. data/app/views/solidus_friendly_promotions/admin/promotions/_form.html.erb +96 -0
  150. data/app/views/solidus_friendly_promotions/admin/promotions/edit.html.erb +73 -0
  151. data/app/views/solidus_friendly_promotions/admin/promotions/index.html.erb +124 -0
  152. data/app/views/solidus_friendly_promotions/admin/promotions/new.html.erb +9 -0
  153. data/app/views/solidus_friendly_promotions/admin/shared/_promotion_sub_menu.html.erb +14 -0
  154. data/app/views/solidus_friendly_promotions/promotion_code_batch_mailer/promotion_code_batch_errored.text.erb +2 -0
  155. data/app/views/solidus_friendly_promotions/promotion_code_batch_mailer/promotion_code_batch_finished.text.erb +2 -0
  156. data/bin/console +17 -0
  157. data/bin/importmap +4 -0
  158. data/bin/rails +7 -0
  159. data/bin/rails-engine +13 -0
  160. data/bin/rails-sandbox +16 -0
  161. data/bin/rake +7 -0
  162. data/bin/sandbox +75 -0
  163. data/bin/setup +8 -0
  164. data/config/importmap.rb +12 -0
  165. data/config/initializers/solidus_friendly_promotions.rb +3 -0
  166. data/config/locales/en.yml +255 -0
  167. data/config/routes.rb +18 -0
  168. data/db/migrate/20230703101637_create_promotions.rb +16 -0
  169. data/db/migrate/20230703141116_create_promotion_categories.rb +14 -0
  170. data/db/migrate/20230703143943_create_promotion_rules.rb +12 -0
  171. data/db/migrate/20230704083830_add_rule_tables.rb +31 -0
  172. data/db/migrate/20230704093625_create_promotion_actions.rb +14 -0
  173. data/db/migrate/20230704102444_create_promotion_codes.rb +11 -0
  174. data/db/migrate/20230704102656_create_promotion_code_batches.rb +33 -0
  175. data/db/migrate/20230705171556_create_friendly_order_promotions.rb +11 -0
  176. data/db/migrate/20230725074235_create_shipping_rate_discounts.rb +12 -0
  177. data/db/migrate/20230928093138_add_lane_to_solidus_friendly_promotions_promotions.rb +5 -0
  178. data/db/migrate/20231006134042_add_customer_label_to_promotions.rb +7 -0
  179. data/db/migrate/20231011100059_add_db_comments_to_friendly_order_promotions.rb +61 -0
  180. data/db/migrate/20231011120928_add_db_comments_to_friendly_promotion_rules_taxons.rb +54 -0
  181. data/db/migrate/20231011131324_add_db_comments_to_friendly_promotion_rules.rb +60 -0
  182. data/db/migrate/20231011142040_add_db_comments_to_friendly_promotion_rules_users.rb +53 -0
  183. data/db/migrate/20231011154553_allow_null_promotion_ids.rb +9 -0
  184. data/db/migrate/20231011155822_add_db_comments_to_friendly_promotions.rb +123 -0
  185. data/db/migrate/20231011163030_add_db_comments_to_friendly_promotion_codes.rb +60 -0
  186. data/db/migrate/20231011173312_add_db_comments_to_friendly_promotion_code_batches.rb +91 -0
  187. data/db/migrate/20231011184205_add_db_comments_to_friendly_promotion_rules_stores.rb +53 -0
  188. data/db/migrate/20231011190222_add_db_comments_to_friendly_promotion_actions.rb +68 -0
  189. data/db/migrate/20231012020928_add_db_comments_to_friendly_products_promotion_rules.rb +52 -0
  190. data/db/migrate/20231012120928_add_db_comments_to_friendly_promotion_categories.rb +52 -0
  191. data/db/migrate/20231013181921_add_original_promotion_ids.rb +6 -0
  192. data/lib/generators/solidus_friendly_promotions/install/install_generator.rb +38 -0
  193. data/lib/generators/solidus_friendly_promotions/install/templates/initializer.rb +118 -0
  194. data/lib/solidus_friendly_promotions/configuration.rb +52 -0
  195. data/lib/solidus_friendly_promotions/engine.rb +37 -0
  196. data/lib/solidus_friendly_promotions/migrate_adjustments.rb +62 -0
  197. data/lib/solidus_friendly_promotions/migrate_order_promotions.rb +73 -0
  198. data/lib/solidus_friendly_promotions/nested_class_set.rb +24 -0
  199. data/lib/solidus_friendly_promotions/promotion_map.rb +96 -0
  200. data/lib/solidus_friendly_promotions/promotion_migrator.rb +103 -0
  201. data/lib/solidus_friendly_promotions/testing_support/factories/friendly_order_factory.rb +20 -0
  202. data/lib/solidus_friendly_promotions/testing_support/factories/friendly_order_promotion_factory.rb +8 -0
  203. data/lib/solidus_friendly_promotions/testing_support/factories/friendly_promotion_category_factory.rb +7 -0
  204. data/lib/solidus_friendly_promotions/testing_support/factories/friendly_promotion_code_factory.rb +8 -0
  205. data/lib/solidus_friendly_promotions/testing_support/factories/friendly_promotion_factory.rb +91 -0
  206. data/lib/solidus_friendly_promotions/testing_support/factories/friendly_shipping_rate_discount_factory.rb +14 -0
  207. data/lib/solidus_friendly_promotions/testing_support.rb +9 -0
  208. data/lib/solidus_friendly_promotions/version.rb +5 -0
  209. data/lib/solidus_friendly_promotions.rb +18 -0
  210. data/lib/tasks/solidus_friendly_promotions/migrate_adjustments.rake +17 -0
  211. data/lib/tasks/solidus_friendly_promotions/migrate_existing_promotions.rake +12 -0
  212. data/lib/tasks/solidus_friendly_promotions/migrate_order_promotions.rake +17 -0
  213. data/solidus_friendly_promotions.gemspec +40 -0
  214. metadata +392 -0
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddDbCommentsToFriendlyOrderPromotions < ActiveRecord::Migration[6.1]
4
+ def up
5
+ if connection.supports_comments?
6
+ change_table_comment(:friendly_order_promotions, friendly_order_promotions_table_comment)
7
+ change_column_comment(:friendly_order_promotions, :order_id, order_id_comment)
8
+ change_column_comment(:friendly_order_promotions, :promotion_id, promotion_id_comment)
9
+ change_column_comment(:friendly_order_promotions, :promotion_code_id, promotion_code_id_comment)
10
+ change_column_comment(:friendly_order_promotions, :id, id_comment)
11
+ change_column_comment(:friendly_order_promotions, :created_at, created_at_comment)
12
+ change_column_comment(:friendly_order_promotions, :updated_at, updated_at_comment)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def friendly_order_promotions_table_comment
19
+ <<~COMMENT
20
+ Join table between spree_orders and friendly_promotions. One of two places that record whether a promotion is linked to an order.
21
+ The other place is the spree_adjustments table which records promotion code IDs and could be both eligible and ineligible.
22
+ An entry here is created every time a promotion is linked to an order.
23
+ COMMENT
24
+ end
25
+
26
+ def order_id_comment
27
+ <<~COMMENT
28
+ Foreign key to the spree_orders table.
29
+ COMMENT
30
+ end
31
+
32
+ def promotion_id_comment
33
+ <<~COMMENT
34
+ Foreign key to the friendly_promotions table.
35
+ COMMENT
36
+ end
37
+
38
+ def promotion_code_id_comment
39
+ <<~COMMENT
40
+ Foreign key to the friendly_promotion_codes table. If a promotion code was used, records the promotion code.
41
+ COMMENT
42
+ end
43
+
44
+ def id_comment
45
+ <<~COMMENT
46
+ Primary key of this table.
47
+ COMMENT
48
+ end
49
+
50
+ def created_at_comment
51
+ <<~COMMENT
52
+ Timestamp indicating when this record was created.
53
+ COMMENT
54
+ end
55
+
56
+ def updated_at_comment
57
+ <<~COMMENT
58
+ Timestamp indicating when this record was last updated.
59
+ COMMENT
60
+ end
61
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddDbCommentsToFriendlyPromotionRulesTaxons < ActiveRecord::Migration[6.1]
4
+ def up
5
+ if connection.supports_comments?
6
+ change_table_comment(:friendly_promotion_rules_taxons, friendly_promotion_rules_taxons_table_comment)
7
+ change_column_comment(:friendly_promotion_rules_taxons, :id, id_comment)
8
+ change_column_comment(:friendly_promotion_rules_taxons, :taxon_id, taxon_id_comment)
9
+ change_column_comment(:friendly_promotion_rules_taxons, :promotion_rule_id, promotion_rule_id_comment)
10
+ change_column_comment(:friendly_promotion_rules_taxons, :created_at, created_at_comment)
11
+ change_column_comment(:friendly_promotion_rules_taxons, :updated_at, updated_at_comment)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def friendly_promotion_rules_taxons_table_comment
18
+ <<~COMMENT
19
+ Join table between promotion rules and taxons. Only used if the promotion rule's type is SolidusFriendlyPromotion::Rules::Taxon or
20
+ SolidusFriendlyPromotion::Rules::LineItemTaxon. Represents those taxons that the promotion rule matches on using its any/all/none
21
+ or include/exclude match policy.
22
+ COMMENT
23
+ end
24
+
25
+ def id_comment
26
+ <<~COMMENT
27
+ Primary key of this table.
28
+ COMMENT
29
+ end
30
+
31
+ def taxon_id_comment
32
+ <<~COMMENT
33
+ Foreign key to the taxons table.
34
+ COMMENT
35
+ end
36
+
37
+ def promotion_rule_id_comment
38
+ <<~COMMENT
39
+ Foreign key to the friendly_promotion_rules table.
40
+ COMMENT
41
+ end
42
+
43
+ def created_at_comment
44
+ <<~COMMENT
45
+ Timestamp indicating when this record was created.
46
+ COMMENT
47
+ end
48
+
49
+ def updated_at_comment
50
+ <<~COMMENT
51
+ Timestamp indicating when this record was last updated.
52
+ COMMENT
53
+ end
54
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddDbCommentsToFriendlyPromotionRules < ActiveRecord::Migration[6.1]
4
+ def up
5
+ if connection.supports_comments?
6
+ change_table_comment(:friendly_promotion_rules, friendly_promotion_rules_table_comment)
7
+ change_column_comment(:friendly_promotion_rules, :id, id_comment)
8
+ change_column_comment(:friendly_promotion_rules, :promotion_id, promotion_id_comment)
9
+ change_column_comment(:friendly_promotion_rules, :type, type_comment)
10
+ change_column_comment(:friendly_promotion_rules, :created_at, created_at_comment)
11
+ change_column_comment(:friendly_promotion_rules, :updated_at, updated_at_comment)
12
+ change_column_comment(:friendly_promotion_rules, :preferences, preferences_comment)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def friendly_promotion_rules_table_comment
19
+ <<~COMMENT
20
+ Represents promotion rules. A promotion may have many rules, which determine whether the promotion is eligible.
21
+ All rules must be eligible for the promotion to be eligible. If there are no rules, the promotion is always eligible.
22
+ COMMENT
23
+ end
24
+
25
+ def id_comment
26
+ <<~COMMENT
27
+ Primary key of this table.
28
+ COMMENT
29
+ end
30
+
31
+ def promotion_id_comment
32
+ <<~COMMENT
33
+ Foreign key to the promotions table.
34
+ COMMENT
35
+ end
36
+
37
+ def type_comment
38
+ <<~COMMENT
39
+ STI column. This represents which Ruby class to load when an entry of this table is loaded in Rails.
40
+ COMMENT
41
+ end
42
+
43
+ def created_at_comment
44
+ <<~COMMENT
45
+ Timestamp indicating when this record was created.
46
+ COMMENT
47
+ end
48
+
49
+ def updated_at_comment
50
+ <<~COMMENT
51
+ Timestamp indicating when this record was last updated.
52
+ COMMENT
53
+ end
54
+
55
+ def preferences_comment
56
+ <<~COMMENT
57
+ Preferences for this promotion rule. Serialized YAML column with preferences for this promotion rule.
58
+ COMMENT
59
+ end
60
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddDbCommentsToFriendlyPromotionRulesUsers < ActiveRecord::Migration[6.1]
4
+ def up
5
+ if connection.supports_comments?
6
+ change_table_comment(:friendly_promotion_rules_users, friendly_promotion_rules_users_table_comment)
7
+ change_column_comment(:friendly_promotion_rules_users, :user_id, user_id_comment)
8
+ change_column_comment(:friendly_promotion_rules_users, :promotion_rule_id, promotion_rule_id_comment)
9
+ change_column_comment(:friendly_promotion_rules_users, :id, id_comment)
10
+ change_column_comment(:friendly_promotion_rules_users, :created_at, created_at_comment)
11
+ change_column_comment(:friendly_promotion_rules_users, :updated_at, updated_at_comment)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def friendly_promotion_rules_users_table_comment
18
+ <<~COMMENT
19
+ Join table between promotion rules and users. Used with promotion rules of type "SolidusFriendlyPromotions::Rules::User".
20
+ An entry here indicates that a promotion is eligible for the user ID specified here.
21
+ COMMENT
22
+ end
23
+
24
+ def user_id_comment
25
+ <<~COMMENT
26
+ Foreign key to the users table.
27
+ COMMENT
28
+ end
29
+
30
+ def promotion_rule_id_comment
31
+ <<~COMMENT
32
+ Foreign key to the promotion_rules table.
33
+ COMMENT
34
+ end
35
+
36
+ def id_comment
37
+ <<~COMMENT
38
+ Primary key of this table.
39
+ COMMENT
40
+ end
41
+
42
+ def created_at_comment
43
+ <<~COMMENT
44
+ Timestamp indicating when this record was created.
45
+ COMMENT
46
+ end
47
+
48
+ def updated_at_comment
49
+ <<~COMMENT
50
+ Timestamp indicating when this record was last updated.
51
+ COMMENT
52
+ end
53
+ end
@@ -0,0 +1,9 @@
1
+ class AllowNullPromotionIds < ActiveRecord::Migration[7.0]
2
+ def up
3
+ change_column_null :friendly_promotion_actions, :promotion_id, true
4
+ end
5
+
6
+ def down
7
+ change_column_null :friendly_promotion_actions, :promotion_id, false
8
+ end
9
+ end
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddDbCommentsToFriendlyPromotions < ActiveRecord::Migration[6.1]
4
+ def up
5
+ if connection.supports_comments?
6
+ change_table_comment(:friendly_promotions, friendly_promotions_table_comment)
7
+ change_column_comment(:friendly_promotions, :id, id_comment)
8
+ change_column_comment(:friendly_promotions, :description, description_comment)
9
+ change_column_comment(:friendly_promotions, :expires_at, expires_at_comment)
10
+ change_column_comment(:friendly_promotions, :starts_at, starts_at_comment)
11
+ change_column_comment(:friendly_promotions, :customer_label, customer_label_comment)
12
+ change_column_comment(:friendly_promotions, :usage_limit, usage_limit_comment)
13
+ change_column_comment(:friendly_promotions, :advertise, advertise_comment)
14
+ change_column_comment(:friendly_promotions, :path, path_comment)
15
+ change_column_comment(:friendly_promotions, :lane, lane_comment)
16
+ change_column_comment(:friendly_promotions, :name, name_comment)
17
+ change_column_comment(:friendly_promotions, :created_at, created_at_comment)
18
+ change_column_comment(:friendly_promotions, :updated_at, updated_at_comment)
19
+ change_column_comment(:friendly_promotions, :promotion_category_id, promotion_category_id_comment)
20
+ change_column_comment(:friendly_promotions, :per_code_usage_limit, per_code_usage_limit_comment)
21
+ change_column_comment(:friendly_promotions, :apply_automatically, apply_automatically_comment)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def friendly_promotions_table_comment
28
+ <<~COMMENT
29
+ Promotions are sets of rules and actions to discount (parts of) an order.
30
+ COMMENT
31
+ end
32
+
33
+ def id_comment
34
+ <<~COMMENT
35
+ Primary key of this table.
36
+ COMMENT
37
+ end
38
+
39
+ def description_comment
40
+ <<~COMMENT
41
+ The description of this promotion.
42
+ COMMENT
43
+ end
44
+
45
+ def expires_at_comment
46
+ <<~COMMENT
47
+ Timestamp at which the promotion stops being eligible.
48
+ COMMENT
49
+ end
50
+
51
+ def starts_at_comment
52
+ <<~COMMENT
53
+ Timestamp at which the promotion starts being eligible.
54
+ COMMENT
55
+ end
56
+
57
+ def customer_label_comment
58
+ <<~COMMENT
59
+ The contents of this field will be replicated in the labels of adjustments created with it.
60
+ COMMENT
61
+ end
62
+
63
+ def name_comment
64
+ <<~COMMENT
65
+ Admin name of the promotion.
66
+ COMMENT
67
+ end
68
+
69
+ def usage_limit_comment
70
+ <<~COMMENT
71
+ How many times this promotion can be applied to orders globally.
72
+ COMMENT
73
+ end
74
+
75
+ def advertise_comment
76
+ <<~COMMENT
77
+ Marks a promotion as advertised.
78
+ COMMENT
79
+ end
80
+
81
+ def path_comment
82
+ <<~COMMENT
83
+ This could be used for applying a promotion based on a route the customer visits.
84
+ COMMENT
85
+ end
86
+
87
+ def lane_comment
88
+ <<~COMMENT
89
+ Priority lane of this promotion.
90
+ COMMENT
91
+ end
92
+
93
+ def created_at_comment
94
+ <<~COMMENT
95
+ Timestamp indicating when this record was created.
96
+ COMMENT
97
+ end
98
+
99
+ def updated_at_comment
100
+ <<~COMMENT
101
+ Timestamp indicating when this record was last updated.
102
+ COMMENT
103
+ end
104
+
105
+ def promotion_category_id_comment
106
+ <<~COMMENT
107
+ Foreign key to the friendly_promotion_categories table.
108
+ COMMENT
109
+ end
110
+
111
+ def per_code_usage_limit_comment
112
+ <<~COMMENT
113
+ How many times this promotion can be used per promotion code.
114
+ COMMENT
115
+ end
116
+
117
+ def apply_automatically_comment
118
+ <<~COMMENT
119
+ Whether this promotion applies automatically in the cart, as opposed to the promotion being activated through a promotion code
120
+ or a path (see above).
121
+ COMMENT
122
+ end
123
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddDbCommentsToFriendlyPromotionCodes < ActiveRecord::Migration[6.1]
4
+ def up
5
+ if connection.supports_comments?
6
+ change_table_comment(:friendly_promotion_codes, friendly_promotion_codes_table_comment)
7
+ change_column_comment(:friendly_promotion_codes, :id, id_comment)
8
+ change_column_comment(:friendly_promotion_codes, :promotion_id, promotion_id_comment)
9
+ change_column_comment(:friendly_promotion_codes, :value, value_comment)
10
+ change_column_comment(:friendly_promotion_codes, :created_at, created_at_comment)
11
+ change_column_comment(:friendly_promotion_codes, :updated_at, updated_at_comment)
12
+ change_column_comment(:friendly_promotion_codes, :promotion_code_batch_id, promotion_code_batch_id_comment)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def friendly_promotion_codes_table_comment
19
+ <<~COMMENT
20
+ Promotions can have many promotion codes. This table is a collection of those codes.
21
+ COMMENT
22
+ end
23
+
24
+ def id_comment
25
+ <<~COMMENT
26
+ Primary key of this table.
27
+ COMMENT
28
+ end
29
+
30
+ def promotion_id_comment
31
+ <<~COMMENT
32
+ Foreign key to the friendly_promotions table.
33
+ COMMENT
34
+ end
35
+
36
+ def value_comment
37
+ <<~COMMENT
38
+ The actual code, such as "BOATLIFE" for example.
39
+ COMMENT
40
+ end
41
+
42
+ def created_at_comment
43
+ <<~COMMENT
44
+ Timestamp indicating when this record was created.
45
+ COMMENT
46
+ end
47
+
48
+ def updated_at_comment
49
+ <<~COMMENT
50
+ Timestamp indicating when this record was last updated.
51
+ COMMENT
52
+ end
53
+
54
+ def promotion_code_batch_id_comment
55
+ <<~COMMENT
56
+ Foreign key to the friendly_promotion_code_batches table.
57
+ If this promotion code was created using a promotion code batch, links to the batch.
58
+ COMMENT
59
+ end
60
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddDbCommentsToFriendlyPromotionCodeBatches < ActiveRecord::Migration[6.1]
4
+ def up
5
+ if connection.supports_comments?
6
+ change_table_comment(:friendly_promotion_code_batches, friendly_promotion_code_batches_table_comment)
7
+ change_column_comment(:friendly_promotion_code_batches, :id, id_comment)
8
+ change_column_comment(:friendly_promotion_code_batches, :promotion_id, promotion_id_comment)
9
+ change_column_comment(:friendly_promotion_code_batches, :base_code, base_code_comment)
10
+ change_column_comment(:friendly_promotion_code_batches, :number_of_codes, number_of_codes_comment)
11
+ change_column_comment(:friendly_promotion_code_batches, :email, email_comment)
12
+ change_column_comment(:friendly_promotion_code_batches, :error, error_comment)
13
+ change_column_comment(:friendly_promotion_code_batches, :state, state_comment)
14
+ change_column_comment(:friendly_promotion_code_batches, :created_at, created_at_comment)
15
+ change_column_comment(:friendly_promotion_code_batches, :updated_at, updated_at_comment)
16
+ change_column_comment(:friendly_promotion_code_batches, :join_characters, join_characters_comment)
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def friendly_promotion_code_batches_table_comment
23
+ <<~COMMENT
24
+ We allow creating a large number of promotion codes automatically through a background job. This table collects the input
25
+ for creating such a batch of promotion codes.
26
+ COMMENT
27
+ end
28
+
29
+ def id_comment
30
+ <<~COMMENT
31
+ Primary key of this table.
32
+ COMMENT
33
+ end
34
+
35
+ def promotion_id_comment
36
+ <<~COMMENT
37
+ Foreign key to the friendly_promotions table.
38
+ COMMENT
39
+ end
40
+
41
+ def base_code_comment
42
+ <<~COMMENT
43
+ The base code of this promotion code batch, such as "BOATLIFE".
44
+ COMMENT
45
+ end
46
+
47
+ def number_of_codes_comment
48
+ <<~COMMENT
49
+ How many codes should be generated.
50
+ COMMENT
51
+ end
52
+
53
+ def email_comment
54
+ <<~COMMENT
55
+ After the batch has been created, or in the event of an error, notify this email address.
56
+ COMMENT
57
+ end
58
+
59
+ def error_comment
60
+ <<~COMMENT
61
+ Error that has occurred during batch processing, if any.
62
+ COMMENT
63
+ end
64
+
65
+ def state_comment
66
+ <<~COMMENT
67
+ What the state of the promotion code batch is:
68
+ - pending
69
+ - processing
70
+ - completed
71
+ COMMENT
72
+ end
73
+
74
+ def created_at_comment
75
+ <<~COMMENT
76
+ Timestamp indicating when this record was created.
77
+ COMMENT
78
+ end
79
+
80
+ def updated_at_comment
81
+ <<~COMMENT
82
+ Timestamp indicating when this record was last updated.
83
+ COMMENT
84
+ end
85
+
86
+ def join_characters_comment
87
+ <<~COMMENT
88
+ What characters to use for joining the base code with the individual extension, such as "_" for creating "BOATLIFE_S3CR3T".
89
+ COMMENT
90
+ end
91
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddDbCommentsToFriendlyPromotionRulesStores < ActiveRecord::Migration[6.1]
4
+ def up
5
+ if connection.supports_comments?
6
+ change_table_comment(:friendly_promotion_rules_stores, friendly_promotion_rules_stores_table_comment)
7
+ change_column_comment(:friendly_promotion_rules_stores, :id, id_comment)
8
+ change_column_comment(:friendly_promotion_rules_stores, :store_id, store_id_comment)
9
+ change_column_comment(:friendly_promotion_rules_stores, :promotion_rule_id, promotion_rule_id_comment)
10
+ change_column_comment(:friendly_promotion_rules_stores, :created_at, created_at_comment)
11
+ change_column_comment(:friendly_promotion_rules_stores, :updated_at, updated_at_comment)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def friendly_promotion_rules_stores_table_comment
18
+ <<~COMMENT
19
+ Join table between promotion rules and stores. Only used with the promotion rule "Store", which checks that an order
20
+ has been placed in a particular Spree::Store instance.
21
+ COMMENT
22
+ end
23
+
24
+ def id_comment
25
+ <<~COMMENT
26
+ Primary key of this table.
27
+ COMMENT
28
+ end
29
+
30
+ def store_id_comment
31
+ <<~COMMENT
32
+ Foreign key to the spree_stores table.
33
+ COMMENT
34
+ end
35
+
36
+ def promotion_rule_id_comment
37
+ <<~COMMENT
38
+ Foreign key to the friendly_promotion_rules table.
39
+ COMMENT
40
+ end
41
+
42
+ def created_at_comment
43
+ <<~COMMENT
44
+ Timestamp indicating when this record was created.
45
+ COMMENT
46
+ end
47
+
48
+ def updated_at_comment
49
+ <<~COMMENT
50
+ Timestamp indicating when this record was last updated.
51
+ COMMENT
52
+ end
53
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddDbCommentsToFriendlyPromotionActions < ActiveRecord::Migration[6.1]
4
+ def up
5
+ if connection.supports_comments?
6
+ change_table_comment(:friendly_promotion_actions, friendly_promotion_actions_table_comment)
7
+ change_column_comment(:friendly_promotion_actions, :id, id_comment)
8
+ change_column_comment(:friendly_promotion_actions, :promotion_id, promotion_id_comment)
9
+ change_column_comment(:friendly_promotion_actions, :type, type_comment)
10
+ change_column_comment(:friendly_promotion_actions, :deleted_at, deleted_at_comment)
11
+ change_column_comment(:friendly_promotion_actions, :preferences, preferences_comment)
12
+ change_column_comment(:friendly_promotion_actions, :created_at, created_at_comment)
13
+ change_column_comment(:friendly_promotion_actions, :updated_at, updated_at_comment)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def friendly_promotion_actions_table_comment
20
+ <<~COMMENT
21
+ Single Table inheritance table. Represents what to do to an order when the linked promotion is eligible.
22
+ Promotions can have many promotion actions.
23
+ COMMENT
24
+ end
25
+
26
+ def id_comment
27
+ <<~COMMENT
28
+ Primary key of this table.
29
+ COMMENT
30
+ end
31
+
32
+ def promotion_id_comment
33
+ <<~COMMENT
34
+ Foreign key to the friendly_promotions table.
35
+ COMMENT
36
+ end
37
+
38
+ def type_comment
39
+ <<~COMMENT
40
+ A class name representing which promotion action this represents.
41
+ Usually SolidusFriendlyPromotions::Actions::Adjust{LineItem,Shipment}.
42
+ COMMENT
43
+ end
44
+
45
+ def deleted_at_comment
46
+ <<~COMMENT
47
+ Timestamp indicating if and when this record was soft-deleted.
48
+ COMMENT
49
+ end
50
+
51
+ def preferences_comment
52
+ <<~COMMENT
53
+ Preferences for this promotion action. Serialized YAML.
54
+ COMMENT
55
+ end
56
+
57
+ def created_at_comment
58
+ <<~COMMENT
59
+ Timestamp indicating when this record was created.
60
+ COMMENT
61
+ end
62
+
63
+ def updated_at_comment
64
+ <<~COMMENT
65
+ Timestamp indicating when this record was last updated.
66
+ COMMENT
67
+ end
68
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddDbCommentsToFriendlyProductsPromotionRules < ActiveRecord::Migration[6.1]
4
+ def up
5
+ if connection.supports_comments?
6
+ change_table_comment(:friendly_products_promotion_rules, friendly_products_promotion_rules_table_comment)
7
+ change_column_comment(:friendly_products_promotion_rules, :id, id_comment)
8
+ change_column_comment(:friendly_products_promotion_rules, :product_id, product_id_comment)
9
+ change_column_comment(:friendly_products_promotion_rules, :promotion_rule_id, promotion_rule_id_comment)
10
+ change_column_comment(:friendly_products_promotion_rules, :created_at, created_at_comment)
11
+ change_column_comment(:friendly_products_promotion_rules, :updated_at, updated_at_comment)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def friendly_products_promotion_rules_table_comment
18
+ <<~COMMENT
19
+ Join table between promotion rules and products.
20
+ COMMENT
21
+ end
22
+
23
+ def id_comment
24
+ <<~COMMENT
25
+ Primary key of this table.
26
+ COMMENT
27
+ end
28
+
29
+ def product_id_comment
30
+ <<~COMMENT
31
+ Foreign key to the spree_products table.
32
+ COMMENT
33
+ end
34
+
35
+ def promotion_rule_id_comment
36
+ <<~COMMENT
37
+ Foreign key to the friendly_promotion_rules table.
38
+ COMMENT
39
+ end
40
+
41
+ def created_at_comment
42
+ <<~COMMENT
43
+ Timestamp indicating when this record was created.
44
+ COMMENT
45
+ end
46
+
47
+ def updated_at_comment
48
+ <<~COMMENT
49
+ Timestamp indicating when this record was last updated.
50
+ COMMENT
51
+ end
52
+ end