solidus_friendly_promotions 1.0.1 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/Gemfile +1 -1
  4. data/MIGRATING.md +1 -1
  5. data/README.md +22 -16
  6. data/app/assets/config/solidus_friendly_promotions/manifest.js +7 -1
  7. data/app/controllers/solidus_friendly_promotions/admin/benefits_controller.rb +85 -0
  8. data/app/controllers/solidus_friendly_promotions/admin/conditions_controller.rb +69 -0
  9. data/app/controllers/solidus_friendly_promotions/admin/promotions_controller.rb +3 -3
  10. data/app/decorators/models/solidus_friendly_promotions/adjustment_decorator.rb +4 -4
  11. data/app/decorators/models/solidus_friendly_promotions/line_item_decorator.rb +2 -2
  12. data/app/decorators/models/solidus_friendly_promotions/order_decorator.rb +6 -6
  13. data/app/helpers/solidus_friendly_promotions/admin/benefits_helper.rb +19 -0
  14. data/app/helpers/solidus_friendly_promotions/admin/conditions_helper.rb +12 -0
  15. data/app/javascript/solidus_friendly_promotions/controllers/product_option_values_controller.js +1 -1
  16. data/app/javascript/solidus_friendly_promotions/web_components/number_with_currency.js +35 -0
  17. data/app/javascript/solidus_friendly_promotions/{jquery → web_components}/option_value_picker.js +8 -0
  18. data/app/javascript/solidus_friendly_promotions/web_components/product_picker.js +7 -0
  19. data/app/javascript/solidus_friendly_promotions/web_components/select_two.js +11 -0
  20. data/app/javascript/solidus_friendly_promotions/web_components/taxon_picker.js +7 -0
  21. data/app/javascript/solidus_friendly_promotions/web_components/user_picker.js +7 -0
  22. data/app/javascript/solidus_friendly_promotions/web_components/variant_picker.js +7 -0
  23. data/app/javascript/solidus_friendly_promotions.js +7 -11
  24. data/app/models/concerns/solidus_friendly_promotions/{actions/order_level_action.rb → benefits/order_benefit.rb} +2 -2
  25. data/app/models/concerns/solidus_friendly_promotions/{rules/line_item_applicable_order_rule.rb → conditions/line_item_applicable_order_condition.rb} +2 -2
  26. data/app/models/concerns/solidus_friendly_promotions/{rules/line_item_level_rule.rb → conditions/line_item_level_condition.rb} +2 -2
  27. data/app/models/concerns/solidus_friendly_promotions/{rules/order_level_rule.rb → conditions/order_level_condition.rb} +2 -2
  28. data/app/models/concerns/solidus_friendly_promotions/{rules/shipment_level_rule.rb → conditions/shipment_level_condition.rb} +2 -2
  29. data/app/models/solidus_friendly_promotions/{promotion_action.rb → benefit.rb} +48 -11
  30. data/app/models/solidus_friendly_promotions/{actions → benefits}/adjust_line_item.rb +6 -2
  31. data/app/models/solidus_friendly_promotions/{actions → benefits}/adjust_line_item_quantity_groups.rb +3 -3
  32. data/app/models/solidus_friendly_promotions/{actions → benefits}/adjust_shipment.rb +6 -2
  33. data/app/models/solidus_friendly_promotions/{actions → benefits}/create_discounted_item.rb +6 -7
  34. data/app/models/solidus_friendly_promotions/calculators/distributed_amount.rb +1 -1
  35. data/app/models/solidus_friendly_promotions/calculators/tiered_flat_rate.rb +1 -1
  36. data/app/models/solidus_friendly_promotions/calculators/tiered_percent.rb +1 -1
  37. data/app/models/solidus_friendly_promotions/calculators/tiered_percent_on_eligible_item_quantity.rb +4 -2
  38. data/app/models/solidus_friendly_promotions/{promotion_rule.rb → condition.rb} +13 -7
  39. data/app/models/solidus_friendly_promotions/condition_product.rb +8 -0
  40. data/app/models/solidus_friendly_promotions/condition_store.rb +8 -0
  41. data/app/models/solidus_friendly_promotions/condition_taxon.rb +8 -0
  42. data/app/models/solidus_friendly_promotions/{promotion_rules_user.rb → condition_user.rb} +2 -2
  43. data/app/models/solidus_friendly_promotions/{rules → conditions}/discounted_item_total.rb +3 -3
  44. data/app/models/solidus_friendly_promotions/{rules → conditions}/first_order.rb +3 -3
  45. data/app/models/solidus_friendly_promotions/{rules → conditions}/first_repeat_purchase_since.rb +3 -3
  46. data/app/models/solidus_friendly_promotions/{rules → conditions}/item_total.rb +5 -5
  47. data/app/models/solidus_friendly_promotions/{rules → conditions}/line_item_option_value.rb +3 -3
  48. data/app/models/solidus_friendly_promotions/{rules → conditions}/line_item_product.rb +8 -8
  49. data/app/models/solidus_friendly_promotions/{rules → conditions}/line_item_taxon.rb +8 -8
  50. data/app/models/solidus_friendly_promotions/{rules → conditions}/minimum_quantity.rb +8 -8
  51. data/app/models/solidus_friendly_promotions/{rules → conditions}/nth_order.rb +5 -5
  52. data/app/models/solidus_friendly_promotions/{rules → conditions}/one_use_per_user.rb +3 -3
  53. data/app/models/solidus_friendly_promotions/{rules → conditions}/option_value.rb +3 -3
  54. data/app/models/solidus_friendly_promotions/{rules → conditions}/product.rb +9 -9
  55. data/app/models/solidus_friendly_promotions/{rules → conditions}/shipping_method.rb +3 -3
  56. data/app/models/solidus_friendly_promotions/{rules → conditions}/store.rb +6 -6
  57. data/app/models/solidus_friendly_promotions/{rules → conditions}/taxon.rb +12 -12
  58. data/app/models/solidus_friendly_promotions/{rules → conditions}/user.rb +7 -7
  59. data/app/models/solidus_friendly_promotions/{rules → conditions}/user_logged_in.rb +3 -3
  60. data/app/models/solidus_friendly_promotions/{rules → conditions}/user_role.rb +3 -3
  61. data/app/models/solidus_friendly_promotions/eligibility_result.rb +1 -1
  62. data/app/models/solidus_friendly_promotions/eligibility_results.rb +7 -7
  63. data/app/models/solidus_friendly_promotions/friendly_promotion_adjuster/discount_order.rb +28 -29
  64. data/app/models/solidus_friendly_promotions/friendly_promotion_adjuster/load_promotions.rb +10 -11
  65. data/app/models/solidus_friendly_promotions/friendly_promotion_adjuster/persist_discounted_order.rb +2 -2
  66. data/app/models/solidus_friendly_promotions/order_promotion.rb +1 -1
  67. data/app/models/solidus_friendly_promotions/permission_sets/friendly_promotion_management.rb +1 -1
  68. data/app/models/solidus_friendly_promotions/promotion.rb +14 -43
  69. data/app/models/solidus_friendly_promotions/promotion_advertiser.rb +10 -0
  70. data/app/models/solidus_friendly_promotions/promotion_code.rb +1 -1
  71. data/app/models/solidus_friendly_promotions/shipping_rate_discount.rb +1 -1
  72. data/app/views/solidus_friendly_promotions/admin/benefit_fields/_adjust_line_item.html.erb +6 -0
  73. data/app/views/solidus_friendly_promotions/admin/{promotion_actions/actions → benefit_fields}/_adjust_line_item_quantity_groups.html.erb +4 -4
  74. data/app/views/solidus_friendly_promotions/admin/benefit_fields/_adjust_shipment.html.erb +6 -0
  75. data/app/views/solidus_friendly_promotions/admin/benefit_fields/_calculator_fields.erb +11 -0
  76. data/app/views/solidus_friendly_promotions/admin/{promotion_actions/actions → benefit_fields}/_create_discounted_item.html.erb +8 -6
  77. data/app/views/solidus_friendly_promotions/admin/benefits/_benefit.html.erb +50 -0
  78. data/app/views/solidus_friendly_promotions/admin/benefits/_calculator_select.html.erb +16 -0
  79. data/app/views/solidus_friendly_promotions/admin/benefits/_form.html.erb +3 -0
  80. data/app/views/solidus_friendly_promotions/admin/benefits/_new_benefit.html.erb +33 -0
  81. data/app/views/solidus_friendly_promotions/admin/benefits/_type_select.html.erb +16 -0
  82. data/app/views/solidus_friendly_promotions/admin/benefits/edit.html.erb +19 -0
  83. data/app/views/solidus_friendly_promotions/admin/benefits/new.html.erb +1 -0
  84. data/app/views/solidus_friendly_promotions/admin/{promotion_actions/calculators → calculator_fields}/_default_fields.html.erb +1 -1
  85. data/app/views/solidus_friendly_promotions/admin/{promotion_actions/calculators → calculator_fields}/distributed_amount/_fields.html.erb +3 -3
  86. data/app/views/solidus_friendly_promotions/admin/calculator_fields/flat_rate/_fields.html.erb +6 -0
  87. data/app/views/solidus_friendly_promotions/admin/calculator_fields/flexi_rate/_fields.html.erb +24 -0
  88. data/app/views/solidus_friendly_promotions/admin/calculator_fields/percent/_fields.html.erb +6 -0
  89. data/app/views/solidus_friendly_promotions/admin/calculator_fields/tiered_flat_rate/_fields.html.erb +32 -0
  90. data/app/views/solidus_friendly_promotions/admin/{promotion_actions/calculators → calculator_fields}/tiered_flat_rate/_tier_fields.html.erb +7 -8
  91. data/app/views/solidus_friendly_promotions/admin/calculator_fields/tiered_percent/_fields.html.erb +47 -0
  92. data/app/views/solidus_friendly_promotions/admin/{promotion_actions/calculators → calculator_fields}/tiered_percent/_tier_fields.html.erb +8 -7
  93. data/app/views/solidus_friendly_promotions/admin/{promotion_actions/calculators → calculator_fields}/tiered_percent_on_eligible_item_quantity/_fields.html.erb +11 -9
  94. data/app/views/solidus_friendly_promotions/admin/calculator_fields/tiered_percent_on_eligible_item_quantity/_tier_fields.html.erb +35 -0
  95. data/app/views/solidus_friendly_promotions/admin/condition_fields/_first_order.html.erb +3 -0
  96. data/app/views/solidus_friendly_promotions/admin/condition_fields/_first_repeat_purchase_since.html.erb +7 -0
  97. data/app/views/solidus_friendly_promotions/admin/condition_fields/_item_total.html.erb +15 -0
  98. data/app/views/solidus_friendly_promotions/admin/condition_fields/_line_item_option_value.html.erb +25 -0
  99. data/app/views/solidus_friendly_promotions/admin/{promotion_rules/rules → condition_fields}/_line_item_product.html.erb +7 -7
  100. data/app/views/solidus_friendly_promotions/admin/condition_fields/_line_item_taxon.html.erb +17 -0
  101. data/app/views/solidus_friendly_promotions/admin/condition_fields/_minimum_quantity.html.erb +5 -0
  102. data/app/views/solidus_friendly_promotions/admin/condition_fields/_nth_order.html.erb +15 -0
  103. data/app/views/solidus_friendly_promotions/admin/condition_fields/_one_use_per_user.html.erb +3 -0
  104. data/app/views/solidus_friendly_promotions/admin/{promotion_rules/rules → condition_fields}/_option_value.html.erb +10 -10
  105. data/app/views/solidus_friendly_promotions/admin/condition_fields/_product.html.erb +28 -0
  106. data/app/views/solidus_friendly_promotions/admin/{promotion_rules/rules → condition_fields}/_shipping_method.html.erb +3 -3
  107. data/app/views/solidus_friendly_promotions/admin/condition_fields/_store.html.erb +9 -0
  108. data/app/views/solidus_friendly_promotions/admin/condition_fields/_taxon.html.erb +28 -0
  109. data/app/views/solidus_friendly_promotions/admin/condition_fields/_user.html.erb +7 -0
  110. data/app/views/solidus_friendly_promotions/admin/condition_fields/_user_logged_in.html.erb +3 -0
  111. data/app/views/solidus_friendly_promotions/admin/condition_fields/_user_role.html.erb +15 -0
  112. data/app/views/solidus_friendly_promotions/admin/condition_fields/line_item_option_value/_option_value_fields.html.erb +21 -0
  113. data/app/views/solidus_friendly_promotions/admin/conditions/_condition.html.erb +26 -0
  114. data/app/views/solidus_friendly_promotions/admin/conditions/_new_condition.html.erb +26 -0
  115. data/app/views/solidus_friendly_promotions/admin/conditions/_type_select.html.erb +20 -0
  116. data/app/views/solidus_friendly_promotions/admin/conditions/new.html.erb +1 -0
  117. data/app/views/solidus_friendly_promotions/admin/promotion_code_batches/_form_fields.html.erb +5 -5
  118. data/app/views/solidus_friendly_promotions/admin/promotions/_form.html.erb +4 -4
  119. data/app/views/solidus_friendly_promotions/admin/promotions/_table_filter.html.erb +6 -6
  120. data/app/views/solidus_friendly_promotions/admin/promotions/edit.html.erb +7 -41
  121. data/app/views/solidus_friendly_promotions/admin/shared/_number_with_currency.html.erb +20 -0
  122. data/app/views/solidus_friendly_promotions/admin/shared/preference_fields/_boolean.html.erb +14 -0
  123. data/app/views/solidus_friendly_promotions/admin/shared/preference_fields/_decimal.html.erb +12 -0
  124. data/app/views/solidus_friendly_promotions/admin/shared/preference_fields/_encrypted_string.html.erb +12 -0
  125. data/app/views/solidus_friendly_promotions/admin/shared/preference_fields/_integer.html.erb +12 -0
  126. data/app/views/solidus_friendly_promotions/admin/shared/preference_fields/_password.html.erb +12 -0
  127. data/app/views/solidus_friendly_promotions/admin/shared/preference_fields/_string.html.erb +12 -0
  128. data/app/views/solidus_friendly_promotions/admin/shared/preference_fields/_text.html.erb +12 -0
  129. data/bin/sandbox +3 -3
  130. data/config/importmap.rb +2 -0
  131. data/config/locales/en.yml +128 -94
  132. data/config/routes.rb +3 -2
  133. data/db/migrate/20231011120928_add_db_comments_to_friendly_promotion_rules_taxons.rb +2 -2
  134. data/db/migrate/20231011142040_add_db_comments_to_friendly_promotion_rules_users.rb +1 -1
  135. data/db/migrate/20231011190222_add_db_comments_to_friendly_promotion_actions.rb +1 -1
  136. data/db/migrate/20240409093831_add_action_reference_to_rules.rb +34 -0
  137. data/db/migrate/20240506142650_remove_promotion_rules_promotion_id.rb +5 -0
  138. data/db/migrate/20240508080834_rename_promotion_rules_to_conditions.rb +19 -0
  139. data/db/migrate/20240508131514_rename_friendly_promotion_actions_to_friendly_benefits.rb +19 -0
  140. data/db/migrate/20240612113608_update_column_comments_for_benefits.rb +31 -0
  141. data/db/migrate/20240612114132_update_column_comments_for_conditions.rb +30 -0
  142. data/db/migrate/20240612115209_update_column_comments_for_condition_stores.rb +23 -0
  143. data/db/migrate/20240612115749_update_column_comments_for_condition_products.rb +22 -0
  144. data/db/migrate/20240612120411_update_column_comments_for_condition_taxons.rb +24 -0
  145. data/db/migrate/20240612121049_update_column_comments_for_condition_users.rb +23 -0
  146. data/lib/generators/solidus_friendly_promotions/install/templates/initializer.rb +30 -30
  147. data/lib/solidus_friendly_promotions/configuration.rb +11 -3
  148. data/lib/solidus_friendly_promotions/migrate_adjustments.rb +11 -11
  149. data/lib/solidus_friendly_promotions/promotion_map.rb +17 -17
  150. data/lib/solidus_friendly_promotions/promotion_migrator.rb +16 -16
  151. data/lib/solidus_friendly_promotions/testing_support/factories/friendly_promotion_factory.rb +8 -34
  152. data/lib/solidus_friendly_promotions/testing_support/factories/friendly_shipping_rate_discount_factory.rb +2 -2
  153. data/lib/solidus_friendly_promotions/version.rb +1 -1
  154. data/lib/tasks/solidus_friendly_promotions/migrate_adjustments.rake +2 -2
  155. data/solidus_friendly_promotions.gemspec +2 -2
  156. metadata +114 -86
  157. data/.rubocop_todo.yml +0 -157
  158. data/app/controllers/solidus_friendly_promotions/admin/promotion_actions_controller.rb +0 -103
  159. data/app/controllers/solidus_friendly_promotions/admin/promotion_rules_controller.rb +0 -105
  160. data/app/helpers/solidus_friendly_promotions/admin/promotion_actions_helper.rb +0 -23
  161. data/app/helpers/solidus_friendly_promotions/admin/promotion_rules_helper.rb +0 -25
  162. data/app/models/solidus_friendly_promotions/products_promotion_rule.rb +0 -8
  163. data/app/models/solidus_friendly_promotions/promotion_rules_store.rb +0 -8
  164. data/app/models/solidus_friendly_promotions/promotion_rules_taxon.rb +0 -8
  165. data/app/views/solidus_friendly_promotions/admin/promotion_actions/_calculator_select.html.erb +0 -16
  166. data/app/views/solidus_friendly_promotions/admin/promotion_actions/_form.html.erb +0 -3
  167. data/app/views/solidus_friendly_promotions/admin/promotion_actions/_promotion_action.html.erb +0 -29
  168. data/app/views/solidus_friendly_promotions/admin/promotion_actions/_type_select.html.erb +0 -14
  169. data/app/views/solidus_friendly_promotions/admin/promotion_actions/actions/_adjust_line_item.html.erb +0 -6
  170. data/app/views/solidus_friendly_promotions/admin/promotion_actions/actions/_adjust_shipment.html.erb +0 -6
  171. data/app/views/solidus_friendly_promotions/admin/promotion_actions/actions/_calculator_fields.erb +0 -9
  172. data/app/views/solidus_friendly_promotions/admin/promotion_actions/calculators/flat_rate/_fields.html.erb +0 -6
  173. data/app/views/solidus_friendly_promotions/admin/promotion_actions/calculators/tiered_flat_rate/_fields.html.erb +0 -34
  174. data/app/views/solidus_friendly_promotions/admin/promotion_actions/calculators/tiered_percent/_fields.html.erb +0 -34
  175. data/app/views/solidus_friendly_promotions/admin/promotion_actions/calculators/tiered_percent_on_eligible_item_quantity/_tier_fields.html.erb +0 -27
  176. data/app/views/solidus_friendly_promotions/admin/promotion_actions/edit.html.erb +0 -23
  177. data/app/views/solidus_friendly_promotions/admin/promotion_actions/new.html.erb +0 -26
  178. data/app/views/solidus_friendly_promotions/admin/promotion_rules/_promotion_rule.html.erb +0 -22
  179. data/app/views/solidus_friendly_promotions/admin/promotion_rules/_type_select.html.erb +0 -20
  180. data/app/views/solidus_friendly_promotions/admin/promotion_rules/new.html.erb +0 -24
  181. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_first_order.html.erb +0 -3
  182. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_first_repeat_purchase_since.html.erb +0 -6
  183. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_item_total.html.erb +0 -17
  184. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_line_item_option_value.html.erb +0 -25
  185. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_line_item_taxon.html.erb +0 -17
  186. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_minimum_quantity.html.erb +0 -5
  187. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_nth_order.html.erb +0 -15
  188. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_one_use_per_user.html.erb +0 -3
  189. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_product.html.erb +0 -44
  190. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_store.html.erb +0 -9
  191. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_taxon.html.erb +0 -44
  192. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_user.html.erb +0 -7
  193. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_user_logged_in.html.erb +0 -3
  194. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_user_role.html.erb +0 -15
  195. data/app/views/solidus_friendly_promotions/admin/promotion_rules/rules/line_item_option_value/_option_value_fields.html.erb +0 -17
@@ -1,105 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolidusFriendlyPromotions
4
- module Admin
5
- class PromotionRulesController < Spree::Admin::BaseController
6
- helper "solidus_friendly_promotions/admin/promotion_rules"
7
-
8
- before_action :validate_level, only: [:new, :create]
9
- before_action :load_promotion, only: [:create, :destroy, :update, :new]
10
- before_action :validate_promotion_rule_type, only: [:create]
11
-
12
- def new
13
- if params.dig(:promotion_rule, :type)
14
- validate_promotion_rule_type
15
- @promotion_rule = @promotion.rules.build(type: @promotion_rule_type)
16
- end
17
- render layout: false
18
- end
19
-
20
- def create
21
- @promotion_rule = @promotion.rules.build(
22
- promotion_rule_params.merge(type: @promotion_rule_type.to_s)
23
- )
24
- if @promotion_rule.save
25
- flash[:success] =
26
- t("spree.successfully_created", resource: SolidusFriendlyPromotions::PromotionRule.model_name.human)
27
- end
28
- redirect_to location_after_save
29
- end
30
-
31
- def update
32
- @promotion_rule = @promotion.rules.find(params[:id])
33
- @promotion_rule.assign_attributes(promotion_rule_params)
34
- if @promotion_rule.save
35
- flash[:success] =
36
- t("spree.successfully_updated", resource: SolidusFriendlyPromotions::PromotionRule.model_name.human)
37
- end
38
- redirect_to location_after_save
39
- end
40
-
41
- def destroy
42
- @promotion_rule = @promotion.rules.find(params[:id])
43
- if @promotion_rule.destroy
44
- flash[:success] =
45
- t("spree.successfully_removed", resource: SolidusFriendlyPromotions::PromotionRule.model_name.human)
46
- end
47
- redirect_to location_after_save
48
- end
49
-
50
- private
51
-
52
- def location_after_save
53
- solidus_friendly_promotions.edit_admin_promotion_path(@promotion)
54
- end
55
-
56
- def load_promotion
57
- @promotion = SolidusFriendlyPromotions::Promotion.find(params[:promotion_id])
58
- end
59
-
60
- def model_class
61
- SolidusFriendlyPromotions::PromotionRule
62
- end
63
-
64
- def validate_promotion_rule_type
65
- requested_type = params[:promotion_rule].delete(:type)
66
- promotion_rule_types = SolidusFriendlyPromotions.config.send(:"#{@level}_rules")
67
- @promotion_rule_type = promotion_rule_types.detect do |klass|
68
- klass.name == requested_type
69
- end
70
- return if @promotion_rule_type
71
-
72
- flash[:error] = t("solidus_friendly_promotions.invalid_promotion_rule")
73
- respond_to do |format|
74
- format.html { redirect_to solidus_friendly_promotions.edit_admin_promotion_path(@promotion) }
75
- format.js { render layout: false }
76
- end
77
- end
78
-
79
- def validate_level
80
- requested_level = params[:level].to_s
81
- if requested_level.in?(["order", "line_item", "shipment"])
82
- @level = requested_level
83
- else
84
- @level = "order"
85
- flash.now[:error] = t(:invalid_promotion_rule_level, scope: :solidus_friendly_promotions)
86
- end
87
- end
88
-
89
- def promotion_rule_params
90
- params[:promotion_rule].try(:permit!) || {}
91
- end
92
-
93
- def promotion_rule_types
94
- case params[:level]
95
- when "order"
96
- SolidusFriendlyPromotions.config.order_rules
97
- when "line_item"
98
- SolidusFriendlyPromotions.config.line_item_rules
99
- when "shipment"
100
- SolidusFriendlyPromotions.config.shipment_rules
101
- end
102
- end
103
- end
104
- end
105
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolidusFriendlyPromotions
4
- module Admin
5
- module PromotionActionsHelper
6
- def options_for_promotion_action_calculator_types(promotion_action)
7
- calculators = promotion_action.available_calculators
8
- options = calculators.map { |calculator| [calculator.model_name.human, calculator.name] }
9
- options_for_select(options, promotion_action.calculator_type.to_s)
10
- end
11
-
12
- def options_for_promotion_action_types(promotion_action)
13
- actions = SolidusFriendlyPromotions.config.actions
14
- options = actions.map { |action| [action.model_name.human, action.name] }
15
- options_for_select(options, promotion_action&.type&.to_s)
16
- end
17
-
18
- def promotion_actions_by_level(promotion, level)
19
- promotion.actions.select { |action| action.level == level }
20
- end
21
- end
22
- end
23
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolidusFriendlyPromotions
4
- module Admin
5
- module PromotionRulesHelper
6
- def options_for_promotion_rule_types(promotion_rule, level)
7
- existing = promotion_rule.promotion.rules.select(&:persisted?).map { |rule| rule.class.name }
8
- rules = SolidusFriendlyPromotions.config.send(:"#{level}_rules").reject { |rule| existing.include? rule.name }
9
- options = rules.map { |rule| [rule.model_name.human, rule.name] }
10
- options_for_select(options, promotion_rule.type.to_s)
11
- end
12
-
13
- def promotion_rules_by_level(promotion, level)
14
- promotion.rules.select do |rule|
15
- rule.level == level || rule_applicable_by_preference(rule, level)
16
- end
17
- end
18
-
19
- def rule_applicable_by_preference(rule, level)
20
- method_name = "preferred_#{level}_applicable"
21
- rule.respond_to?(method_name) && rule.send(method_name)
22
- end
23
- end
24
- end
25
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolidusFriendlyPromotions
4
- class ProductsPromotionRule < Spree::Base
5
- belongs_to :product, class_name: "Spree::Product", optional: true
6
- belongs_to :promotion_rule, class_name: "SolidusFriendlyPromotions::PromotionRule", optional: true
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolidusFriendlyPromotions
4
- class PromotionRulesStore < Spree::Base
5
- belongs_to :promotion_rule, class_name: "SolidusFriendlyPromotions::PromotionRule", optional: true
6
- belongs_to :store, class_name: "Spree::Store", optional: true
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SolidusFriendlyPromotions
4
- class PromotionRulesTaxon < Spree::Base
5
- belongs_to :promotion_rule, class_name: "SolidusFriendlyPromotions::PromotionRule", optional: true
6
- belongs_to :taxon, class_name: "Spree::Taxon", optional: true
7
- end
8
- end
@@ -1,16 +0,0 @@
1
- <%= form_with model: promotion_action, scope: :promotion_action, url: path, method: :get do |form| %>
2
- <div class="field">
3
- <%= form.hidden_field :type %>
4
- <%= form.label :calculator_type %>
5
- <%=
6
- form.select :calculator_type,
7
- options_for_promotion_action_calculator_types(form.object),
8
- {
9
- include_blank: t(:choose_promotion_action_calculator, scope: 'solidus_friendly_promotions')
10
- },
11
- class: 'custom-select fullwidth',
12
- onchange: 'this.form.requestSubmit()',
13
- required: true
14
- %>
15
- </div>
16
- <% end %>
@@ -1,3 +0,0 @@
1
- <%= form.hidden_field :type %>
2
- <%= form.hidden_field :calculator_type %>
3
- <%= render form.object, promotion_action: form.object, param_prefix: form.object_name, form: form %>
@@ -1,29 +0,0 @@
1
- <%= turbo_frame_tag @promotion, dom_id(promotion_action) do %>
2
- <div class="promotion_action promotion-block">
3
- <h6 class='promotion-title'> <%= promotion_action.model_name.human %></h6>
4
-
5
- <% if can?(:destroy, promotion_action) %>
6
- <%= link_to_with_icon 'trash', '', solidus_friendly_promotions.admin_promotion_promotion_action_path(@promotion, promotion_action), method: :delete, class: 'delete' %>
7
- <% end %>
8
-
9
-
10
- <%= render "solidus_friendly_promotions/admin/promotion_actions/calculator_select",
11
- path: solidus_friendly_promotions.edit_admin_promotion_promotion_action_path(@promotion, promotion_action),
12
- promotion_action: promotion_action %>
13
-
14
- <%=
15
- form_with(
16
- model: promotion_action,
17
- scope: :promotion_action,
18
- url: solidus_friendly_promotions.admin_promotion_promotion_action_path(@promotion, promotion_action),
19
- data: { turbo: false }
20
- ) do |form| %>
21
- <%= render 'solidus_friendly_promotions/admin/promotion_actions/form', form: form %>
22
- <div class="row">
23
- <div class="col-12">
24
- <%= button_tag t(:update, scope: [:solidus_friendly_promotions, :crud]), class: "btn btn-secondary float-right" %>
25
- </div>
26
- </div>
27
- <% end %>
28
- </div>
29
- <% end %>
@@ -1,14 +0,0 @@
1
- <%= form_with model: @promotion_action, scope: :promotion_action, url: solidus_friendly_promotions.new_admin_promotion_promotion_action_path(@promotion), method: :get do |form| %>
2
- <%= form.label :type %>
3
- <%= admin_hint t('solidus_friendly_promotions.adjustment_type'), t(:promotions, scope: [:solidus_friendly_promotions, :hints, "solidus_friendly_promotions/calculator"]) %>
4
- <%=
5
- form.select :type,
6
- options_for_promotion_action_types(form.object),
7
- {
8
- include_blank: t(:choose_promotion_action, scope: 'solidus_friendly_promotions')
9
- },
10
- class: 'custom-select fullwidth',
11
- onchange: 'this.form.requestSubmit()',
12
- required: true
13
- %>
14
- <% end %>
@@ -1,6 +0,0 @@
1
- <%= render(
2
- "solidus_friendly_promotions/admin/promotion_actions/actions/calculator_fields",
3
- promotion_action: promotion_action,
4
- param_prefix: param_prefix,
5
- form: form
6
- ) %>
@@ -1,6 +0,0 @@
1
- <%= render(
2
- "solidus_friendly_promotions/admin/promotion_actions/actions/calculator_fields",
3
- promotion_action: promotion_action,
4
- param_prefix: param_prefix,
5
- form: form
6
- ) %>
@@ -1,9 +0,0 @@
1
-
2
- <% calculator = promotion_action.calculator %>
3
- <% type_name = calculator.type.demodulize.underscore %>
4
- <%= calculator.description %>
5
- <% if lookup_context.exists?("fields", ["solidus_friendly_promotions/admin/promotion_actions/calculators/#{type_name}"], true) %>
6
- <%= render "solidus_friendly_promotions/admin/promotion_actions/calculators/#{type_name}/fields", calculator: calculator, prefix: param_prefix, form: form %>
7
- <% else %>
8
- <%= render "solidus_friendly_promotions/admin/promotion_actions/calculators/default_fields", calculator: calculator, prefix: param_prefix, form: form %>
9
- <% end %>
@@ -1,6 +0,0 @@
1
- <div class="field">
2
- <%= fields_for "#{prefix}[calculator_attributes]", calculator do |f| %>
3
- <%= f.label :preferred_amount %>
4
- <%= render "spree/admin/shared/number_with_currency", f: f, amount_attr: :preferred_amount, currency_attr: :preferred_currency %>
5
- <% end %>
6
- </div>
@@ -1,34 +0,0 @@
1
- <%= render "spree/admin/shared/preference_fields/#{calculator.preference_type(:base_amount)}",
2
- name: "#{prefix}[calculator_attributes][preferred_base_amount]",
3
- value: calculator.preferred_base_amount,
4
- label: calculator.class.human_attribute_name(:preferred_base_amount) %>
5
-
6
- <div class="field">
7
- <%= label_tag(
8
- "#{prefix}[calculator_attributes][preferred_currency]",
9
- t('spree.currency')
10
- ) %>
11
- <%= select_tag(
12
- "#{prefix}[calculator_attributes][preferred_currency]",
13
- options_for_select(
14
- Spree::Config.available_currencies,
15
- calculator.preferred_currency || Spree::Config[:currency]
16
- ),
17
- { class: 'custom-select fullwidth' }
18
- ) %>
19
- </div>
20
-
21
- <div class="field">
22
- <%= label_tag nil, calculator.class.human_attribute_name(:tiers) %>
23
- <div data-controller="calculator-tiers">
24
- <template data-calculator-tiers-target="template">
25
- <%= render "solidus_friendly_promotions/admin/promotion_actions/calculators/tiered_flat_rate/tier_fields", tier: [nil, nil], form: form %>
26
- </template>
27
- <% form.object.calculator.preferred_tiers.each do |tier| %>
28
- <%= render "solidus_friendly_promotions/admin/promotion_actions/calculators/tiered_flat_rate/tier_fields", tier: tier, form: form %>
29
- <% end %>
30
- <div class="mb-3" data-calculator-tiers-target="links">
31
- <%= link_to t(:add_tier, scope: [:solidus_friendly_promotions, :admin, :promotions, :calculator]), "#", class: "btn btn-outline-primary", data: { action: "click->calculator-tiers#add_association" } %>
32
- </div>
33
- </div>
34
- </div>
@@ -1,34 +0,0 @@
1
- <%= render "spree/admin/shared/preference_fields/#{calculator.preference_type(:base_percent)}",
2
- name: "#{prefix}[calculator_attributes][preferred_base_percent]",
3
- value: calculator.preferred_base_percent,
4
- label: calculator.class.human_attribute_name(:preferred_base_percent) %>
5
-
6
- <div class="field">
7
- <%= label_tag(
8
- "#{prefix}[calculator_attributes][preferred_currency]",
9
- t('spree.currency')
10
- ) %>
11
- <%= select_tag(
12
- "#{prefix}[calculator_attributes][preferred_currency]",
13
- options_for_select(
14
- Spree::Config.available_currencies,
15
- calculator.preferred_currency || Spree::Config[:currency]
16
- ),
17
- { class: 'custom-select fullwidth' }
18
- ) %>
19
- </div>
20
-
21
- <div class="field">
22
- <%= label_tag nil, calculator.class.human_attribute_name(:tiers) %>
23
- <div data-controller="calculator-tiers">
24
- <template data-calculator-tiers-target="template">
25
- <%= render "solidus_friendly_promotions/admin/promotion_actions/calculators/tiered_percent/tier_fields", tier: [nil, nil], form: form %>
26
- </template>
27
- <% form.object.calculator.preferred_tiers.each do |tier| %>
28
- <%= render "solidus_friendly_promotions/admin/promotion_actions/calculators/tiered_percent/tier_fields", tier: tier, form: form %>
29
- <% end %>
30
- <div class="mb-3" data-calculator-tiers-target="links">
31
- <%= link_to t(:add_tier, scope: [:solidus_friendly_promotions, :admin, :promotions, :calculator]), "#", class: "btn btn-outline-primary", data: { action: "click->calculator-tiers#add_association" } %>
32
- </div>
33
- </div>
34
- </div>
@@ -1,27 +0,0 @@
1
- <div class="fullwidth tier calculator-tiers">
2
- <a class="fa fa-trash remove" data-action="click->calculator-tiers#remove_association"></a>
3
- <div class="row">
4
- <div class="col-6">
5
- <input
6
- class="js-base-input form-control"
7
- data-action="calculator-tiers#propagate_base_to_value_input"
8
- type="text"
9
- value="<%= tier[0] %>"
10
- >
11
- </div>
12
- <div class="col-6">
13
- <div class="input-group">
14
- <input
15
- class="js-value-input form-control right-align"
16
- name="<%= form.object_name %>[calculator_attributes][preferred_tiers][<%= tier[0] %>]"
17
- type="text"
18
- value="<%= tier[1] %>"
19
- >
20
- <div class="input-group-append">
21
- <span class="input-group-text">%</span>
22
- </div>
23
- </div>
24
- </div>
25
- </div>
26
- <div class="clear"></div>
27
- </div>
@@ -1,23 +0,0 @@
1
- <%= turbo_frame_tag @promotion, dom_id(@promotion_action) do %>
2
- <div class="promotion_action promotion-block">
3
- <h6 class='promotion-title'> <%= @promotion_action.class.human_attribute_name(:description) %></h6>
4
- <%= link_to_with_icon 'trash', '', solidus_friendly_promotions.admin_promotion_promotion_action_path(@promotion, @promotion_action), method: :delete, class: 'delete' %>
5
- <%= render 'calculator_select', path: solidus_friendly_promotions.edit_admin_promotion_promotion_action_path(@promotion, @promotion_action), promotion_action: @promotion_action %>
6
-
7
- <%=
8
- form_with(
9
- model: @promotion_action,
10
- scope: :promotion_action,
11
- url: solidus_friendly_promotions.admin_promotion_promotion_action_path(@promotion, @promotion_action),
12
- ) do |form| %>
13
- <%= render "form", form: form %>
14
-
15
- <div class="row">
16
- <div class="col-12">
17
- <%= button_tag "Update", class: "btn btn-secondary float-right" %>
18
- </div>
19
- </div>
20
-
21
- <% end %>
22
- </div>
23
- <% end %>
@@ -1,26 +0,0 @@
1
- <%= turbo_frame_tag @promotion, "new_promotion_action" do %>
2
- <div class="promotion_action promotion-block">
3
- <h6 class='promotion-title'> <%= t(:add_action, scope: :solidus_friendly_promotions) %></h6>
4
- <%= link_to_with_icon 'trash', '', solidus_friendly_promotions.edit_admin_promotion_path(@promotion), class: 'delete' %>
5
- <%= render 'type_select' %>
6
- <% if @promotion_action.respond_to?(:calculator) %>
7
- <%= render 'calculator_select', path: solidus_friendly_promotions.new_admin_promotion_promotion_action_path(@promotion), promotion_action: @promotion_action %>
8
- <% if @promotion_action.calculator %>
9
- <%=
10
- form_with(
11
- model: @promotion_action,
12
- scope: :promotion_action,
13
- url: solidus_friendly_promotions.admin_promotion_promotion_actions_path(@promotion),
14
- data: { turbo: false }
15
- ) do |form| %>
16
- <%= render 'form', form: form %>
17
- <div class="row">
18
- <div class="col-12">
19
- <%= button_tag t(:add, scope: [:solidus_friendly_promotions, :crud]), class: "btn btn-secondary float-right" %>
20
- </div>
21
- </div>
22
- <% end %>
23
- <% end %>
24
- <% end %>
25
- </div>
26
- <% end %>
@@ -1,22 +0,0 @@
1
-
2
- <div class="promotion_rule promotion-block" id="<%= dom_id promotion_rule %>">
3
- <%= form_with model: promotion_rule, scope: :promotion_rule, url: solidus_friendly_promotions.admin_promotion_promotion_rule_path(@promotion, promotion_rule), method: :patch do |form| %>
4
- <h6 class='promotion-title'><%= promotion_rule.class.model_name.human %></h6>
5
- <% if can?(:destroy, promotion_rule) && promotion_rule.level == level %>
6
- <%= link_to_with_icon 'trash', '', solidus_friendly_promotions.admin_promotion_promotion_rule_path(@promotion, promotion_rule), method: :delete, class: 'delete' %>
7
- <% end %>
8
-
9
- <% param_prefix = "promotion[promotion_rules_attributes][#{promotion_rule.id}]" %>
10
- <%= hidden_field_tag "#{param_prefix}[id]", promotion_rule.id %>
11
- <%= render partial: "spree/shared/error_messages", locals: { target: promotion_rule } %>
12
- <%= render promotion_rule, promotion_rule: promotion_rule, param_prefix: "promotion_rule", form: form, context: level %>
13
-
14
- <% if promotion_rule.updateable? && promotion_rule.level == level %>
15
- <div class="row">
16
- <div class="col-12">
17
- <%= form.submit(t(:update, scope: [:solidus_friendly_promotions, :crud]), class: "btn btn-secondary float-right") %>
18
- </div>
19
- </div>
20
- <% end %>
21
- <% end %>
22
- </div>
@@ -1,20 +0,0 @@
1
- <%= form_with(
2
- model: @promotion_rule || SolidusFriendlyPromotions::PromotionRule.new(promotion: @promotion),
3
- scope: :promotion_rule,
4
- url: solidus_friendly_promotions.new_admin_promotion_promotion_rule_path(@promotion),
5
- method: :get
6
- ) do |form| %>
7
- <%= hidden_field_tag :level, @level %>
8
- <%= form.label :type %>
9
- <%= admin_hint SolidusFriendlyPromotions::PromotionRule.human_attribute_name(:type), t(:promotions, scope: [:solidus_friendly_promotions, :hints, "spree/calculator"]) %>
10
- <%=
11
- form.select :type,
12
- options_for_promotion_rule_types(form.object, level),
13
- {
14
- include_blank: t(:choose_promotion_rule, scope: 'solidus_friendly_promotions')
15
- },
16
- class: 'custom-select fullwidth',
17
- onchange: 'this.form.requestSubmit()',
18
- required: true
19
- %>
20
- <% end %>
@@ -1,24 +0,0 @@
1
- <%= turbo_frame_tag @promotion, "new_#{@level}_promotion_rule" do %>
2
- <div class="promotion_rule promotion-block">
3
- <h6 class='promotion-title'> <%= t(:add_rule, scope: :solidus_friendly_promotions) %></h6>
4
- <%= link_to_with_icon 'trash', '', solidus_friendly_promotions.edit_admin_promotion_path(@promotion), class: 'delete' %>
5
- <%= render 'type_select', level: @level %>
6
- <% flash.each do |severity, message| %>
7
- <%= content_tag(:div, "", data: { controller: :flash, severity: severity, message: message }) %>
8
- <% end %>
9
- <% if @promotion_rule %>
10
- <%= form_with model: @promotion_rule, scope: "promotion_rule", url: solidus_friendly_promotions.admin_promotion_promotion_rules_path(@promotion), data: { turbo: false } do |form| %>
11
- <%= hidden_field_tag :level, @level %>
12
- <%= hidden_field_tag "promotion_rule[type]", @promotion_rule.class.name %>
13
- <%= render @promotion_rule, promotion_rule: @promotion_rule, param_prefix: "promotion_rule", form: form %>
14
-
15
- <div class="row">
16
- <div class="col-12">
17
- <%= form.submit(t(:add, scope: [:solidus_friendly_promotions, :crud]), class: "btn btn-secondary float-right") %>
18
- </div>
19
- </div>
20
-
21
- <% end %>
22
- </div>
23
- <% end %>
24
- <% end %>
@@ -1,3 +0,0 @@
1
- <p>
2
- <%= promotion_rule.class.human_attribute_name(:description) %>
3
- </p>
@@ -1,6 +0,0 @@
1
- <p>
2
- <%= promotion_rule.class.human_attribute_name(:description) %>
3
- </p>
4
- <div class="field">
5
- <%= number_field_tag "#{param_prefix}[preferred_days_ago]", promotion_rule.preferred_days_ago, class: 'fullwidth' %>
6
- </div>
@@ -1,17 +0,0 @@
1
- <p>
2
- <%= promotion_rule.class.human_attribute_name(:description) %>
3
- </p>
4
- <div class="row">
5
- <div class="col-6">
6
- <div class="field">
7
- <%= select_tag "#{param_prefix}[preferred_operator]", options_for_select(promotion_rule.class.operator_options, promotion_rule.preferred_operator), {class: 'custom-select select_item_total fullwidth'} %>
8
- </div>
9
- </div>
10
- <div class="col-6">
11
- <div class="field">
12
- <%= fields_for param_prefix, promotion_rule do |f| %>
13
- <%= render "spree/admin/shared/number_with_currency", f: f, amount_attr: :preferred_amount, currency_attr: :preferred_currency %>
14
- <% end %>
15
- </div>
16
- </div>
17
- </div>
@@ -1,25 +0,0 @@
1
-
2
- <p>
3
- <%= promotion_rule.class.human_attribute_name(:description) %>
4
- </p>
5
- <div class="field promo-rule-option-values">
6
- <div class="param-prefix hidden" data-param-prefix="<%= param_prefix %>"></div>
7
- <div class="row">
8
- <div class="col-6"><%= label_tag nil, Spree::Product.model_name.human %></div>
9
- <div class="col-6"><%= label_tag nil, plural_resource_name(Spree::OptionValue) %></div>
10
- </div>
11
-
12
- <div class="field">
13
- <div data-controller="product-option-values">
14
- <template data-product-option-values-target="template">
15
- <%= render "solidus_friendly_promotions/admin/promotion_rules/rules/line_item_option_value/option_value_fields", product_option_values: [nil, []], form: form %>
16
- </template>
17
- <% form.object.preferred_eligible_values.each do |product_option_values| %>
18
- <%= render "solidus_friendly_promotions/admin/promotion_rules/rules/line_item_option_value/option_value_fields", product_option_values: product_option_values, form: form %>
19
- <% end %>
20
- <div class="mb-3" data-product-option-values-target="links">
21
- <%= link_to "Add Row", "#", class: "btn btn-outline-primary", data: { action: "click->product-option-values#add_row" } %>
22
- </div>
23
- </div>
24
- </div>
25
- </div>
@@ -1,17 +0,0 @@
1
- <p>
2
- <%= promotion_rule.class.human_attribute_name(:description) %>
3
- </p>
4
- <div class="field taxons_rule_taxons">
5
- <%= label_tag "#{param_prefix}_taxon_ids_string", t("solidus_friendly_promotions.taxon_rule.choose_taxons") %>
6
- <%= hidden_field_tag "#{param_prefix}[taxon_ids_string]", promotion_rule.taxon_ids.join(","), class: "taxon_picker fullwidth", id: "product_taxon_ids" %>
7
- </div>
8
- <div class="field">
9
- <div class="field">
10
- <%= label_tag("#{param_prefix}_preferred_match_policy", promotion_rule.class.human_attribute_name(:preferred_match_policy)) %>
11
- <%= select_tag(
12
- "#{param_prefix}[preferred_match_policy]",
13
- options_for_select(I18n.t("solidus_friendly_promotions.promotion_rules.line_item_taxon.match_policies").to_a.map(&:reverse), promotion_rule.preferred_match_policy),
14
- class: "custom-select fullwidth",
15
- ) %>
16
- </div>
17
- </div>
@@ -1,5 +0,0 @@
1
- <div class="field">
2
- <% field_name = "#{param_prefix}[preferred_minimum_quantity]" %>
3
- <%= label_tag field_name, promotion_rule.model_name.human %>
4
- <%= number_field_tag field_name, promotion_rule.preferred_minimum_quantity, class: "fullwidth", min: 1 %>
5
- </div>
@@ -1,15 +0,0 @@
1
- <p>
2
- <%= promotion_rule.class.human_attribute_name(:description) %>
3
- </p>
4
- <div class="row">
5
- <div class="col-6">
6
- <div class="field">
7
- <%= SolidusFriendlyPromotions::Rules::NthOrder.human_attribute_name(:form_text) %>
8
- </div>
9
- </div>
10
- <div class="col-6">
11
- <div class="field">
12
- <%= number_field_tag "#{param_prefix}[preferred_nth_order]", promotion_rule.preferred_nth_order, class: 'fullwidth' %>
13
- </div>
14
- </div>
15
- </div>
@@ -1,3 +0,0 @@
1
- <p>
2
- <%= promotion_rule.class.human_attribute_name(:description) %>
3
- </p>