solidus_legacy_promotions 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +345 -0
  3. data/Rakefile +43 -0
  4. data/app/assets/config/solidus_legacy_promotions/manifest.js +2 -0
  5. data/app/assets/javascripts/spree/backend/edit_promotion.js +7 -0
  6. data/app/assets/javascripts/spree/backend/promotions/activation.js +26 -0
  7. data/app/assets/javascripts/spree/backend/promotions.js +35 -0
  8. data/app/assets/javascripts/spree/backend/templates/promotions/calculators/fields/tiered_flat_rate.hbs +23 -0
  9. data/app/assets/javascripts/spree/backend/templates/promotions/calculators/fields/tiered_percent.hbs +23 -0
  10. data/app/assets/javascripts/spree/backend/templates/promotions/rules/option_values.hbs +12 -0
  11. data/app/assets/javascripts/spree/backend/views/calculators/tiered.js +54 -0
  12. data/app/assets/javascripts/spree/backend/views/order/details_adjustments.js +43 -0
  13. data/app/assets/javascripts/spree/backend/views/promotions/option_values_rule.js +79 -0
  14. data/app/assets/javascripts/spree/backend/views/promotions.js +3 -0
  15. data/app/assets/stylesheets/solidus_legacy_promotions/promotions/_edit.scss +138 -0
  16. data/app/assets/stylesheets/solidus_legacy_promotions/promotions.scss +3 -0
  17. data/app/assets/stylesheets/spree/backend/sections/_adjustments.scss +3 -0
  18. data/app/decorators/solidus_legacy_promotions/controllers/solidus_admin/solidus_admin_adjustments_controller_decorator.rb +20 -0
  19. data/app/decorators/solidus_legacy_promotions/lib/spree_order_state_machine_decorator.rb +18 -0
  20. data/app/decorators/solidus_legacy_promotions/models/spree_adjustment_decorator.rb +76 -0
  21. data/app/decorators/solidus_legacy_promotions/models/spree_calculator_returns_default_refund_amount_decorator.rb +13 -0
  22. data/app/decorators/solidus_legacy_promotions/models/spree_line_item_decorator.rb +11 -0
  23. data/app/decorators/solidus_legacy_promotions/models/spree_order_decorator.rb +28 -0
  24. data/app/decorators/solidus_legacy_promotions/models/spree_order_updater_decorator.rb +40 -0
  25. data/app/decorators/solidus_legacy_promotions/models/spree_product_decorator.rb +16 -0
  26. data/app/decorators/solidus_legacy_promotions/models/spree_promotion_code_batch_decorator.rb +16 -0
  27. data/app/decorators/solidus_legacy_promotions/models/spree_shipment_decorator.rb +13 -0
  28. data/app/helpers/spree/admin/promotions_helper.rb +15 -0
  29. data/app/helpers/spree/promotion_rules_helper.rb +12 -0
  30. data/app/jobs/spree/promotion_code_batch_job.rb +26 -0
  31. data/app/mailers/spree/promotion_code_batch_mailer.rb +15 -0
  32. data/app/models/spree/calculator/distributed_amount.rb +33 -0
  33. data/app/models/spree/calculator/flat_percent_item_total.rb +23 -0
  34. data/app/models/spree/calculator/flexi_rate.rb +22 -0
  35. data/app/models/spree/calculator/percent_on_line_item.rb +13 -0
  36. data/app/models/spree/calculator/tiered_flat_rate.rb +52 -0
  37. data/app/models/spree/calculator/tiered_percent.rb +62 -0
  38. data/app/models/spree/order_contents.rb +36 -0
  39. data/app/models/spree/order_promotion.rb +27 -0
  40. data/app/models/spree/permission_sets/promotion_display.rb +25 -0
  41. data/app/models/spree/permission_sets/promotion_management.rb +25 -0
  42. data/app/models/spree/promotion/actions/create_adjustment.rb +81 -0
  43. data/app/models/spree/promotion/actions/create_item_adjustments.rb +98 -0
  44. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +139 -0
  45. data/app/models/spree/promotion/actions/free_shipping.rb +59 -0
  46. data/app/models/spree/promotion/order_adjustments_recalculator.rb +92 -0
  47. data/app/models/spree/promotion/rules/first_order.rb +36 -0
  48. data/app/models/spree/promotion/rules/first_repeat_purchase_since.rb +36 -0
  49. data/app/models/spree/promotion/rules/item_total.rb +86 -0
  50. data/app/models/spree/promotion/rules/minimum_quantity.rb +59 -0
  51. data/app/models/spree/promotion/rules/nth_order.rb +45 -0
  52. data/app/models/spree/promotion/rules/one_use_per_user.rb +25 -0
  53. data/app/models/spree/promotion/rules/option_value.rb +50 -0
  54. data/app/models/spree/promotion/rules/product.rb +86 -0
  55. data/app/models/spree/promotion/rules/store.rb +26 -0
  56. data/app/models/spree/promotion/rules/taxon.rb +91 -0
  57. data/app/models/spree/promotion/rules/user.rb +34 -0
  58. data/app/models/spree/promotion/rules/user_logged_in.rb +20 -0
  59. data/app/models/spree/promotion/rules/user_role.rb +45 -0
  60. data/app/models/spree/promotion.rb +271 -0
  61. data/app/models/spree/promotion_action.rb +51 -0
  62. data/app/models/spree/promotion_advertiser.rb +10 -0
  63. data/app/models/spree/promotion_category.rb +8 -0
  64. data/app/models/spree/promotion_chooser.rb +34 -0
  65. data/app/models/spree/promotion_code/batch_builder.rb +68 -0
  66. data/app/models/spree/promotion_code.rb +54 -0
  67. data/app/models/spree/promotion_code_batch.rb +18 -0
  68. data/app/models/spree/promotion_finder.rb +9 -0
  69. data/app/models/spree/promotion_handler/cart.rb +75 -0
  70. data/app/models/spree/promotion_handler/coupon.rb +125 -0
  71. data/app/models/spree/promotion_handler/page.rb +26 -0
  72. data/app/models/spree/promotion_handler/shipping.rb +61 -0
  73. data/app/models/spree/promotion_rule.rb +55 -0
  74. data/app/models/spree/promotion_rule_store.rb +10 -0
  75. data/app/models/spree/promotion_rule_taxon.rb +8 -0
  76. data/app/models/spree/promotion_rule_user.rb +10 -0
  77. data/app/subscribers/spree/order_promotion_subscriber.rb +20 -0
  78. data/app/views/spree/order_mailer/cancel_email.html.erb +45 -0
  79. data/app/views/spree/order_mailer/cancel_email.text.erb +16 -0
  80. data/app/views/spree/order_mailer/confirm_email.html.erb +84 -0
  81. data/app/views/spree/order_mailer/confirm_email.text.erb +38 -0
  82. data/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_errored.text.erb +2 -0
  83. data/app/views/spree/promotion_code_batch_mailer/promotion_code_batch_finished.text.erb +2 -0
  84. data/bin/rails +13 -0
  85. data/config/locales/en.yml +101 -0
  86. data/config/locales/promotion_categories.en.yml +6 -0
  87. data/config/locales/promotions.en.yml +6 -0
  88. data/config/routes.rb +28 -0
  89. data/db/migrate/20160101010001_solidus_one_four_promotions.rb +126 -0
  90. data/db/migrate/20161017102621_create_spree_promotion_code_batch.rb +48 -0
  91. data/db/migrate/20180202190713_create_promotion_rule_stores.rb +14 -0
  92. data/db/migrate/20180328172631_add_join_characters_to_promotion_code_batch.rb +15 -0
  93. data/db/migrate/20190106184413_remove_code_from_spree_promotions.rb +46 -0
  94. data/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +20 -0
  95. data/db/migrate/20230322085416_remove_match_policy_from_spree_promotion.rb +7 -0
  96. data/db/migrate/20230325132905_remove_unused_columns_from_promotion_rules.rb +10 -0
  97. data/db/migrate/20231027084517_add_order_promotions_foreign_key.rb +14 -0
  98. data/db/migrate/20240621100123_add_promotion_code_id_to_spree_adjustments.rb +10 -0
  99. data/db/migrate/20240622113334_move_adjustment_eligible_to_legacy_promotions.rb +11 -0
  100. data/lib/components/admin/solidus_admin/orders/show/adjustments/index/source/spree_promotion_action/component.rb +17 -0
  101. data/lib/components/admin/solidus_admin/promotion_categories/index/component.rb +56 -0
  102. data/lib/components/admin/solidus_admin/promotions/index/component.rb +104 -0
  103. data/lib/components/admin/solidus_admin/promotions/index/component.yml +10 -0
  104. data/lib/components/admin/solidus_legacy_promotions/orders/index/component.rb +15 -0
  105. data/lib/components/admin/solidus_legacy_promotions/orders/index/component.yml +20 -0
  106. data/lib/controllers/admin/solidus_admin/promotion_categories_controller.rb +29 -0
  107. data/lib/controllers/admin/solidus_admin/promotions_controller.rb +46 -0
  108. data/lib/controllers/backend/spree/admin/promotion_actions_controller.rb +51 -0
  109. data/lib/controllers/backend/spree/admin/promotion_categories_controller.rb +8 -0
  110. data/lib/controllers/backend/spree/admin/promotion_code_batches_controller.rb +30 -0
  111. data/lib/controllers/backend/spree/admin/promotion_codes_controller.rb +48 -0
  112. data/lib/controllers/backend/spree/admin/promotion_rules_controller.rb +60 -0
  113. data/lib/controllers/backend/spree/admin/promotions_controller.rb +66 -0
  114. data/lib/solidus_legacy_promotions/configuration.rb +115 -0
  115. data/lib/solidus_legacy_promotions/engine.rb +97 -0
  116. data/lib/solidus_legacy_promotions/migrations/promotions_with_code_handlers.rb +68 -0
  117. data/lib/solidus_legacy_promotions/testing_support/factories/calculator_factory.rb +7 -0
  118. data/lib/solidus_legacy_promotions/testing_support/factories/order_factory.rb +22 -0
  119. data/lib/solidus_legacy_promotions/testing_support/factories/order_promotion_factory.rb +8 -0
  120. data/lib/solidus_legacy_promotions/testing_support/factories/promotion_category_factory.rb +7 -0
  121. data/lib/solidus_legacy_promotions/testing_support/factories/promotion_code_factory.rb +8 -0
  122. data/lib/solidus_legacy_promotions/testing_support/factories/promotion_factory.rb +98 -0
  123. data/lib/solidus_legacy_promotions/testing_support/factory_bot.rb +28 -0
  124. data/lib/solidus_legacy_promotions.rb +28 -0
  125. data/lib/tasks/solidus_legacy_promotions/delete_ineligible_adjustments.rake +8 -0
  126. data/lib/views/backend/spree/admin/adjustments/_adjustment.html.erb +24 -0
  127. data/lib/views/backend/spree/admin/orders/_adjustments.html.erb +19 -0
  128. data/lib/views/backend/spree/admin/orders/_order_details.html.erb +32 -0
  129. data/lib/views/backend/spree/admin/orders/confirm.html.erb +59 -0
  130. data/lib/views/backend/spree/admin/promotion_actions/create.js.erb +10 -0
  131. data/lib/views/backend/spree/admin/promotion_actions/destroy.js.erb +1 -0
  132. data/lib/views/backend/spree/admin/promotion_categories/_form.html.erb +14 -0
  133. data/lib/views/backend/spree/admin/promotion_categories/edit.html.erb +10 -0
  134. data/lib/views/backend/spree/admin/promotion_categories/index.html.erb +47 -0
  135. data/lib/views/backend/spree/admin/promotion_categories/new.html.erb +10 -0
  136. data/lib/views/backend/spree/admin/promotion_code_batches/_form_fields.html.erb +22 -0
  137. data/lib/views/backend/spree/admin/promotion_code_batches/download.csv.ruby +8 -0
  138. data/lib/views/backend/spree/admin/promotion_code_batches/index.html.erb +65 -0
  139. data/lib/views/backend/spree/admin/promotion_code_batches/new.html.erb +8 -0
  140. data/lib/views/backend/spree/admin/promotion_codes/index.csv.ruby +8 -0
  141. data/lib/views/backend/spree/admin/promotion_codes/index.html.erb +32 -0
  142. data/lib/views/backend/spree/admin/promotion_codes/new.html.erb +31 -0
  143. data/lib/views/backend/spree/admin/promotion_rules/create.js.erb +8 -0
  144. data/lib/views/backend/spree/admin/promotion_rules/destroy.js.erb +3 -0
  145. data/lib/views/backend/spree/admin/promotions/_actions.html.erb +37 -0
  146. data/lib/views/backend/spree/admin/promotions/_activations_edit.html.erb +22 -0
  147. data/lib/views/backend/spree/admin/promotions/_activations_new.html.erb +43 -0
  148. data/lib/views/backend/spree/admin/promotions/_form.html.erb +67 -0
  149. data/lib/views/backend/spree/admin/promotions/_promotion_action.html.erb +13 -0
  150. data/lib/views/backend/spree/admin/promotions/_promotion_rule.html.erb +12 -0
  151. data/lib/views/backend/spree/admin/promotions/_rules.html.erb +42 -0
  152. data/lib/views/backend/spree/admin/promotions/actions/_create_adjustment.html.erb +2 -0
  153. data/lib/views/backend/spree/admin/promotions/actions/_create_item_adjustments.html.erb +6 -0
  154. data/lib/views/backend/spree/admin/promotions/actions/_create_quantity_adjustments.html.erb +10 -0
  155. data/lib/views/backend/spree/admin/promotions/actions/_free_shipping.html.erb +0 -0
  156. data/lib/views/backend/spree/admin/promotions/actions/_promotion_calculators_with_custom_fields.html.erb +29 -0
  157. data/lib/views/backend/spree/admin/promotions/calculators/_default_fields.html.erb +6 -0
  158. data/lib/views/backend/spree/admin/promotions/calculators/distributed_amount/_fields.html.erb +56 -0
  159. data/lib/views/backend/spree/admin/promotions/calculators/flat_rate/_fields.html.erb +6 -0
  160. data/lib/views/backend/spree/admin/promotions/calculators/tiered_flat_rate/_fields.html.erb +30 -0
  161. data/lib/views/backend/spree/admin/promotions/calculators/tiered_percent/_fields.html.erb +30 -0
  162. data/lib/views/backend/spree/admin/promotions/edit.html.erb +40 -0
  163. data/lib/views/backend/spree/admin/promotions/index.html.erb +124 -0
  164. data/lib/views/backend/spree/admin/promotions/new.html.erb +14 -0
  165. data/lib/views/backend/spree/admin/promotions/rules/_first_order.html.erb +0 -0
  166. data/lib/views/backend/spree/admin/promotions/rules/_first_repeat_purchase_since.html.erb +13 -0
  167. data/lib/views/backend/spree/admin/promotions/rules/_item_total.html.erb +14 -0
  168. data/lib/views/backend/spree/admin/promotions/rules/_minimum_quantity.html.erb +5 -0
  169. data/lib/views/backend/spree/admin/promotions/rules/_nth_order.html.erb +12 -0
  170. data/lib/views/backend/spree/admin/promotions/rules/_one_use_per_user.html.erb +0 -0
  171. data/lib/views/backend/spree/admin/promotions/rules/_option_value.html.erb +13 -0
  172. data/lib/views/backend/spree/admin/promotions/rules/_product.html.erb +15 -0
  173. data/lib/views/backend/spree/admin/promotions/rules/_store.html.erb +6 -0
  174. data/lib/views/backend/spree/admin/promotions/rules/_taxon.html.erb +9 -0
  175. data/lib/views/backend/spree/admin/promotions/rules/_user.html.erb +4 -0
  176. data/lib/views/backend/spree/admin/promotions/rules/_user_logged_in.html.erb +0 -0
  177. data/lib/views/backend/spree/admin/promotions/rules/_user_role.html.erb +12 -0
  178. data/solidus_legacy_promotions.gemspec +29 -0
  179. metadata +262 -0
@@ -0,0 +1,22 @@
1
+ <% if @promotion.apply_automatically? %>
2
+ <p>
3
+ <%= t('.auto') %>
4
+ </p>
5
+ <% end %>
6
+
7
+ <% if @promotion.codes.count == 1 %>
8
+ <p>
9
+ <%= t('.single_code_html', code: @promotion.codes.first.value) %>
10
+ </p>
11
+ <% elsif @promotion.codes.count > 1 %>
12
+ <p>
13
+ <%= t('.multiple_codes_html', count: @promotion.codes.count) %>
14
+ </p>
15
+ <% end %>
16
+
17
+ <% if @promotion.path %>
18
+ <div class="field">
19
+ <%= f.label :path %>
20
+ <%= f.text_field :path, class: "fullwidth" %>
21
+ </div>
22
+ <% end %>
@@ -0,0 +1,43 @@
1
+ <% activation_type = params[:activation_type] || 'single_code' %>
2
+ <div class="row" id="js_promotion_activation">
3
+ <div class="col-3">
4
+ <div class="form-check">
5
+ <label class="form-check-label">
6
+ <%= radio_button_tag('activation_type', 'auto', activation_type == 'auto') %>
7
+ <%= t('.auto') %> <%= f.field_hint :promo_code_will_be_disabled %>
8
+ </label>
9
+ </div>
10
+ <div class="form-check">
11
+ <label class="form-check-label">
12
+ <%= radio_button_tag('activation_type', 'single_code', activation_type == 'single_code') %>
13
+ <%= t('.single_code') %>
14
+ </label>
15
+ </div>
16
+ <div class="form-check">
17
+ <label class="form-check-label">
18
+ <%= radio_button_tag('activation_type', 'multiple_codes', activation_type == 'multiple_codes') %>
19
+ <%= t('.multiple_codes') %>
20
+ </label>
21
+ </div>
22
+ </div>
23
+ <div class="col-9">
24
+ <input name="promotion[apply_automatically]" type="hidden" value="0">
25
+ <div data-activation-type="auto">
26
+ <input name="promotion[apply_automatically]" type="hidden" value="1">
27
+ </div>
28
+
29
+ <div data-activation-type="single_code">
30
+ <div class="field">
31
+ <%= label_tag :single_code, Spree::PromotionCode.model_name.human, class: "required" %>
32
+ <%= text_field_tag :single_code, @promotion.codes.first.try!(:value), class: "fullwidth", required: true %>
33
+ </div>
34
+ </div>
35
+
36
+ <div data-activation-type="multiple_codes">
37
+ <%= fields_for :promotion_code_batch, @promotion_code_batch do |batch| %>
38
+ <%= render partial: 'spree/admin/promotion_code_batches/form_fields', locals: {f: f, batch: batch, promotion_id: params[:promotion_id]} %>
39
+ <% end %>
40
+ </div>
41
+
42
+ </div>
43
+ </div>
@@ -0,0 +1,67 @@
1
+ <%= render partial: 'spree/shared/error_messages', locals: { target: @promotion } %>
2
+ <fieldset class="form-group no-border-bottom no-border-top">
3
+ <div class="row">
4
+ <div id="general_fields" class="col-9">
5
+ <div class="row">
6
+ <div class="col-12">
7
+ <%= f.field_container :name do %>
8
+ <%= f.label :name, class: 'required' %>
9
+ <%= f.text_field :name, class: 'fullwidth', required: true %>
10
+ <% end %>
11
+
12
+ <%= f.field_container :description do %>
13
+ <%= f.label :description %><br>
14
+ <%= f.text_area :description, rows: 7, class: 'fullwidth' %>
15
+ <span class="info">
16
+ <%= t('spree.character_limit') %>
17
+ </span>
18
+ <% end %>
19
+
20
+ <%= f.field_container :category do %>
21
+ <%= f.label :promotion_category_id, Spree::PromotionCategory.model_name.human %><br>
22
+ <%= f.collection_select(:promotion_category_id, @promotion_categories, :id, :name, { include_blank: t('spree.match_choices.none') }, { class: 'custom-select fullwidth' }) %>
23
+ <% end %>
24
+ </div>
25
+ </div>
26
+ </div>
27
+
28
+ <div id="expiry_fields" class="col-3">
29
+ <%= f.field_container :overall_usage_limit do %>
30
+ <%= f.label :usage_limit %><br>
31
+ <%= f.number_field :usage_limit, min: 0, class: 'fullwidth' %><br>
32
+ <span class="info">
33
+ <%= t('spree.current_promotion_usage', count: @promotion.usage_count) %>
34
+ </span>
35
+ <% end %>
36
+
37
+ <% if @promotion.persisted? %>
38
+ <%= f.field_container :per_code_usage_limit do %>
39
+ <%= f.label :per_code_usage_limit %><br>
40
+ <%= f.number_field :per_code_usage_limit, min: 0, class: 'fullwidth' %><br>
41
+ <% end %>
42
+ <% end %>
43
+
44
+ <div id="starts_at_field" class="field">
45
+ <%= f.label :starts_at %>
46
+ <%= f.field_hint :starts_at %>
47
+ <%= f.text_field :starts_at, value: datepicker_field_value(@promotion.starts_at, with_time: true), placeholder: t(".starts_at_placeholder"), class: 'datepicker datepicker-from fullwidth', data: { :'enable-time' => true, :'default-hour' => 0 } %>
48
+ </div>
49
+
50
+ <div id="expires_at_field" class="field">
51
+ <%= f.label :expires_at %>
52
+ <%= f.field_hint :expires_at %>
53
+ <%= f.text_field :expires_at, value: datepicker_field_value(@promotion.expires_at, with_time: true), placeholder: t(".expires_at_placeholder"), class: 'datepicker datepicker-to fullwidth', data: { :'enable-time' => true, :'default-hour' => 0 } %>
54
+ </div>
55
+ </div>
56
+ </div>
57
+ </fieldset>
58
+
59
+ <fieldset class="form-group no-border-bottom">
60
+ <legend><%= t '.activation' %></legend>
61
+
62
+ <% if @promotion.new_record? %>
63
+ <%= render 'spree/admin/promotions/activations_new', f: f %>
64
+ <% else %>
65
+ <%= render 'spree/admin/promotions/activations_edit', f: f %>
66
+ <% end %>
67
+ </fieldset>
@@ -0,0 +1,13 @@
1
+ <div class="promotion_action promotion-block <%= promotion_action.model_name.element %>" id="<%= dom_id promotion_action %>">
2
+ <h6 class="promotion-title"><%= promotion_action.class.human_attribute_name(:description) %></h6>
3
+ <% if can?(:destroy, promotion_action) %>
4
+ <%= link_to_with_icon 'trash', '', spree.admin_promotion_promotion_action_path(@promotion, promotion_action), remote: true, method: :delete, class: 'delete' %>
5
+ <% end %>
6
+
7
+ <% param_prefix = "promotion[promotion_actions_attributes][#{promotion_action.id}]" %>
8
+ <%= hidden_field_tag "#{param_prefix}[id]", promotion_action.id %>
9
+
10
+ <%= render partial: "spree/shared/error_messages", locals: { target: promotion_action } %>
11
+ <%= render partial: promotion_action.to_partial_path,
12
+ locals: { promotion_action: promotion_action, param_prefix: param_prefix } %>
13
+ </div>
@@ -0,0 +1,12 @@
1
+ <div class="promotion_rule promotion-block col-12" id="<%= dom_id promotion_rule %>">
2
+ <% type_name = promotion_rule.model_name.element %>
3
+ <h6 class='promotion-title <%= 'no-text' if type_name.in? %w(user_logged_in first_order one_use_per_user) %>'><%= promotion_rule.class.human_attribute_name(:description) %></h6>
4
+ <% if can?(:destroy, promotion_rule) %>
5
+ <%= link_to_with_icon 'trash', '', spree.admin_promotion_promotion_rule_path(@promotion, promotion_rule), remote: true, method: :delete, class: 'delete' %>
6
+ <% end %>
7
+
8
+ <% param_prefix = "promotion[promotion_rules_attributes][#{promotion_rule.id}]" %>
9
+ <%= hidden_field_tag "#{param_prefix}[id]", promotion_rule.id %>
10
+ <%= render partial: "spree/shared/error_messages", locals: { target: promotion_rule } %>
11
+ <%= render partial: promotion_rule.to_partial_path, locals: { promotion_rule: promotion_rule, param_prefix: param_prefix } %>
12
+ </div>
@@ -0,0 +1,42 @@
1
+ <fieldset id="rule_fields" class="no-border-bottom no-border-top">
2
+
3
+ <%= form_tag spree.admin_promotion_promotion_rules_path(@promotion), remote: true, id: 'new_product_rule_form' do %>
4
+ <fieldset>
5
+ <legend align="center"><%= t('spree.rules') %></legend>
6
+
7
+ <% if can?(:update, @promotion) %>
8
+ <div class="field">
9
+ <%= label_tag :promotion_rule_type, t('spree.discount_rules') %>
10
+ <%= select_tag('promotion_rule[type]', options_for_promotion_rule_types(@promotion), include_blank: t(:choose_promotion_rule, scope: 'spree'), class: 'custom-select fullwidth', required: true) %>
11
+ </div>
12
+ <div class="filter-actions actions">
13
+ <%= button_tag t('spree.actions.add'), class: 'btn btn-primary' %>
14
+ </div>
15
+ <% end %>
16
+ </fieldset>
17
+ <% end %>
18
+
19
+ <%= form_for @promotion, url: object_url, method: :put do |f| %>
20
+ <fieldset class="no-border-top">
21
+ <div id="rules" class="filter_list">
22
+ <% if @promotion.rules.any? %>
23
+ <div class="col-12">
24
+ <div class="row">
25
+ <%= render partial: 'promotion_rule', collection: @promotion.rules, locals: {} %>
26
+ </div>
27
+ </div>
28
+ <% else %>
29
+ <div class="no-objects-found">
30
+ <%= t('spree.no_rules_added') %>
31
+ </div>
32
+ <% end %>
33
+ </div>
34
+
35
+ <% if can?(:update, @promotion) %>
36
+ <div class="promotion-update filter-actions actions">
37
+ <%= button_tag t('spree.actions.update'), class: 'btn btn-primary' %>
38
+ </div>
39
+ <% end %>
40
+ </fieldset>
41
+ <% end %>
42
+ </fieldset>
@@ -0,0 +1,2 @@
1
+ <%= render partial: 'spree/admin/promotions/actions/promotion_calculators_with_custom_fields',
2
+ locals: { calculators: promotion_action.available_calculators, promotion_action: promotion_action, param_prefix: param_prefix } %>
@@ -0,0 +1,6 @@
1
+ <%= render(
2
+ "spree/admin/promotions/actions/promotion_calculators_with_custom_fields",
3
+ calculators: promotion_action.available_calculators,
4
+ promotion_action: promotion_action,
5
+ param_prefix: param_prefix
6
+ ) %>
@@ -0,0 +1,10 @@
1
+ <div class="field">
2
+ <% field_name = "#{param_prefix}[preferred_group_size]" %>
3
+ <%= label_tag field_name, t('spree.group_size') %>
4
+ <%= number_field_tag field_name, promotion_action.preferred_group_size, class: "fullwidth", min: 1 %>
5
+ </div>
6
+
7
+ <%= render "spree/admin/promotions/actions/promotion_calculators_with_custom_fields",
8
+ calculators: promotion_action.available_calculators,
9
+ promotion_action: promotion_action,
10
+ param_prefix: param_prefix %>
@@ -0,0 +1,29 @@
1
+ <div class="calculator-fields js-calculator-fields row">
2
+ <div class="col-6">
3
+ <div class="field">
4
+ <% field_name = "#{param_prefix}[calculator_type]" %>
5
+ <%= label_tag field_name, t('spree.admin.promotions.actions.calculator_label') %>
6
+ <%= select_tag field_name,
7
+ options_from_collection_for_select(calculators, :to_s, :description, promotion_action.calculator.type),
8
+ class: 'type-select js-calculator-type custom-select fullwidth' %>
9
+ </div>
10
+ </div>
11
+ <div class="col-6">
12
+ <div class="settings">
13
+ <% calculators.each do |calculator_class| %>
14
+ <% calculator = promotion_action.calculator.class == calculator_class ? promotion_action.calculator : calculator_class.new %>
15
+ <div class="js-calculator-preferences" data-calculator-type="<%= calculator_class %>">
16
+ <% type_name = calculator.type.demodulize.underscore %>
17
+ <% if lookup_context.exists?("fields",
18
+ ["spree/admin/promotions/calculators/#{type_name}"], true) %>
19
+ <%= render "spree/admin/promotions/calculators/#{type_name}/fields",
20
+ calculator: calculator, prefix: param_prefix %>
21
+ <% else %>
22
+ <%= render "spree/admin/promotions/calculators/default_fields",
23
+ calculator: calculator, prefix: param_prefix %>
24
+ <% end %>
25
+ </div>
26
+ <% end %>
27
+ </div>
28
+ </div>
29
+ </div>
@@ -0,0 +1,6 @@
1
+ <% calculator.admin_form_preference_names.map do |name| %>
2
+ <%= render "spree/admin/shared/preference_fields/#{calculator.preference_type(name)}",
3
+ name: "#{prefix}[calculator_attributes][preferred_#{name}]",
4
+ value: calculator.get_preference(name),
5
+ label: t(name.to_s, scope: 'spree', default: name.to_s.humanize) %>
6
+ <% end %>
@@ -0,0 +1,56 @@
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>
7
+
8
+ <div class="field">
9
+ <p>
10
+ <%= admin_hint(
11
+ calculator.model_name.human,
12
+ """
13
+ <p>
14
+ This amount will be distributed to line items weighted relative to
15
+ their price. More expensive line items will receive a greater share
16
+ of the adjustment.
17
+ </p>
18
+
19
+ <p>
20
+ For example, with three line items and a preferred amount of $15 we
21
+ would end up with the following distribution:
22
+ </p>
23
+
24
+ <table>
25
+ <thead>
26
+ <tr>
27
+ <th></th>
28
+ <th>Price</th>
29
+ <th>Weighted Adj.</th>
30
+ </tr>
31
+ </thead>
32
+ <tbody>
33
+ <tr>
34
+ <td>Socks</td>
35
+ <td>$5</td>
36
+ <td>-$1.5</td>
37
+ </tr>
38
+ <tr>
39
+ <td>Shoes</td>
40
+ <td>$30</td>
41
+ <td>-$9</td>
42
+ </tr>
43
+ <tr>
44
+ <td>Slippers</td>
45
+ <td>$15</td>
46
+ <td>-$4.5</td>
47
+ </tr>
48
+ </tbody>
49
+ </table>
50
+ """
51
+ ) %>
52
+
53
+ This amount will be the <strong>total</strong> discount spread amongst all
54
+ of the line items.
55
+ </p>
56
+ </div>
@@ -0,0 +1,6 @@
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>
@@ -0,0 +1,30 @@
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, label: t('spree.base_amount') %>
4
+
5
+ <div class="field">
6
+ <%= label_tag(
7
+ "#{prefix}[calculator_attributes][preferred_currency]",
8
+ t('spree.currency')
9
+ ) %>
10
+ <%= select_tag(
11
+ "#{prefix}[calculator_attributes][preferred_currency]",
12
+ options_for_select(
13
+ Spree::Config.available_currencies,
14
+ calculator.preferred_currency || Spree::Config[:currency]
15
+ ),
16
+ { class: 'custom-select fullwidth' }
17
+ ) %>
18
+ </div>
19
+
20
+ <div class="field">
21
+ <%= label_tag nil, t('spree.tiers') %>
22
+ <div class="js-tiered-calculator">
23
+ <%= content_tag :div, nil, class: "js-tiers", data: {
24
+ 'original-tiers' => Hash[calculator.preferred_tiers.sort],
25
+ 'form-prefix' => prefix,
26
+ 'calculator' => 'tiered_flat_rate'
27
+ } %>
28
+ <a class="button js-add-tier"><%= t('spree.actions.add') %></a>
29
+ </div>
30
+ </div>
@@ -0,0 +1,30 @@
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, label: t('spree.base_percent') %>
4
+
5
+ <div class="field">
6
+ <%= label_tag(
7
+ "#{prefix}[calculator_attributes][preferred_currency]",
8
+ t('spree.currency')
9
+ ) %>
10
+ <%= select_tag(
11
+ "#{prefix}[calculator_attributes][preferred_currency]",
12
+ options_for_select(
13
+ Spree::Config.available_currencies,
14
+ calculator.preferred_currency || Spree::Config[:currency]
15
+ ),
16
+ { class: 'custom-select fullwidth' }
17
+ ) %>
18
+ </div>
19
+
20
+ <div class="field">
21
+ <%= label_tag nil, t('spree.tiers') %>
22
+ <div class="js-tiered-calculator">
23
+ <%= content_tag :div, nil, class: "js-tiers", data: {
24
+ 'original-tiers' => Hash[calculator.preferred_tiers.sort],
25
+ 'form-prefix' => prefix,
26
+ 'calculator' => 'tiered_percent'
27
+ } %>
28
+ <a class="button js-add-tier"><%= t('spree.actions.add') %></a>
29
+ </div>
30
+ </div>
@@ -0,0 +1,40 @@
1
+ <% admin_layout "full-width" %>
2
+
3
+ <% admin_breadcrumb(link_to plural_resource_name(Spree::Promotion), spree.admin_promotions_path) %>
4
+ <% admin_breadcrumb(@promotion.name) %>
5
+
6
+ <% content_for :page_actions do %>
7
+ <li>
8
+ <% if can?(:show, Spree::PromotionCode) %>
9
+ <%= link_to t('spree.view_promotion_codes_list'), admin_promotion_promotion_codes_path(promotion_id: @promotion.id), class: 'btn btn-primary' %>
10
+
11
+ <%= link_to t('spree.download_promotion_codes_list'), admin_promotion_promotion_codes_path(promotion_id: @promotion.id, format: :csv), class: 'btn btn-primary' %>
12
+ <% end %>
13
+
14
+ <% if can?(:show, Spree::PromotionCodeBatch) %>
15
+ <%= link_to plural_resource_name(Spree::PromotionCodeBatch), admin_promotion_promotion_code_batches_path(promotion_id: @promotion.id), class: 'btn btn-primary' %>
16
+ <% end %>
17
+ </li>
18
+ <% end %>
19
+
20
+ <% content_for :head do %>
21
+ <%= stylesheet_link_tag 'solidus_legacy_promotions/promotions' %>
22
+ <%= javascript_include_tag 'spree/backend/edit_promotion' %>
23
+ <% end %>
24
+
25
+ <%= form_for @promotion, url: object_url, method: :put do |f| %>
26
+ <%= render partial: 'form', locals: { f: f } %>
27
+ <% if can?(:update, @promotion) %>
28
+ <%= render partial: 'spree/admin/shared/edit_resource_links' %>
29
+ <% end %>
30
+ <% end %>
31
+
32
+ <div id="promotion-filters" class="row">
33
+ <div id="rules_container" class="col-6">
34
+ <%= render partial: 'rules' %>
35
+ </div>
36
+
37
+ <div id="actions_container" class="col-6">
38
+ <%= render partial: 'actions' %>
39
+ </div>
40
+ </div>
@@ -0,0 +1,124 @@
1
+ <% admin_breadcrumb(plural_resource_name(Spree::Promotion)) %>
2
+
3
+ <% content_for :page_actions do %>
4
+ <% if can? :create, Spree::Promotion %>
5
+ <li>
6
+ <%= link_to t('spree.new_promotion'), spree.new_admin_promotion_path, class: 'btn btn-primary' %>
7
+ </li>
8
+ <% end %>
9
+ <% end %>
10
+
11
+ <% content_for :table_filter_title do %>
12
+ <%= t('spree.search') %>
13
+ <% end %>
14
+
15
+ <% content_for :table_filter do %>
16
+ <div data-hook="admin_promotions_index_search">
17
+ <%= search_form_for [:admin, @search] do |f| %>
18
+ <div class="row">
19
+ <div class="col-4">
20
+ <div class="field">
21
+ <%= label_tag :q_name_cont, Spree::Promotion.human_attribute_name(:name) %>
22
+ <%= f.text_field :name_cont, tabindex: 1 %>
23
+ </div>
24
+ </div>
25
+
26
+ <div class="col-2">
27
+ <div class="field">
28
+ <%= label_tag :q_codes_value_cont, Spree::Promotion.human_attribute_name(:code) %>
29
+ <%= f.text_field :codes_value_cont, tabindex: 1 %>
30
+ </div>
31
+ </div>
32
+
33
+ <div class="col-2">
34
+ <div class="field">
35
+ <%= label_tag :q_path_cont, Spree::Promotion.human_attribute_name(:path) %>
36
+ <%= f.text_field :path_cont, tabindex: 1 %>
37
+ </div>
38
+ </div>
39
+
40
+ <div class="col-2">
41
+ <div class="field">
42
+ <%= label_tag :q_promotion_category_id_eq, Spree::PromotionCategory.model_name.human %><br>
43
+ <%= f.collection_select(:promotion_category_id_eq, @promotion_categories, :id, :name, { include_blank: t('spree.match_choices.all') }, { class: 'custom-select fullwidth' }) %>
44
+ </div>
45
+ </div>
46
+
47
+ <div class="col-2">
48
+ <div class="field">
49
+ <%= label_tag :active, t('spree.active') %><br>
50
+ <%= f.check_box :active, label: false, as: :boolean, checked_value: true %>
51
+ </div>
52
+ </div>
53
+ </div>
54
+
55
+ <div class="clearfix"></div>
56
+
57
+ <div class="actions filter-actions">
58
+ <div data-hook="admin_promotions_index_search_buttons">
59
+ <%= button_tag t('spree.filter_results'), class: 'btn btn-primary' %>
60
+ </div>
61
+ </div>
62
+ <% end %>
63
+ </div>
64
+ <% end %>
65
+
66
+ <%= paginate @promotions, theme: "solidus_admin" %>
67
+
68
+ <% if @promotions.length > 0 %>
69
+ <table class="index">
70
+ <thead>
71
+ <tr>
72
+ <th><%= Spree::Promotion.human_attribute_name(:name) %></th>
73
+ <th><%= Spree::Promotion.human_attribute_name(:code) %></th>
74
+ <th><%= Spree::Promotion.human_attribute_name(:status) %></th>
75
+ <th><%= Spree::Promotion.human_attribute_name(:usage_limit) %></th>
76
+ <th><%= Spree::Promotion.human_attribute_name(:uses) %></th>
77
+ <th><%= Spree::Promotion.human_attribute_name(:starts_at) %></th>
78
+ <th><%= Spree::Promotion.human_attribute_name(:expires_at) %></th>
79
+ <th class="actions"></th>
80
+ </tr>
81
+ </thead>
82
+ <tbody>
83
+ <% @promotions.each do |promotion| %>
84
+ <tr id="<%= spree_dom_id promotion %>">
85
+ <td><%= promotion.name %></td>
86
+ <td>
87
+ <%= (promotion.codes.size == 1) ? promotion.codes.pluck(:value).first : t('spree.number_of_codes', count: promotion.codes.size) %>
88
+ </td>
89
+ <td>
90
+ <span class="pill pill-<%= promotion.active? ? 'active' : 'inactive' %>">
91
+ <%= t(admin_promotion_status(promotion), scope: 'spree.admin.promotion_status') %>
92
+ </span>
93
+ </td>
94
+ <td>
95
+ <%= promotion.usage_limit.nil? ? "∞" : promotion.usage_limit %>
96
+ </td>
97
+ <td>
98
+ <%= promotion.usage_count %>
99
+ </td>
100
+ <td>
101
+ <%= promotion.starts_at.to_fs(:long) if promotion.starts_at %>
102
+ </td>
103
+ <td>
104
+ <%= promotion.expires_at.to_fs(:long) if promotion.expires_at %>
105
+ </td>
106
+ <td class="actions">
107
+ <% if can?(:edit, promotion) %>
108
+ <%= link_to_edit promotion, no_text: true %>
109
+ <% end %>
110
+ <% if can?(:destroy, promotion) %>
111
+ <%= link_to_delete promotion, no_text: true %>
112
+ <% end %>
113
+ </td>
114
+ </tr>
115
+ <% end %>
116
+ </tbody>
117
+ </table>
118
+ <% else %>
119
+ <div class="no-objects-found">
120
+ <%= render 'spree/admin/shared/no_objects_found',
121
+ resource: Spree::Promotion,
122
+ new_resource_url: new_object_url %>
123
+ </div>
124
+ <% end %>
@@ -0,0 +1,14 @@
1
+ <% admin_layout "full-width" %>
2
+
3
+ <% admin_breadcrumb(link_to plural_resource_name(Spree::Promotion), spree.admin_promotions_path) %>
4
+ <% admin_breadcrumb(t('spree.new_promotion')) %>
5
+
6
+ <% content_for :head do %>
7
+ <%= stylesheet_link_tag 'solidus_legacy_promotions/promotions' %>
8
+ <%= javascript_include_tag 'spree/backend/edit_promotion' %>
9
+ <% end %>
10
+
11
+ <%= form_for @promotion, url: collection_url do |f| %>
12
+ <%= render partial: 'form', locals: { f: f } %>
13
+ <%= render partial: 'spree/admin/shared/new_resource_links' %>
14
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <div class="row">
2
+ <div class="col-6">
3
+ <div class="field">
4
+ <%= Spree::Promotion::Rules::FirstRepeatPurchaseSince.human_attribute_name(:form_text) %>
5
+ </div>
6
+ </div>
7
+
8
+ <div class="col-6">
9
+ <div class="field">
10
+ <%= number_field_tag "#{param_prefix}[preferred_days_ago]", promotion_rule.preferred_days_ago, class: 'fullwidth' %>
11
+ </div>
12
+ </div>
13
+ </div>
@@ -0,0 +1,14 @@
1
+ <div class="row">
2
+ <div class="col-6">
3
+ <div class="field">
4
+ <%= 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'} %>
5
+ </div>
6
+ </div>
7
+ <div class="col-6">
8
+ <div class="field">
9
+ <%= fields_for param_prefix, promotion_rule do |f| %>
10
+ <%= render "spree/admin/shared/number_with_currency", f: f, amount_attr: :preferred_amount, currency_attr: :preferred_currency %>
11
+ <% end %>
12
+ </div>
13
+ </div>
14
+ </div>
@@ -0,0 +1,5 @@
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>
@@ -0,0 +1,12 @@
1
+ <div class="row">
2
+ <div class="col-6">
3
+ <div class="field">
4
+ <%= Spree::Promotion::Rules::NthOrder.human_attribute_name(:form_text) %>
5
+ </div>
6
+ </div>
7
+ <div class="col-6">
8
+ <div class="field">
9
+ <%= number_field_tag "#{param_prefix}[preferred_nth_order]", promotion_rule.preferred_nth_order, class: 'fullwidth' %>
10
+ </div>
11
+ </div>
12
+ </div>
@@ -0,0 +1,13 @@
1
+ <div class="field promo-rule-option-values">
2
+ <div class="param-prefix hidden" data-param-prefix="<%= param_prefix %>"></div>
3
+ <div class="row">
4
+ <div class="col-6"><%= label_tag nil, Spree::Product.model_name.human %></div>
5
+ <div class="col-6"><%= label_tag nil, plural_resource_name(Spree::OptionValue) %></div>
6
+ </div>
7
+
8
+ <%= content_tag :div, nil, class: "js-promo-rule-option-values",
9
+ data: { :'original-option-values' => promotion_rule.preferred_eligible_values } %>
10
+
11
+ <button class="button js-add-promo-rule-option-value"><%= t('spree.actions.add') %></button>
12
+
13
+ </div>