solidus_friendly_promotions 1.9.0 → 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +0 -3
  3. data/CHANGELOG.md +16 -2
  4. data/Gemfile +2 -0
  5. data/Rakefile +14 -3
  6. data/app/jobs/solidus_friendly_promotions/promotion_code_batch_job.rb +1 -1
  7. data/app/models/solidus_friendly_promotions/conditions/line_item_product.rb +4 -0
  8. data/app/models/solidus_friendly_promotions/conditions/line_item_taxon.rb +4 -0
  9. data/app/views/solidus_friendly_promotions/admin/promotions/_table_filter.html.erb +5 -5
  10. data/db/migrate/20240409093831_rename_promotion_rules_to_conditions.rb +48 -0
  11. data/db/migrate/20240506142650_rename_friendly_promotion_actions_to_friendly_benefits.rb +35 -0
  12. data/db/migrate/20240506142651_change_calculable_types.rb +17 -0
  13. data/db/migrate/20240508080834_add_benefit_reference_to_conditions.rb +29 -0
  14. data/db/migrate/20240508131514_remove_conditions_promotion_id.rb +5 -0
  15. data/db/migrate/20240612114132_update_column_comments_for_conditions.rb +1 -1
  16. data/db/migrate/20240612115209_update_column_comments_for_condition_stores.rb +1 -1
  17. data/db/migrate/20240612115749_update_column_comments_for_condition_products.rb +1 -1
  18. data/db/migrate/20240612120411_update_column_comments_for_condition_taxons.rb +1 -1
  19. data/db/migrate/20240612121049_update_column_comments_for_condition_users.rb +1 -1
  20. data/lib/generators/solidus_friendly_promotions/install/templates/initializer.rb +1 -72
  21. data/lib/solidus_friendly_promotions/configuration.rb +78 -11
  22. data/lib/solidus_friendly_promotions/engine.rb +6 -0
  23. data/lib/solidus_friendly_promotions/environment_extension.rb +39 -0
  24. data/lib/solidus_friendly_promotions/version.rb +1 -1
  25. data/solidus_friendly_promotions.gemspec +2 -1
  26. metadata +24 -8
  27. data/db/migrate/20240409093831_add_action_reference_to_rules.rb +0 -34
  28. data/db/migrate/20240506142650_remove_promotion_rules_promotion_id.rb +0 -5
  29. data/db/migrate/20240508080834_rename_promotion_rules_to_conditions.rb +0 -19
  30. data/db/migrate/20240508131514_rename_friendly_promotion_actions_to_friendly_benefits.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c80d1d515ec8f0e3b4a5742c3715d92394e054b7b53bc41df7b8ba0c0532824
4
- data.tar.gz: 2aa767f69a6df858b9ccf19cda5c65db70770feb3a087ca0fbc62f6d82ce4e37
3
+ metadata.gz: b1d63ce9c998edebedc88fa30880ca469075882379c83e7d8b6400422b1c788a
4
+ data.tar.gz: b7baf6e466a970deb57e03c73ebcb138124fbe5df6fb34fd969d78e2f8ddfc4b
5
5
  SHA512:
6
- metadata.gz: 80d3369aed9485a308424965906944f8ccc10159fd125da74a1f5446866727c6b8df986df7c13d0bceac1a8e24a191383ac18bc011c7fd7962ca03f3168ec1cf
7
- data.tar.gz: 2dfd860061b46abd2324e86cc4e3bd89a8627b57097484c121fa4bc7282c7a976f7472b3f2033df2dddc5daf85f2af060bb6531ff9080f2321ae7b4a0bdafc69
6
+ metadata.gz: 86b3fb7b6c95683987c2dc421e4d9d06c7ef5893e4d30dcf0b9bfde07ba0e940f1e7190fc991f0cfbc012263263fd5db40441543b4edab3ef6114c5958341f19
7
+ data.tar.gz: ffd6bfbd56c2a0a0f64bc5f00dbc9f332c9c929ab004e675347d500a650a93f952d37d8014a59e3f6a26bd2b0bd1b4fcf156ced24a0199e4f4056e38ae17029a
data/.circleci/config.yml CHANGED
@@ -21,7 +21,6 @@ jobs:
21
21
  - checkout
22
22
  - solidusio_extensions/dependencies
23
23
  - solidusio_extensions/run-tests-solidus-current
24
- - solidusio_extensions/run-tests-solidus-main
25
24
  run-specs-with-postgres:
26
25
  executor:
27
26
  name: solidusio_extensions/postgres
@@ -31,7 +30,6 @@ jobs:
31
30
  - checkout
32
31
  - solidusio_extensions/dependencies
33
32
  - solidusio_extensions/run-tests-solidus-current
34
- - solidusio_extensions/run-tests-solidus-main
35
33
  run-specs-with-sqlite:
36
34
  executor:
37
35
  name: solidusio_extensions/sqlite
@@ -41,7 +39,6 @@ jobs:
41
39
  - checkout
42
40
  - solidusio_extensions/dependencies
43
41
  - solidusio_extensions/run-tests-solidus-current
44
- - solidusio_extensions/run-tests-solidus-main
45
42
  workflows:
46
43
  Run specs on supported Solidus versions:
47
44
  jobs:
data/CHANGELOG.md CHANGED
@@ -1,11 +1,21 @@
1
1
  # Changelog
2
2
 
3
- ## [v1.9.0](https://github.com/friendlycart/solidus_friendly_promotions/tree/v1.9.0) (2024-06-13)
3
+ ## [v1.9.2](https://github.com/friendlycart/solidus_friendly_promotions/tree/v1.9.2) (2024-06-28)
4
4
 
5
- [Full Changelog](https://github.com/friendlycart/solidus_friendly_promotions/compare/v1.0.1...v1.9.0)
5
+ [Full Changelog](https://github.com/friendlycart/solidus_friendly_promotions/compare/v1.9.1...v1.9.2)
6
+
7
+ ## [v1.9.1](https://github.com/friendlycart/solidus_friendly_promotions/tree/v1.9.1) (2024-06-28)
8
+
9
+ [Full Changelog](https://github.com/friendlycart/solidus_friendly_promotions/compare/v1.9.0...v1.9.1)
6
10
 
7
11
  **Merged pull requests:**
8
12
 
13
+ - Fix specs after solidus merges [\#132](https://github.com/friendlycart/solidus_friendly_promotions/pull/132) ([mamhoff](https://github.com/mamhoff))
14
+ - Use ActiveRecord::Migration\[7.0\] [\#131](https://github.com/friendlycart/solidus_friendly_promotions/pull/131) ([mamhoff](https://github.com/mamhoff))
15
+ - Split rails\_helper and spec\_helper [\#126](https://github.com/friendlycart/solidus_friendly_promotions/pull/126) ([mamhoff](https://github.com/mamhoff))
16
+ - Use single-file dummy app from Solidus core [\#124](https://github.com/friendlycart/solidus_friendly_promotions/pull/124) ([mamhoff](https://github.com/mamhoff))
17
+ - Allow Turbo 2.x, but fix its issues [\#122](https://github.com/friendlycart/solidus_friendly_promotions/pull/122) ([mamhoff](https://github.com/mamhoff))
18
+ - Miscellaneous spec fixes [\#121](https://github.com/friendlycart/solidus_friendly_promotions/pull/121) ([mamhoff](https://github.com/mamhoff))
9
19
  - Documentation updates [\#116](https://github.com/friendlycart/solidus_friendly_promotions/pull/116) ([mamhoff](https://github.com/mamhoff))
10
20
  - Fix homepage path in gemspec [\#115](https://github.com/friendlycart/solidus_friendly_promotions/pull/115) ([pelargir](https://github.com/pelargir))
11
21
  - Use Bootstrap cards for admin UI [\#114](https://github.com/friendlycart/solidus_friendly_promotions/pull/114) ([mamhoff](https://github.com/mamhoff))
@@ -15,6 +25,10 @@
15
25
  - Rules per action [\#110](https://github.com/friendlycart/solidus_friendly_promotions/pull/110) ([mamhoff](https://github.com/mamhoff))
16
26
  - Promotion advertiser [\#109](https://github.com/friendlycart/solidus_friendly_promotions/pull/109) ([mamhoff](https://github.com/mamhoff))
17
27
 
28
+ ## [v1.9.0](https://github.com/friendlycart/solidus_friendly_promotions/tree/v1.9.0) (2024-06-13)
29
+
30
+ [Full Changelog](https://github.com/friendlycart/solidus_friendly_promotions/compare/v1.0.1...v1.9.0)
31
+
18
32
  ## [v1.0.1](https://github.com/friendlycart/solidus_friendly_promotions/tree/v1.0.1) (2024-05-07)
19
33
 
20
34
  [Full Changelog](https://github.com/friendlycart/solidus_friendly_promotions/compare/v1.0.0...v1.0.1)
data/Gemfile CHANGED
@@ -26,6 +26,8 @@ when "postgresql"
26
26
  else
27
27
  gem "sqlite3", "~> 1.3"
28
28
  end
29
+ # Fix for Ruby 3.3.3 packaging bug
30
+ gem "net-pop", github: "ruby/net-pop"
29
31
 
30
32
  gemspec
31
33
 
data/Rakefile CHANGED
@@ -1,7 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rubygems"
4
+ require "rake"
5
+ require "rake/testtask"
6
+ require "rspec/core/rake_task"
7
+ require "spree/testing_support/dummy_app/rake_tasks"
3
8
  require "bundler/gem_tasks"
4
- require "solidus_dev_support/rake_tasks"
5
- SolidusDevSupport::RakeTasks.install
6
9
 
7
- task default: "extension:specs"
10
+ RSpec::Core::RakeTask.new
11
+ task default: :spec
12
+
13
+ DummyApp::RakeTasks.new(
14
+ gem_root: File.dirname(__FILE__),
15
+ lib_name: "solidus_friendly_promotions"
16
+ )
17
+
18
+ task test_app: "db:reset"
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusFriendlyPromotions
4
- class PromotionCodeBatchJob < ApplicationJob
4
+ class PromotionCodeBatchJob < ActiveJob::Base
5
5
  queue_as :default
6
6
 
7
7
  def perform(promotion_code_batch)
@@ -18,6 +18,10 @@ module SolidusFriendlyPromotions
18
18
 
19
19
  preference :match_policy, :string, default: MATCH_POLICIES.first
20
20
 
21
+ def preload_relations
22
+ [:products]
23
+ end
24
+
21
25
  def eligible?(line_item, _options = {})
22
26
  order_includes_product = product_ids.include?(line_item.variant.product_id)
23
27
  success = inverse? ? !order_includes_product : order_includes_product
@@ -15,6 +15,10 @@ module SolidusFriendlyPromotions
15
15
 
16
16
  preference :match_policy, :string, default: MATCH_POLICIES.first
17
17
 
18
+ def preload_relations
19
+ [:taxons]
20
+ end
21
+
18
22
  def eligible?(line_item, _options = {})
19
23
  found = Spree::Classification.where(
20
24
  product_id: line_item.variant.product_id,
@@ -9,33 +9,33 @@
9
9
  <div class="col-4">
10
10
  <div class="form-group">
11
11
  <%= label_tag :q_name_cont, SolidusFriendlyPromotions::Promotion.human_attribute_name(:name) %>
12
- <%= f.text_field :name_cont, tabindex: 1 %>
12
+ <%= f.text_field :name_cont, tabindex: 1, class: "w-100" %>
13
13
  </div>
14
14
  </div>
15
15
 
16
16
  <div class="col-4">
17
17
  <div class="form-group">
18
18
  <%= label_tag :q_customer_label_cont, SolidusFriendlyPromotions::Promotion.human_attribute_name(:customer_label) %>
19
- <%= f.text_field :customer_label_cont, tabindex: 1 %>
19
+ <%= f.text_field :customer_label_cont, tabindex: 1, class: "w-100" %>
20
20
  </div>
21
21
  </div>
22
22
 
23
23
  <div class="col-2">
24
24
  <div class="form-group">
25
25
  <%= label_tag :q_codes_value_cont, SolidusFriendlyPromotions::Promotion.human_attribute_name(:code) %>
26
- <%= f.text_field :codes_value_cont, tabindex: 1 %>
26
+ <%= f.text_field :codes_value_cont, tabindex: 1, class: "w-100" %>
27
27
  </div>
28
28
  </div>
29
29
 
30
30
  <div class="col-2">
31
31
  <div class="form-group">
32
32
  <%= label_tag :q_path_cont, SolidusFriendlyPromotions::Promotion.human_attribute_name(:path) %>
33
- <%= f.text_field :path_cont, tabindex: 1 %>
33
+ <%= f.text_field :path_cont, tabindex: 1, class: "w-100" %>
34
34
  </div>
35
35
  </div>
36
36
 
37
37
  <div class="col-2">
38
- <div class="date-range-filter field">
38
+ <div class="date-range-filter form-group">
39
39
  <%= label_tag :q_active, SolidusFriendlyPromotions::Promotion.human_attribute_name(:active) %>
40
40
  <%= f.text_field :active, value: params[:q][:active],
41
41
  class: 'datepicker datepicker-from fullwidth',
@@ -0,0 +1,48 @@
1
+ class RenamePromotionRulesToConditions < ActiveRecord::Migration[7.0]
2
+ def up
3
+ rename_table :friendly_promotion_rules, :friendly_conditions
4
+ rename_table :friendly_promotion_rules_stores, :friendly_condition_stores
5
+ rename_table :friendly_promotion_rules_taxons, :friendly_condition_taxons
6
+ rename_table :friendly_promotion_rules_users, :friendly_condition_users
7
+ rename_table :friendly_products_promotion_rules, :friendly_condition_products
8
+ rename_column :friendly_condition_stores, :promotion_rule_id, :condition_id
9
+ rename_column :friendly_condition_taxons, :promotion_rule_id, :condition_id
10
+ rename_column :friendly_condition_users, :promotion_rule_id, :condition_id
11
+ rename_column :friendly_condition_products, :promotion_rule_id, :condition_id
12
+ solidus_sql = <<~SQL
13
+ UPDATE friendly_conditions
14
+ SET type = REPLACE(type, 'SolidusFriendlyPromotions::Rules', 'SolidusFriendlyPromotions::Conditions')
15
+ SQL
16
+ execute(solidus_sql)
17
+
18
+ cs_sql = <<~SQL
19
+ UPDATE friendly_conditions
20
+ SET type = REPLACE(type, 'Cs::Promotion::Rules', 'Cs::Promotion::Conditions')
21
+ SQL
22
+ execute(cs_sql)
23
+ end
24
+
25
+ def down
26
+ rename_table :friendly_conditions, :friendly_promotion_rules
27
+ rename_table :friendly_condition_stores, :friendly_promotion_rules_stores
28
+ rename_table :friendly_condition_taxons, :friendly_promotion_rules_taxons
29
+ rename_table :friendly_condition_users, :friendly_promotion_rules_users
30
+ rename_table :friendly_condition_products, :friendly_products_promotion_rules
31
+ rename_column :friendly_promotion_rules_stores, :condition_id, :promotion_rule_id
32
+ rename_column :friendly_promotion_rules_taxons, :condition_id, :promotion_rule_id
33
+ rename_column :friendly_promotion_rules_users, :condition_id, :promotion_rule_id
34
+ rename_column :friendly_products_promotion_rules, :condition_id, :promotion_rule_id
35
+
36
+ solidus_sql = <<~SQL
37
+ UPDATE friendly_promotion_rules
38
+ SET type = REPLACE(type, 'SolidusFriendlyPromotions::Conditions', 'SolidusFriendlyPromotions::Rules')
39
+ SQL
40
+ execute(solidus_sql)
41
+
42
+ cs_sql = <<~SQL
43
+ UPDATE friendly_promotion_rules
44
+ SET type = REPLACE(type, 'Cs::Promotion::Conditions', 'Cs::Promotion::Rules')
45
+ SQL
46
+ execute(cs_sql)
47
+ end
48
+ end
@@ -0,0 +1,35 @@
1
+ class RenameFriendlyPromotionActionsToFriendlyBenefits < ActiveRecord::Migration[6.1]
2
+ def up
3
+ rename_table :friendly_promotion_actions, :friendly_benefits
4
+ rename_column :spree_line_items, :managed_by_order_action_id, :managed_by_order_benefit_id
5
+ rename_column :friendly_shipping_rate_discounts, :promotion_action_id, :benefit_id
6
+ update_benefit_type_sql = <<~SQL
7
+ UPDATE friendly_benefits
8
+ SET type = REPLACE(type, 'SolidusFriendlyPromotions::Actions', 'SolidusFriendlyPromotions::Benefits')
9
+ SQL
10
+ execute(update_benefit_type_sql)
11
+ update_adjustment_source_type_sql = <<~SQL
12
+ UPDATE spree_adjustments
13
+ SET source_type = REPLACE(source_type, 'SolidusFriendlyPromotions::PromotionAction', 'SolidusFriendlyPromotions::Benefit')
14
+ WHERE source_type = 'SolidusFriendlyPromotions::PromotionAction'
15
+ SQL
16
+ execute(update_adjustment_source_type_sql)
17
+ end
18
+
19
+ def down
20
+ rename_table :friendly_benefits, :friendly_promotion_actions
21
+ rename_column :spree_line_items, :managed_by_order_benefit_id, :managed_by_order_action_id
22
+ rename_column :friendly_shipping_rate_discounts, :benefit_id, :promotion_action_id
23
+ update_benefit_type_sql = <<~SQL
24
+ UPDATE friendly_promotion_actions
25
+ SET type = REPLACE(type, 'SolidusFriendlyPromotions::Benefits', 'SolidusFriendlyPromotions::Actions')
26
+ SQL
27
+ execute(update_benefit_type_sql)
28
+ update_adjustment_source_type_sql = <<~SQL
29
+ UPDATE spree_adjustments
30
+ SET source_type = REPLACE(source_type, 'SolidusFriendlyPromotions::Benefit', 'SolidusFriendlyPromotions::PromotionAction')
31
+ WHERE source_type = 'SolidusFriendlyPromotions::Benefit'
32
+ SQL
33
+ execute(update_adjustment_source_type_sql)
34
+ end
35
+ end
@@ -0,0 +1,17 @@
1
+ class ChangeCalculableTypes < ActiveRecord::Migration[6.1]
2
+ def up
3
+ sql = <<~SQL
4
+ UPDATE spree_calculators
5
+ SET calculable_type = REPLACE(calculable_type, 'SolidusFriendlyPromotions::PromotionAction', 'SolidusFriendlyPromotions::Benefit')
6
+ SQL
7
+ execute(sql)
8
+ end
9
+
10
+ def down
11
+ sql = <<~SQL
12
+ UPDATE spree_calculators
13
+ SET calculable_type = REPLACE(calculable_type, 'SolidusFriendlyPromotions::Benefit', 'SolidusFriendlyPromotions::PromotionAction')
14
+ SQL
15
+ execute(sql)
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ class AddBenefitReferenceToConditions < ActiveRecord::Migration[6.1]
2
+ def up
3
+ remove_foreign_key :friendly_conditions, :friendly_promotions
4
+ change_column :friendly_conditions, :promotion_id, :integer, null: true
5
+
6
+ add_reference :friendly_conditions, :benefit, index: {name: :condition}, null: true, foreign_key: {to_table: :friendly_benefits}
7
+
8
+ SolidusFriendlyPromotions::Condition.reset_column_information
9
+
10
+ SolidusFriendlyPromotions::Benefit.find_each do |benefit|
11
+ SolidusFriendlyPromotions::Condition.where(promotion_id: benefit.promotion_id).each do |condition|
12
+ condition.dup.tap do |new_condition|
13
+ new_condition.preload_relations.each do |relation|
14
+ new_condition.send(:"#{relation}=", condition.send(relation).dup)
15
+ end
16
+ new_condition.benefit = benefit
17
+ new_condition.save!
18
+ end
19
+ condition.destroy!
20
+ end
21
+ end
22
+ end
23
+
24
+ def down
25
+ SolidusFriendlyPromotions::Condition.where.not(benefit_id: nil).delete_all
26
+ change_column :friendly_conditions, :promotion_id, :integer, null: true
27
+ add_foreign_key :friendly_conditions, :friendly_promotions, column: :promotion_id
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ class RemoveConditionsPromotionId < ActiveRecord::Migration[6.1]
2
+ def up
3
+ remove_column :friendly_conditions, :promotion_id
4
+ end
5
+ end
@@ -1,4 +1,4 @@
1
- class UpdateColumnCommentsForConditions < ActiveRecord::Migration[7.1]
1
+ class UpdateColumnCommentsForConditions < ActiveRecord::Migration[7.0]
2
2
  def up
3
3
  if connection.supports_comments?
4
4
  change_table_comment(:friendly_conditions, friendly_conditions_table_comment)
@@ -1,4 +1,4 @@
1
- class UpdateColumnCommentsForConditionStores < ActiveRecord::Migration[7.1]
1
+ class UpdateColumnCommentsForConditionStores < ActiveRecord::Migration[7.0]
2
2
  def up
3
3
  if connection.supports_comments?
4
4
  change_table_comment(:friendly_condition_stores, friendly_condition_stores_table_comment)
@@ -1,4 +1,4 @@
1
- class UpdateColumnCommentsForConditionProducts < ActiveRecord::Migration[7.1]
1
+ class UpdateColumnCommentsForConditionProducts < ActiveRecord::Migration[7.0]
2
2
  def up
3
3
  if connection.supports_comments?
4
4
  change_table_comment(:friendly_condition_products, friendly_condition_products_table_comment)
@@ -1,4 +1,4 @@
1
- class UpdateColumnCommentsForConditionTaxons < ActiveRecord::Migration[7.1]
1
+ class UpdateColumnCommentsForConditionTaxons < ActiveRecord::Migration[7.0]
2
2
  def up
3
3
  if connection.supports_comments?
4
4
  change_table_comment(:friendly_condition_taxons, friendly_condition_taxons_table_comment)
@@ -1,4 +1,4 @@
1
- class UpdateColumnCommentsForConditionUsers < ActiveRecord::Migration[7.1]
1
+ class UpdateColumnCommentsForConditionUsers < ActiveRecord::Migration[7.0]
2
2
  def up
3
3
  if connection.supports_comments?
4
4
  change_table_comment(:friendly_condition_users, friendly_condition_users_table_comment)
@@ -4,10 +4,6 @@
4
4
  Spree::Config.order_contents_class = "SolidusFriendlyPromotions::SimpleOrderContents"
5
5
  Spree::Config.promotion_adjuster_class = "SolidusFriendlyPromotions::FriendlyPromotionAdjuster"
6
6
 
7
- Rails.application.config.to_prepare do |config|
8
- Spree::Order.line_item_comparison_hooks << :free_from_order_benefit?
9
- end
10
-
11
7
  # Replace the promotions menu from core with ours
12
8
  Spree::Backend::Config.configure do |config|
13
9
  config.menu_items = config.menu_items.map do |item|
@@ -60,72 +56,5 @@ Spree::Backend::Config.configure do |config|
60
56
  end
61
57
 
62
58
  SolidusFriendlyPromotions.configure do |config|
63
- # This class chooses which promotion should apply to a line item in case
64
- # that more than one promotion is eligible.
65
- config.discount_chooser_class = "SolidusFriendlyPromotions::FriendlyPromotionAdjuster::ChooseDiscounts"
66
-
67
- # How many promotions should be displayed on the index page in the admin.
68
- config.promotions_per_page = 25
69
-
70
- config.promotion_calculators = SolidusFriendlyPromotions::NestedClassSet.new(
71
- "SolidusFriendlyPromotions::Benefits::AdjustShipment" => [
72
- "SolidusFriendlyPromotions::Calculators::FlatRate",
73
- "SolidusFriendlyPromotions::Calculators::FlexiRate",
74
- "SolidusFriendlyPromotions::Calculators::Percent",
75
- "SolidusFriendlyPromotions::Calculators::TieredFlatRate",
76
- "SolidusFriendlyPromotions::Calculators::TieredPercent",
77
- "SolidusFriendlyPromotions::Calculators::TieredPercentOnEligibleItemQuantity"
78
- ],
79
- "SolidusFriendlyPromotions::Benefits::AdjustLineItem" => [
80
- "SolidusFriendlyPromotions::Calculators::DistributedAmount",
81
- "SolidusFriendlyPromotions::Calculators::FlatRate",
82
- "SolidusFriendlyPromotions::Calculators::FlexiRate",
83
- "SolidusFriendlyPromotions::Calculators::Percent",
84
- "SolidusFriendlyPromotions::Calculators::TieredFlatRate",
85
- "SolidusFriendlyPromotions::Calculators::TieredPercent",
86
- "SolidusFriendlyPromotions::Calculators::TieredPercentOnEligibleItemQuantity"
87
- ],
88
- "SolidusFriendlyPromotions::Benefits::AdjustLineItemQuantityGroups" => [
89
- "SolidusFriendlyPromotions::Calculators::FlatRate",
90
- "SolidusFriendlyPromotions::Calculators::Percent",
91
- "SolidusFriendlyPromotions::Calculators::TieredPercentOnEligibleItemQuantity"
92
- ],
93
- "SolidusFriendlyPromotions::Benefits::CreateDiscountedItem" => [
94
- "SolidusFriendlyPromotions::Calculators::FlatRate",
95
- "SolidusFriendlyPromotions::Calculators::Percent",
96
- "SolidusFriendlyPromotions::Calculators::TieredPercentOnEligibleItemQuantity"
97
- ]
98
- )
99
-
100
- config.order_conditions = [
101
- "SolidusFriendlyPromotions::Conditions::FirstOrder",
102
- "SolidusFriendlyPromotions::Conditions::FirstRepeatPurchaseSince",
103
- "SolidusFriendlyPromotions::Conditions::ItemTotal",
104
- "SolidusFriendlyPromotions::Conditions::DiscountedItemTotal",
105
- "SolidusFriendlyPromotions::Conditions::MinimumQuantity",
106
- "SolidusFriendlyPromotions::Conditions::NthOrder",
107
- "SolidusFriendlyPromotions::Conditions::OneUsePerUser",
108
- "SolidusFriendlyPromotions::Conditions::OptionValue",
109
- "SolidusFriendlyPromotions::Conditions::Product",
110
- "SolidusFriendlyPromotions::Conditions::Store",
111
- "SolidusFriendlyPromotions::Conditions::Taxon",
112
- "SolidusFriendlyPromotions::Conditions::UserLoggedIn",
113
- "SolidusFriendlyPromotions::Conditions::UserRole",
114
- "SolidusFriendlyPromotions::Conditions::User"
115
- ]
116
- config.line_item_conditions = [
117
- "SolidusFriendlyPromotions::Conditions::LineItemOptionValue",
118
- "SolidusFriendlyPromotions::Conditions::LineItemProduct",
119
- "SolidusFriendlyPromotions::Conditions::LineItemTaxon"
120
- ]
121
- config.shipment_conditions = [
122
- "SolidusFriendlyPromotions::Conditions::ShippingMethod"
123
- ]
124
-
125
- config.actions = [
126
- "SolidusFriendlyPromotions::Benefits::AdjustLineItem",
127
- "SolidusFriendlyPromotions::Benefits::AdjustLineItemQuantityGroups",
128
- "SolidusFriendlyPromotions::Benefits::AdjustShipment",
129
- "SolidusFriendlyPromotions::Benefits::CreateDiscountedItem"
130
- ]
59
+ # Add your custom configuration here
131
60
  end
@@ -1,31 +1,98 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "spree/core/environment_extension"
3
+ require "solidus_friendly_promotions/environment_extension"
4
4
 
5
5
  module SolidusFriendlyPromotions
6
6
  class Configuration < Spree::Preferences::Configuration
7
7
  attr_accessor :sync_order_promotions
8
8
  attr_accessor :recalculate_complete_orders
9
- attr_accessor :promotion_calculators
10
9
 
11
10
  def initialize
12
11
  @sync_order_promotions = true
13
12
  @recalculate_complete_orders = true
14
- @promotion_calculators = NestedClassSet.new
15
13
  end
16
14
 
17
- include Spree::Core::EnvironmentExtension
15
+ include SolidusFriendlyPromotions::EnvironmentExtension
18
16
 
19
- add_class_set :line_item_discount_calculators
20
- add_class_set :shipment_discount_calculators
17
+ class_name_attribute :order_adjuster_class, default: "SolidusFriendlyPromotions::FriendlyPromotionAdjuster"
21
18
 
22
- add_class_set :order_conditions
23
- add_class_set :line_item_conditions
24
- add_class_set :shipment_conditions
19
+ class_name_attribute :coupon_code_handler_class, default: "SolidusFriendlyPromotions::PromotionHandler::Coupon"
25
20
 
26
- add_class_set :actions
21
+ # Allows providing a different promotion advertiser.
22
+ # @!attribute [rw] advertiser_class
23
+ # @see Spree::NullPromotionAdvertiser
24
+ # @return [Class] an object that conforms to the API of
25
+ # the standard promotion advertiser class
26
+ # Spree::NullPromotionAdvertiser.
27
+ class_name_attribute :advertiser_class, default: "SolidusFriendlyPromotions::PromotionAdvertiser"
28
+
29
+ # In case solidus_legacy_promotions is loaded, we need to define this.
30
+ class_name_attribute :shipping_promotion_handler_class, default: "Spree::NullPromotionHandler"
31
+
32
+ add_class_set :order_conditions, default: [
33
+ "SolidusFriendlyPromotions::Conditions::FirstOrder",
34
+ "SolidusFriendlyPromotions::Conditions::FirstRepeatPurchaseSince",
35
+ "SolidusFriendlyPromotions::Conditions::ItemTotal",
36
+ "SolidusFriendlyPromotions::Conditions::DiscountedItemTotal",
37
+ "SolidusFriendlyPromotions::Conditions::MinimumQuantity",
38
+ "SolidusFriendlyPromotions::Conditions::NthOrder",
39
+ "SolidusFriendlyPromotions::Conditions::OneUsePerUser",
40
+ "SolidusFriendlyPromotions::Conditions::OptionValue",
41
+ "SolidusFriendlyPromotions::Conditions::Product",
42
+ "SolidusFriendlyPromotions::Conditions::Store",
43
+ "SolidusFriendlyPromotions::Conditions::Taxon",
44
+ "SolidusFriendlyPromotions::Conditions::UserLoggedIn",
45
+ "SolidusFriendlyPromotions::Conditions::UserRole",
46
+ "SolidusFriendlyPromotions::Conditions::User"
47
+ ]
48
+
49
+ add_class_set :line_item_conditions, default: [
50
+ "SolidusFriendlyPromotions::Conditions::LineItemOptionValue",
51
+ "SolidusFriendlyPromotions::Conditions::LineItemProduct",
52
+ "SolidusFriendlyPromotions::Conditions::LineItemTaxon"
53
+ ]
54
+ add_class_set :shipment_conditions, default: [
55
+ "SolidusFriendlyPromotions::Conditions::ShippingMethod"
56
+ ]
57
+
58
+ add_class_set :actions, default: [
59
+ "SolidusFriendlyPromotions::Benefits::AdjustLineItem",
60
+ "SolidusFriendlyPromotions::Benefits::AdjustLineItemQuantityGroups",
61
+ "SolidusFriendlyPromotions::Benefits::AdjustShipment",
62
+ "SolidusFriendlyPromotions::Benefits::CreateDiscountedItem"
63
+ ]
64
+
65
+ add_nested_class_set :promotion_calculators, default: {
66
+ "SolidusFriendlyPromotions::Benefits::AdjustShipment" => [
67
+ "SolidusFriendlyPromotions::Calculators::FlatRate",
68
+ "SolidusFriendlyPromotions::Calculators::FlexiRate",
69
+ "SolidusFriendlyPromotions::Calculators::Percent",
70
+ "SolidusFriendlyPromotions::Calculators::TieredFlatRate",
71
+ "SolidusFriendlyPromotions::Calculators::TieredPercent",
72
+ "SolidusFriendlyPromotions::Calculators::TieredPercentOnEligibleItemQuantity"
73
+ ],
74
+ "SolidusFriendlyPromotions::Benefits::AdjustLineItem" => [
75
+ "SolidusFriendlyPromotions::Calculators::DistributedAmount",
76
+ "SolidusFriendlyPromotions::Calculators::FlatRate",
77
+ "SolidusFriendlyPromotions::Calculators::FlexiRate",
78
+ "SolidusFriendlyPromotions::Calculators::Percent",
79
+ "SolidusFriendlyPromotions::Calculators::TieredFlatRate",
80
+ "SolidusFriendlyPromotions::Calculators::TieredPercent",
81
+ "SolidusFriendlyPromotions::Calculators::TieredPercentOnEligibleItemQuantity"
82
+ ],
83
+ "SolidusFriendlyPromotions::Benefits::AdjustLineItemQuantityGroups" => [
84
+ "SolidusFriendlyPromotions::Calculators::FlatRate",
85
+ "SolidusFriendlyPromotions::Calculators::Percent",
86
+ "SolidusFriendlyPromotions::Calculators::TieredPercentOnEligibleItemQuantity"
87
+ ],
88
+ "SolidusFriendlyPromotions::Benefits::CreateDiscountedItem" => [
89
+ "SolidusFriendlyPromotions::Calculators::FlatRate",
90
+ "SolidusFriendlyPromotions::Calculators::Percent",
91
+ "SolidusFriendlyPromotions::Calculators::TieredPercentOnEligibleItemQuantity"
92
+ ]
93
+ }
27
94
 
28
- class_name_attribute :discount_chooser_class, default: "SolidusFriendlyPromotions::DiscountChooser"
95
+ class_name_attribute :discount_chooser_class, default: "SolidusFriendlyPromotions::FriendlyPromotionAdjuster::ChooseDiscounts"
29
96
  class_name_attribute :promotion_code_batch_mailer_class,
30
97
  default: "SolidusFriendlyPromotions::PromotionCodeBatchMailer"
31
98
 
@@ -20,6 +20,12 @@ module SolidusFriendlyPromotions
20
20
  app.config.assets.precompile << "solidus_friendly_promotions/manifest.js"
21
21
  end
22
22
 
23
+ initializer "solidus_promotions.spree_config", after: "spree.load_config_initializers" do
24
+ Rails.application.config.to_prepare do
25
+ Spree::Order.line_item_comparison_hooks << :free_from_order_benefit?
26
+ end
27
+ end
28
+
23
29
  initializer "solidus_friendly_promotions.importmap" do |app|
24
30
  SolidusFriendlyPromotions.importmap.draw(Engine.root.join("config", "importmap.rb"))
25
31
 
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spree/core/class_constantizer"
4
+ require "solidus_friendly_promotions/nested_class_set"
5
+
6
+ module SolidusFriendlyPromotions
7
+ module EnvironmentExtension
8
+ extend ActiveSupport::Concern
9
+
10
+ class_methods do
11
+ def add_class_set(name, default: [])
12
+ define_method(name) do
13
+ set = instance_variable_get(:"@#{name}")
14
+ set ||= send(:"#{name}=", default)
15
+ set
16
+ end
17
+
18
+ define_method(:"#{name}=") do |klasses|
19
+ set = Spree::Core::ClassConstantizer::Set.new
20
+ set.concat(klasses)
21
+ instance_variable_set(:"@#{name}", set)
22
+ end
23
+ end
24
+
25
+ def add_nested_class_set(name, default: {})
26
+ define_method(name) do
27
+ set = instance_variable_get(:"@#{name}")
28
+ set ||= send(:"#{name}=", default)
29
+ set
30
+ end
31
+
32
+ define_method(:"#{name}=") do |hash|
33
+ set = SolidusFriendlyPromotions::NestedClassSet.new(hash)
34
+ instance_variable_set(:"@#{name}", set)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusFriendlyPromotions
4
- VERSION = "1.9.0"
4
+ VERSION = "1.9.2"
5
5
  end
@@ -30,11 +30,12 @@ Gem::Specification.new do |spec|
30
30
 
31
31
  spec.add_dependency "solidus_core", [">= 4.0.0", "< 4.4"]
32
32
  spec.add_dependency "solidus_support", "~> 0.5"
33
- spec.add_dependency "turbo-rails", "~> 1.4"
33
+ spec.add_dependency "turbo-rails", ">= 1.4"
34
34
  spec.add_dependency "stimulus-rails", "~> 1.2"
35
35
  spec.add_dependency "importmap-rails", "~> 1.2"
36
36
  spec.add_dependency "ransack-enum", "~> 1.0"
37
37
  spec.add_development_dependency "rspec-activemodel-mocks", "~> 1.0"
38
+ spec.add_development_dependency "rspec-retry"
38
39
  spec.add_development_dependency "shoulda-matchers", "~> 5.3"
39
40
  spec.add_development_dependency "solidus_dev_support", "~> 2.6"
40
41
  spec.add_development_dependency "standard", "~> 1.31"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_friendly_promotions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Meyerhoff
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-13 00:00:00.000000000 Z
11
+ date: 2024-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -48,14 +48,14 @@ dependencies:
48
48
  name: turbo-rails
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - "~>"
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '1.4'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - "~>"
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: '1.4'
61
61
  - !ruby/object:Gem::Dependency
@@ -114,6 +114,20 @@ dependencies:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
116
  version: '1.0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rspec-retry
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
117
131
  - !ruby/object:Gem::Dependency
118
132
  name: shoulda-matchers
119
133
  requirement: !ruby/object:Gem::Requirement
@@ -384,10 +398,11 @@ files:
384
398
  - db/migrate/20231104135812_add_managed_by_order_action_to_line_items.rb
385
399
  - db/migrate/20240124104855_add_deleted_at_to_promotions.rb
386
400
  - db/migrate/20240125102050_drop_deleted_at_from_promotion_actions.rb
387
- - db/migrate/20240409093831_add_action_reference_to_rules.rb
388
- - db/migrate/20240506142650_remove_promotion_rules_promotion_id.rb
389
- - db/migrate/20240508080834_rename_promotion_rules_to_conditions.rb
390
- - db/migrate/20240508131514_rename_friendly_promotion_actions_to_friendly_benefits.rb
401
+ - db/migrate/20240409093831_rename_promotion_rules_to_conditions.rb
402
+ - db/migrate/20240506142650_rename_friendly_promotion_actions_to_friendly_benefits.rb
403
+ - db/migrate/20240506142651_change_calculable_types.rb
404
+ - db/migrate/20240508080834_add_benefit_reference_to_conditions.rb
405
+ - db/migrate/20240508131514_remove_conditions_promotion_id.rb
391
406
  - db/migrate/20240612113608_update_column_comments_for_benefits.rb
392
407
  - db/migrate/20240612114132_update_column_comments_for_conditions.rb
393
408
  - db/migrate/20240612115209_update_column_comments_for_condition_stores.rb
@@ -399,6 +414,7 @@ files:
399
414
  - lib/solidus_friendly_promotions.rb
400
415
  - lib/solidus_friendly_promotions/configuration.rb
401
416
  - lib/solidus_friendly_promotions/engine.rb
417
+ - lib/solidus_friendly_promotions/environment_extension.rb
402
418
  - lib/solidus_friendly_promotions/migrate_adjustments.rb
403
419
  - lib/solidus_friendly_promotions/migrate_order_promotions.rb
404
420
  - lib/solidus_friendly_promotions/nested_class_set.rb
@@ -1,34 +0,0 @@
1
- class AddActionReferenceToRules < ActiveRecord::Migration[7.0]
2
- class LocalBenefit < ApplicationRecord
3
- self.table_name = "friendly_promotion_actions"
4
- has_many :actions, class_name: "SolidusFriendlyPromotions::Condition", foreign_key: :action_id
5
- end
6
-
7
- def up
8
- remove_foreign_key :friendly_promotion_rules, :friendly_promotions
9
- change_column :friendly_promotion_rules, :promotion_id, :integer, null: true
10
-
11
- add_reference :friendly_promotion_rules, :action, index: {name: :rule}, null: true, foreign_key: {to_table: :friendly_promotion_actions}
12
-
13
- SolidusFriendlyPromotions::Condition.reset_column_information
14
-
15
- LocalBenefit.find_each do |action|
16
- SolidusFriendlyPromotions::Condition.where(promotion_id: action.promotion_id).each do |rule|
17
- rule.dup.tap do |new_rule|
18
- new_rule.preload_relations.each do |relation|
19
- new_rule.send(:"#{relation}=", rule.send(relation).dup)
20
- end
21
- new_rule.action = action
22
- new_rule.save!
23
- end
24
- rule.destroy!
25
- end
26
- end
27
- end
28
-
29
- def down
30
- SolidusFriendlyPromotions::Condition.where.not(action_id: nil).delete_all
31
- change_column :friendly_promotion_rules, :promotion_id, :integer, null: true
32
- add_foreign_key :friendly_promotion_rules, :friendly_promotions, column: :promotion_id
33
- end
34
- end
@@ -1,5 +0,0 @@
1
- class RemovePromotionRulesPromotionId < ActiveRecord::Migration[7.1]
2
- def up
3
- remove_column :friendly_promotion_rules, :promotion_id
4
- end
5
- end
@@ -1,19 +0,0 @@
1
- class RenamePromotionRulesToConditions < ActiveRecord::Migration[7.1]
2
- def change
3
- rename_table :friendly_promotion_rules, :friendly_conditions
4
- rename_table :friendly_promotion_rules_stores, :friendly_condition_stores
5
- rename_table :friendly_promotion_rules_taxons, :friendly_condition_taxons
6
- rename_table :friendly_promotion_rules_users, :friendly_condition_users
7
- rename_table :friendly_products_promotion_rules, :friendly_condition_products
8
- rename_column :friendly_condition_stores, :promotion_rule_id, :condition_id
9
- rename_column :friendly_condition_taxons, :promotion_rule_id, :condition_id
10
- rename_column :friendly_condition_users, :promotion_rule_id, :condition_id
11
- rename_column :friendly_condition_products, :promotion_rule_id, :condition_id
12
- sql = <<~SQL
13
- UPDATE friendly_conditions
14
- SET type = REPLACE(type, 'SolidusFriendlyPromotions::Rules', 'SolidusFriendlyPromotions::Conditions')
15
- SQL
16
-
17
- execute(sql)
18
- end
19
- end
@@ -1,19 +0,0 @@
1
- class RenameFriendlyPromotionActionsToFriendlyBenefits < ActiveRecord::Migration[7.1]
2
- def change
3
- rename_table :friendly_promotion_actions, :friendly_benefits
4
- rename_column :friendly_conditions, :action_id, :benefit_id
5
- rename_column :spree_line_items, :managed_by_order_action_id, :managed_by_order_benefit_id
6
- rename_column :friendly_shipping_rate_discounts, :promotion_action_id, :benefit_id
7
- update_benefit_type_sql = <<~SQL
8
- UPDATE friendly_benefits
9
- SET type = REPLACE(type, 'SolidusFriendlyPromotions::Actions', 'SolidusFriendlyPromotions::Benefits')
10
- SQL
11
- execute(update_benefit_type_sql)
12
- update_adjustment_source_type_sql = <<~SQL
13
- UPDATE spree_adjustments
14
- SET source_type = REPLACE(source_type, 'SolidusFriendlyPromotions::Actions', 'SolidusFriendlyPromotions::Benefits')
15
- WHERE source_type LIKE 'SolidusFriendlyPromotions::Actions%'
16
- SQL
17
- execute(update_adjustment_source_type_sql)
18
- end
19
- end