solidus_legacy_promotions 4.5.0 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/spree/calculator/flexi_rate.rb +1 -1
  3. data/app/models/spree/calculator/tiered_flat_rate.rb +0 -2
  4. data/app/models/spree/calculator/tiered_percent.rb +0 -2
  5. data/app/models/spree/promotion/actions/create_adjustment.rb +2 -2
  6. data/app/models/spree/promotion/actions/create_item_adjustments.rb +2 -2
  7. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +2 -2
  8. data/app/models/spree/promotion/rules/first_order.rb +1 -1
  9. data/app/models/spree/promotion/rules/product.rb +6 -3
  10. data/app/models/spree/promotion/rules/store.rb +5 -3
  11. data/app/models/spree/promotion/rules/taxon.rb +6 -3
  12. data/app/models/spree/promotion/rules/user.rb +5 -3
  13. data/app/models/spree/promotion.rb +1 -5
  14. data/app/models/spree/promotion_action.rb +0 -2
  15. data/app/models/spree/promotion_category.rb +2 -2
  16. data/app/models/spree/promotion_chooser.rb +1 -1
  17. data/app/models/spree/promotion_code.rb +1 -1
  18. data/app/models/spree/promotion_code_batch.rb +1 -1
  19. data/app/models/spree/promotion_rule.rb +0 -2
  20. data/app/patches/models/solidus_legacy_promotions/spree_order_updater_patch.rb +1 -1
  21. data/app/patches/models/solidus_legacy_promotions/spree_taxon_patch.rb +12 -0
  22. data/db/migrate/20231027084517_add_order_promotions_foreign_key.rb +1 -1
  23. data/lib/components/admin/solidus_admin/promotion_categories/edit/component.html.erb +5 -5
  24. data/lib/components/admin/solidus_admin/promotion_categories/edit/component.yml +0 -1
  25. data/lib/components/admin/solidus_admin/promotion_categories/index/component.rb +4 -4
  26. data/lib/components/admin/solidus_admin/promotion_categories/new/component.html.erb +5 -5
  27. data/lib/components/admin/solidus_admin/promotion_categories/new/component.yml +0 -1
  28. metadata +8 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a55daf802efdf77185de8109a5214de29a6a0eecabb6630a7fbe9cd86deb526
4
- data.tar.gz: 84674636a0a129b192d70ebabf17be810c0dc36790a7ed03f0edccc4a6521dee
3
+ metadata.gz: cf47c0f45a295148fe77753d40e3010744ea09c9e4a541213744c7534ddc0616
4
+ data.tar.gz: 9fceff71425ec0cd5bca313747bb602daae0417fe091144c39bf6489f9e44679
5
5
  SHA512:
6
- metadata.gz: e68e598172fd94f4eedc72b1d35b325fa3d248ca209d70ddda8b9c235cc4c000a08fe5b1418b0e2dbde9b20c9a7319f10b2117003aca4a99a55db5934f30366d
7
- data.tar.gz: 363c73e69b24eb4790233c0454b2649f85dba023e97310c42e8b2b6372834625b2ec41d179ea59cfdc2e0afb66deb79344bb2c667a5581c61817d209aa050bcb
6
+ metadata.gz: 6485062b87b025dcf87dff943480f5272a7c938cdcc46a3abf9ff9ae1fae28a68a08898e64f5070e0442c6ba939e04d0c8eebe283fcf7424ac0863c4dcdc9a14
7
+ data.tar.gz: 052be047b145b6798edeeabd7de5d4029048ffb5161bb9d62c743fa7ef6dce6a0b21c81d352c8dd454fd4329e5dc8c0e09b39e61f6dd01b3d95550d990a295ff
@@ -13,7 +13,7 @@ module Spree
13
13
  items_count = object.quantity
14
14
  items_count = [items_count, preferred_max_items].min unless preferred_max_items.zero?
15
15
 
16
- return BigDecimal(0) if items_count == 0
16
+ return Spree::ZERO if items_count == 0
17
17
 
18
18
  additional_items_count = items_count - 1
19
19
  preferred_first_item + preferred_additional_item * additional_items_count
@@ -35,8 +35,6 @@ module Spree
35
35
 
36
36
  def cast_to_d(value)
37
37
  value.to_s.to_d
38
- rescue ArgumentError
39
- BigDecimal(0)
40
38
  end
41
39
 
42
40
  def preferred_tiers_content
@@ -42,8 +42,6 @@ module Spree
42
42
 
43
43
  def cast_to_d(value)
44
44
  value.to_s.to_d
45
- rescue ArgumentError
46
- BigDecimal(0)
47
45
  end
48
46
 
49
47
  def preferred_tiers_content
@@ -7,7 +7,7 @@ module Spree
7
7
  include Spree::CalculatedAdjustments
8
8
  include Spree::AdjustmentSource
9
9
 
10
- has_many :adjustments, as: :source
10
+ has_many :adjustments, as: :source, dependent: :restrict_with_error
11
11
 
12
12
  delegate :eligible?, to: :promotion
13
13
 
@@ -43,7 +43,7 @@ module Spree
43
43
  # item_total and ship_total
44
44
  def compute_amount(calculable)
45
45
  amount = calculator.compute(calculable)
46
- amount ||= BigDecimal(0)
46
+ amount ||= Spree::ZERO
47
47
  amount = amount.abs
48
48
  [(calculable.item_total + calculable.ship_total), amount].min * -1
49
49
  end
@@ -7,7 +7,7 @@ module Spree
7
7
  include Spree::CalculatedAdjustments
8
8
  include Spree::AdjustmentSource
9
9
 
10
- has_many :adjustments, as: :source
10
+ has_many :adjustments, as: :source, dependent: :restrict_with_error
11
11
 
12
12
  delegate :eligible?, to: :promotion
13
13
 
@@ -37,7 +37,7 @@ module Spree
37
37
  order = adjustable.is_a?(Order) ? adjustable : adjustable.order
38
38
  return 0 unless promotion.line_item_actionable?(order, adjustable)
39
39
  promotion_amount = calculator.compute(adjustable)
40
- promotion_amount ||= BigDecimal(0)
40
+ promotion_amount ||= Spree::ZERO
41
41
  promotion_amount = promotion_amount.abs
42
42
  [adjustable.amount, promotion_amount].min * -1
43
43
  end
@@ -6,7 +6,7 @@ module Spree
6
6
  class CreateQuantityAdjustments < CreateItemAdjustments
7
7
  preference :group_size, :integer, default: 1
8
8
 
9
- has_many :line_item_actions, foreign_key: :action_id, dependent: :destroy
9
+ has_many :line_item_actions, foreign_key: :action_id, dependent: :destroy, inverse_of: :action
10
10
  has_many :line_items, through: :line_item_actions
11
11
 
12
12
  ##
@@ -57,7 +57,7 @@ module Spree
57
57
  #
58
58
  def compute_amount(line_item)
59
59
  adjustment_amount = calculator.compute(PartialLineItem.new(line_item))
60
- adjustment_amount ||= BigDecimal(0)
60
+ adjustment_amount ||= Spree::ZERO
61
61
  adjustment_amount = adjustment_amount.abs
62
62
 
63
63
  order = line_item.order
@@ -14,7 +14,7 @@ module Spree
14
14
  @user = order.try(:user) || options[:user]
15
15
  @email = order.email
16
16
 
17
- if (user || email) && (completed_orders.present? && completed_orders.first != order)
17
+ if (user || email) && completed_orders.present? && completed_orders.first != order
18
18
  eligibility_errors.add(:base, eligibility_error_message(:not_first_order), error_code: :not_first_order)
19
19
  end
20
20
 
@@ -8,8 +8,11 @@ module Spree
8
8
  # either come from assigned product group or are assingned directly to
9
9
  # the rule.
10
10
  class Product < PromotionRule
11
- has_many :product_promotion_rules, dependent: :destroy, foreign_key: :promotion_rule_id,
12
- class_name: 'Spree::ProductPromotionRule'
11
+ has_many :product_promotion_rules,
12
+ dependent: :destroy,
13
+ foreign_key: :promotion_rule_id,
14
+ class_name: 'Spree::ProductPromotionRule',
15
+ inverse_of: :promotion_rule
13
16
  has_many :products, class_name: 'Spree::Product', through: :product_promotion_rules
14
17
 
15
18
  def preload_relations
@@ -18,7 +21,7 @@ module Spree
18
21
 
19
22
  MATCH_POLICIES = %w(any all none)
20
23
 
21
- validates_inclusion_of :preferred_match_policy, in: MATCH_POLICIES
24
+ validates :preferred_match_policy, inclusion: { in: MATCH_POLICIES }
22
25
 
23
26
  preference :match_policy, :string, default: MATCH_POLICIES.first
24
27
 
@@ -4,9 +4,11 @@ module Spree
4
4
  class Promotion
5
5
  module Rules
6
6
  class Store < PromotionRule
7
- has_many :promotion_rule_stores, class_name: "Spree::PromotionRuleStore",
8
- foreign_key: :promotion_rule_id,
9
- dependent: :destroy
7
+ has_many :promotion_rule_stores,
8
+ class_name: "Spree::PromotionRuleStore",
9
+ foreign_key: :promotion_rule_id,
10
+ dependent: :destroy,
11
+ inverse_of: :promotion_rule
10
12
  has_many :stores, through: :promotion_rule_stores, class_name: "Spree::Store"
11
13
 
12
14
  def preload_relations
@@ -4,8 +4,11 @@ module Spree
4
4
  class Promotion < Spree::Base
5
5
  module Rules
6
6
  class Taxon < PromotionRule
7
- has_many :promotion_rule_taxons, class_name: 'Spree::PromotionRuleTaxon', foreign_key: :promotion_rule_id,
8
- dependent: :destroy
7
+ has_many :promotion_rule_taxons,
8
+ class_name: 'Spree::PromotionRuleTaxon',
9
+ foreign_key: :promotion_rule_id,
10
+ dependent: :destroy,
11
+ inverse_of: :promotion_rule
9
12
  has_many :taxons, through: :promotion_rule_taxons, class_name: 'Spree::Taxon'
10
13
 
11
14
  def preload_relations
@@ -14,7 +17,7 @@ module Spree
14
17
 
15
18
  MATCH_POLICIES = %w(any all none)
16
19
 
17
- validates_inclusion_of :preferred_match_policy, in: MATCH_POLICIES
20
+ validates :preferred_match_policy, inclusion: { in: MATCH_POLICIES }
18
21
 
19
22
  preference :match_policy, :string, default: MATCH_POLICIES.first
20
23
  def applicable?(promotable)
@@ -4,9 +4,11 @@ module Spree
4
4
  class Promotion < Spree::Base
5
5
  module Rules
6
6
  class User < PromotionRule
7
- has_many :promotion_rule_users, class_name: 'Spree::PromotionRuleUser',
8
- foreign_key: :promotion_rule_id,
9
- dependent: :destroy
7
+ has_many :promotion_rule_users,
8
+ class_name: 'Spree::PromotionRuleUser',
9
+ foreign_key: :promotion_rule_id,
10
+ dependent: :destroy,
11
+ inverse_of: :promotion_rule
10
12
  has_many :users, through: :promotion_rule_users, class_name: Spree::UserClassHandle.new
11
13
 
12
14
  def preload_relations
@@ -204,11 +204,7 @@ module Spree
204
204
 
205
205
  if eligible?(order, promotion_code:)
206
206
  rules = eligible_rules(order)
207
- if rules.blank?
208
- true
209
- else
210
- rules.all? { |rule| rule.actionable? line_item }
211
- end
207
+ rules.blank? || rules.all? { |rule| rule.actionable? line_item }
212
208
  else
213
209
  false
214
210
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spree/preferences/persistable'
4
-
5
3
  module Spree
6
4
  # Base class for all types of promotion action.
7
5
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Spree
4
4
  class PromotionCategory < Spree::Base
5
- validates_presence_of :name
6
- has_many :promotions
5
+ validates :name, presence: true
6
+ has_many :promotions, dependent: :nullify
7
7
  end
8
8
  end
@@ -18,7 +18,7 @@ module Spree
18
18
  end
19
19
  best_promotion_adjustment.amount
20
20
  else
21
- BigDecimal('0')
21
+ Spree::ZERO
22
22
  end
23
23
  end
24
24
 
@@ -3,7 +3,7 @@
3
3
  class Spree::PromotionCode < Spree::Base
4
4
  belongs_to :promotion, inverse_of: :codes, optional: true
5
5
  belongs_to :promotion_code_batch, class_name: "Spree::PromotionCodeBatch", optional: true
6
- has_many :adjustments
6
+ has_many :adjustments, dependent: :restrict_with_error
7
7
 
8
8
  before_validation :normalize_code
9
9
 
@@ -9,7 +9,7 @@ module Spree
9
9
  has_many :promotion_codes, class_name: "Spree::PromotionCode", dependent: :destroy
10
10
 
11
11
  validates :number_of_codes, numericality: { greater_than: 0 }
12
- validates_presence_of :base_code, :number_of_codes
12
+ validates :base_code, :number_of_codes, presence: true
13
13
 
14
14
  def finished?
15
15
  state == "completed"
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spree/preferences/persistable'
4
-
5
3
  module Spree
6
4
  # Base class for all promotion rules
7
5
  class PromotionRule < Spree::Base
@@ -17,7 +17,7 @@ module SolidusLegacyPromotions
17
17
 
18
18
  def update_item_totals
19
19
  [*line_items, *shipments].each do |item|
20
- Spree::ItemTotal.new(item).recalculate!
20
+ Spree::Config.item_total_class.new(item).recalculate!
21
21
 
22
22
  # The cancellation_total isn't persisted anywhere but is included in
23
23
  # the adjustment_total.
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusLegacyPromotions
4
+ module SpreeTaxonPatch
5
+ def self.prepended(base)
6
+ base.has_many :promotion_rule_taxons, dependent: :destroy
7
+ base.has_many :promotion_rules, through: :promotion_rule_taxons
8
+ end
9
+
10
+ ::Spree::Taxon.prepend self
11
+ end
12
+ end
@@ -8,7 +8,7 @@ class AddOrderPromotionsForeignKey < ActiveRecord::Migration[7.0]
8
8
 
9
9
  def down
10
10
  if foreign_key_exists?(:spree_orders_promotions, :spree_orders, column: :order_id)
11
- remove_foreign_key :spree_orders_promotions, :spree_orders_promotions
11
+ remove_foreign_key :spree_orders_promotions, :spree_orders, column: :order_id
12
12
  end
13
13
  end
14
14
  end
@@ -1,15 +1,15 @@
1
- <%= turbo_frame_tag :resource_modal, target: "_top" do %>
1
+ <%= turbo_frame_tag :resource_form, target: "_top" do %>
2
2
  <%= render component("ui/modal").new(title: t(".title")) do |modal| %>
3
- <%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>
3
+ <%= solidus_form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>
4
4
  <div class="flex flex-col gap-6 pb-4">
5
- <%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
6
- <%= render component("ui/forms/field").text_field(f, :code, class: "required") %>
5
+ <%= f.text_field(:name, class: "required") %>
6
+ <%= f.text_field(:code, class: "required") %>
7
7
  </div>
8
8
  <% modal.with_actions do %>
9
9
  <form method="dialog">
10
10
  <%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
11
11
  </form>
12
- <%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
12
+ <%= f.submit %>
13
13
  <% end %>
14
14
  <% end %>
15
15
  <% end %>
@@ -1,4 +1,3 @@
1
1
  en:
2
2
  title: "Edit Promotion Category"
3
3
  cancel: "Cancel"
4
- submit: "Update Promotion Category"
@@ -14,7 +14,7 @@ class SolidusAdmin::PromotionCategories::Index::Component < SolidusAdmin::UI::Pa
14
14
  end
15
15
 
16
16
  def turbo_frames
17
- %w[resource_modal]
17
+ %w[resource_form]
18
18
  end
19
19
 
20
20
  def page_actions
@@ -22,7 +22,7 @@ class SolidusAdmin::PromotionCategories::Index::Component < SolidusAdmin::UI::Pa
22
22
  tag: :a,
23
23
  text: t('.add'),
24
24
  href: solidus_admin.new_promotion_category_path(**search_filter_params),
25
- data: { turbo_frame: :resource_modal },
25
+ data: { turbo_frame: :resource_form },
26
26
  icon: "add-line",
27
27
  )
28
28
  end
@@ -50,7 +50,7 @@ class SolidusAdmin::PromotionCategories::Index::Component < SolidusAdmin::UI::Pa
50
50
  header: :name,
51
51
  data: ->(record) do
52
52
  link_to record.name, edit_path(record),
53
- data: { turbo_frame: :resource_modal },
53
+ data: { turbo_frame: :resource_form },
54
54
  class: 'body-link'
55
55
  end
56
56
  }
@@ -61,7 +61,7 @@ class SolidusAdmin::PromotionCategories::Index::Component < SolidusAdmin::UI::Pa
61
61
  header: :code,
62
62
  data: ->(record) do
63
63
  link_to record.code, edit_path(record),
64
- data: { turbo_frame: :resource_modal },
64
+ data: { turbo_frame: :resource_form },
65
65
  class: 'body-link'
66
66
  end
67
67
  }
@@ -1,15 +1,15 @@
1
- <%= turbo_frame_tag :resource_modal, target: "_top" do %>
1
+ <%= turbo_frame_tag :resource_form, target: "_top" do %>
2
2
  <%= render component("ui/modal").new(title: t(".title")) do |modal| %>
3
- <%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>
3
+ <%= solidus_form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>
4
4
  <div class="flex flex-col gap-6 pb-4">
5
- <%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
6
- <%= render component("ui/forms/field").text_field(f, :code, class: "required") %>
5
+ <%= f.text_field(:name, class: "required") %>
6
+ <%= f.text_field(:code, class: "required") %>
7
7
  </div>
8
8
  <% modal.with_actions do %>
9
9
  <form method="dialog">
10
10
  <%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
11
11
  </form>
12
- <%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
12
+ <%= f.submit %>
13
13
  <% end %>
14
14
  <% end %>
15
15
  <% end %>
@@ -1,4 +1,3 @@
1
1
  en:
2
2
  title: "New Promotion Category"
3
3
  cancel: "Cancel"
4
- submit: "Add Promotion Category"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_legacy_promotions
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.5.0
4
+ version: 4.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-20 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: csv
@@ -29,28 +29,28 @@ dependencies:
29
29
  requirements:
30
30
  - - '='
31
31
  - !ruby/object:Gem::Version
32
- version: 4.5.0
32
+ version: 4.6.0
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - '='
38
38
  - !ruby/object:Gem::Version
39
- version: 4.5.0
39
+ version: 4.6.0
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: solidus_core
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - '='
45
45
  - !ruby/object:Gem::Version
46
- version: 4.5.0
46
+ version: 4.6.0
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - '='
52
52
  - !ruby/object:Gem::Version
53
- version: 4.5.0
53
+ version: 4.6.0
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: solidus_support
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -152,6 +152,7 @@ files:
152
152
  - app/patches/models/solidus_legacy_promotions/spree_order_updater_patch.rb
153
153
  - app/patches/models/solidus_legacy_promotions/spree_product_patch.rb
154
154
  - app/patches/models/solidus_legacy_promotions/spree_shipment_patch.rb
155
+ - app/patches/models/solidus_legacy_promotions/spree_taxon_patch.rb
155
156
  - app/subscribers/spree/order_promotion_subscriber.rb
156
157
  - app/views/spree/order_mailer/cancel_email.html.erb
157
158
  - app/views/spree/order_mailer/cancel_email.text.erb
@@ -278,7 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
278
279
  - !ruby/object:Gem::Version
279
280
  version: 1.8.23
280
281
  requirements: []
281
- rubygems_version: 3.6.3
282
+ rubygems_version: 3.6.9
282
283
  specification_version: 4
283
284
  summary: Legacy Solidus promotion system
284
285
  test_files: []