solidus_promotions 4.5.1 → 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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/models/solidus_promotions/benefit.rb +3 -5
- data/app/models/solidus_promotions/benefits/adjust_line_item_quantity_groups.rb +1 -1
- data/app/models/solidus_promotions/calculators/flexi_rate.rb +1 -1
- data/app/models/solidus_promotions/calculators/percent_with_cap.rb +19 -0
- data/app/models/solidus_promotions/calculators/tiered_flat_rate.rb +0 -2
- data/app/models/solidus_promotions/calculators/tiered_percent.rb +0 -2
- data/app/models/solidus_promotions/condition.rb +1 -3
- data/app/models/solidus_promotions/condition_product.rb +2 -2
- data/app/models/solidus_promotions/condition_store.rb +2 -2
- data/app/models/solidus_promotions/condition_taxon.rb +2 -2
- data/app/models/solidus_promotions/condition_user.rb +2 -2
- data/app/models/solidus_promotions/conditions/first_order.rb +1 -1
- data/app/models/solidus_promotions/conditions/line_item_product.rb +2 -1
- data/app/models/solidus_promotions/conditions/line_item_taxon.rb +5 -2
- data/app/models/solidus_promotions/conditions/product.rb +2 -1
- data/app/models/solidus_promotions/conditions/store.rb +4 -2
- data/app/models/solidus_promotions/conditions/taxon.rb +5 -2
- data/app/models/solidus_promotions/conditions/user.rb +2 -1
- data/app/models/solidus_promotions/load_promotions.rb +51 -0
- data/app/models/solidus_promotions/order_adjuster/load_promotions.rb +4 -45
- data/app/models/solidus_promotions/order_adjuster.rb +4 -1
- data/app/models/solidus_promotions/order_promotion.rb +1 -1
- data/app/models/solidus_promotions/promotion.rb +5 -2
- data/config/locales/en.yml +8 -0
- data/lib/components/admin/solidus_promotions/promotion_categories/edit/component.html.erb +5 -5
- data/lib/components/admin/solidus_promotions/promotion_categories/edit/component.yml +0 -1
- data/lib/components/admin/solidus_promotions/promotion_categories/index/component.rb +4 -4
- data/lib/components/admin/solidus_promotions/promotion_categories/new/component.html.erb +5 -5
- data/lib/components/admin/solidus_promotions/promotion_categories/new/component.yml +0 -1
- data/lib/generators/solidus_promotions/install/install_generator.rb +1 -1
- data/lib/solidus_promotions/promotion_migrator.rb +7 -4
- data/lib/tasks/solidus_promotions/migrate_existing_promotions.rake +1 -1
- data/lib/views/backend/solidus_promotions/admin/calculator_fields/_default_fields.html.erb +1 -1
- data/solidus_promotions.gemspec +1 -1
- metadata +15 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9f99870cc08ee90fd5ed318b5ac28e0c600bfbf2e51409d2a9633f45da6e5db
|
4
|
+
data.tar.gz: '01182178d5ec81589d8079c88db347de3dd4e94c53ccfcaf76683de82f0ed8d7'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ed22fba9578d4f479c23187be996c848bf893a2832abf702fa21e9e72d1d0f7a141aaf8a6dba9ecb2d1b1fd72d1ddbbcb7b2f92346e122ddc9326f7433b2d40
|
7
|
+
data.tar.gz: 240167352cd02bd3b82ce6e24608b1d252cf223d08f92827c0ca7942e622fca392a50bc78afc8f54e8269a39d14f56d350d347ce50d7816096ee14b407ce8e4a
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ end
|
|
32
32
|
|
33
33
|
### Types of Benefits
|
34
34
|
|
35
|
-
The new Solidus Promotions Systems ships with three benefit types: `AdjustLineItem`, `AdjustShipment` and `CreateDiscountedItem`. To allow more efficient processing of returns and reduce the complexity for bookkeping and support
|
35
|
+
The new Solidus Promotions Systems ships with three benefit types: `AdjustLineItem`, `AdjustShipment` and `CreateDiscountedItem`. To allow more efficient processing of returns and reduce the complexity for bookkeping and support departments fixed discount to all line items in an order can now be given through the `AdjustLineItem` benefit through the `DistributedAmount` calculator significantly reducing administration issues with refunds.
|
36
36
|
|
37
37
|
#### `AdjustLineItem`
|
38
38
|
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "spree/preferences/persistable"
|
4
|
-
|
5
3
|
module SolidusPromotions
|
6
4
|
# Base class for all types of benefit.
|
7
5
|
#
|
@@ -16,8 +14,8 @@ module SolidusPromotions
|
|
16
14
|
|
17
15
|
belongs_to :promotion, inverse_of: :benefits
|
18
16
|
belongs_to :original_promotion_action, class_name: "Spree::PromotionAction", optional: true
|
19
|
-
has_many :adjustments, class_name: "Spree::Adjustment", as: :source
|
20
|
-
has_many :shipping_rate_discounts, class_name: "SolidusPromotions::ShippingRateDiscount", inverse_of: :benefit
|
17
|
+
has_many :adjustments, class_name: "Spree::Adjustment", as: :source, dependent: :restrict_with_error
|
18
|
+
has_many :shipping_rate_discounts, class_name: "SolidusPromotions::ShippingRateDiscount", inverse_of: :benefit, dependent: :restrict_with_error
|
21
19
|
has_many :conditions, class_name: "SolidusPromotions::Condition", inverse_of: :benefit, dependent: :destroy
|
22
20
|
|
23
21
|
scope :of_type, ->(type) { where(type: Array.wrap(type).map(&:to_s)) }
|
@@ -44,7 +42,7 @@ module SolidusPromotions
|
|
44
42
|
|
45
43
|
# Ensure a negative amount which does not exceed the object's amount
|
46
44
|
def compute_amount(adjustable)
|
47
|
-
promotion_amount = calculator.compute(adjustable) ||
|
45
|
+
promotion_amount = calculator.compute(adjustable) || Spree::ZERO
|
48
46
|
[adjustable.discountable_amount, promotion_amount.abs].min * -1
|
49
47
|
end
|
50
48
|
|
@@ -53,7 +53,7 @@ module SolidusPromotions
|
|
53
53
|
#
|
54
54
|
def compute_amount(line_item)
|
55
55
|
adjustment_amount = calculator.compute(Item.new(line_item))
|
56
|
-
return
|
56
|
+
return Spree::ZERO if adjustment_amount.nil? || adjustment_amount.zero?
|
57
57
|
|
58
58
|
adjustment_amount = adjustment_amount.abs
|
59
59
|
|
@@ -16,7 +16,7 @@ module SolidusPromotions
|
|
16
16
|
items_count = object.quantity
|
17
17
|
items_count = [items_count, preferred_max_items].min unless preferred_max_items.zero?
|
18
18
|
|
19
|
-
return
|
19
|
+
return Spree::ZERO if items_count == 0
|
20
20
|
|
21
21
|
additional_items_count = items_count - 1
|
22
22
|
preferred_first_item + preferred_additional_item * additional_items_count
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusPromotions
|
4
|
+
module Calculators
|
5
|
+
class PercentWithCap < Percent
|
6
|
+
preference :max_amount, :integer, default: 100
|
7
|
+
|
8
|
+
def compute(line_item)
|
9
|
+
percent_discount = super
|
10
|
+
max_discount = DistributedAmount.new(
|
11
|
+
calculable:,
|
12
|
+
preferred_amount: preferred_max_amount
|
13
|
+
).compute_line_item(line_item)
|
14
|
+
|
15
|
+
[percent_discount, max_discount].min
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "spree/preferences/persistable"
|
4
|
-
|
5
3
|
module SolidusPromotions
|
6
4
|
class Condition < Spree::Base
|
7
5
|
include Spree::Preferences::Persistable
|
8
6
|
|
9
|
-
belongs_to :benefit, class_name: "SolidusPromotions::Benefit", inverse_of: :conditions
|
7
|
+
belongs_to :benefit, class_name: "SolidusPromotions::Benefit", inverse_of: :conditions
|
10
8
|
has_one :promotion, through: :benefit
|
11
9
|
|
12
10
|
scope :of_type, ->(type) { where(type: type) }
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module SolidusPromotions
|
4
4
|
class ConditionProduct < Spree::Base
|
5
|
-
belongs_to :condition, class_name: "SolidusPromotions::Condition"
|
6
|
-
belongs_to :product, class_name: "Spree::Product"
|
5
|
+
belongs_to :condition, class_name: "SolidusPromotions::Condition"
|
6
|
+
belongs_to :product, class_name: "Spree::Product"
|
7
7
|
end
|
8
8
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module SolidusPromotions
|
4
4
|
class ConditionStore < Spree::Base
|
5
|
-
belongs_to :condition, class_name: "SolidusPromotions::Condition"
|
6
|
-
belongs_to :store, class_name: "Spree::Store"
|
5
|
+
belongs_to :condition, class_name: "SolidusPromotions::Condition"
|
6
|
+
belongs_to :store, class_name: "Spree::Store"
|
7
7
|
end
|
8
8
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module SolidusPromotions
|
4
4
|
class ConditionTaxon < Spree::Base
|
5
|
-
belongs_to :condition, class_name: "SolidusPromotions::Condition"
|
6
|
-
belongs_to :taxon, class_name: "Spree::Taxon"
|
5
|
+
belongs_to :condition, class_name: "SolidusPromotions::Condition"
|
6
|
+
belongs_to :taxon, class_name: "Spree::Taxon"
|
7
7
|
end
|
8
8
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module SolidusPromotions
|
4
4
|
class ConditionUser < Spree::Base
|
5
|
-
belongs_to :condition, class_name: "SolidusPromotions::Condition"
|
6
|
-
belongs_to :user, class_name: Spree::UserClassHandle.new
|
5
|
+
belongs_to :condition, class_name: "SolidusPromotions::Condition"
|
6
|
+
belongs_to :user, class_name: Spree::UserClassHandle.new
|
7
7
|
end
|
8
8
|
end
|
@@ -10,7 +10,7 @@ module SolidusPromotions
|
|
10
10
|
@user = order.try(:user) || options[:user]
|
11
11
|
@email = order.email
|
12
12
|
|
13
|
-
if (user || email) &&
|
13
|
+
if (user || email) && completed_orders.present? && completed_orders.first != order
|
14
14
|
eligibility_errors.add(:base, eligibility_error_message(:not_first_order), error_code: :not_first_order)
|
15
15
|
end
|
16
16
|
|
@@ -11,7 +11,8 @@ module SolidusPromotions
|
|
11
11
|
has_many :condition_products,
|
12
12
|
dependent: :destroy,
|
13
13
|
foreign_key: :condition_id,
|
14
|
-
class_name: "SolidusPromotions::ConditionProduct"
|
14
|
+
class_name: "SolidusPromotions::ConditionProduct",
|
15
|
+
inverse_of: :condition
|
15
16
|
has_many :products,
|
16
17
|
class_name: "Spree::Product",
|
17
18
|
through: :condition_products
|
@@ -5,8 +5,11 @@ module SolidusPromotions
|
|
5
5
|
class LineItemTaxon < Condition
|
6
6
|
include LineItemLevelCondition
|
7
7
|
|
8
|
-
has_many :condition_taxons,
|
9
|
-
|
8
|
+
has_many :condition_taxons,
|
9
|
+
class_name: "SolidusPromotions::ConditionTaxon",
|
10
|
+
foreign_key: :condition_id,
|
11
|
+
dependent: :destroy,
|
12
|
+
inverse_of: :condition
|
10
13
|
has_many :taxons, through: :condition_taxons, class_name: "Spree::Taxon"
|
11
14
|
|
12
15
|
MATCH_POLICIES = %w[include exclude].freeze
|
@@ -12,7 +12,8 @@ module SolidusPromotions
|
|
12
12
|
has_many :condition_products,
|
13
13
|
dependent: :destroy,
|
14
14
|
foreign_key: :condition_id,
|
15
|
-
class_name: "SolidusPromotions::ConditionProduct"
|
15
|
+
class_name: "SolidusPromotions::ConditionProduct",
|
16
|
+
inverse_of: :condition
|
16
17
|
has_many :products, class_name: "Spree::Product", through: :condition_products
|
17
18
|
|
18
19
|
def preload_relations
|
@@ -5,9 +5,11 @@ module SolidusPromotions
|
|
5
5
|
class Store < Condition
|
6
6
|
include OrderLevelCondition
|
7
7
|
|
8
|
-
has_many :condition_stores,
|
8
|
+
has_many :condition_stores,
|
9
|
+
class_name: "SolidusPromotions::ConditionStore",
|
9
10
|
foreign_key: :condition_id,
|
10
|
-
dependent: :destroy
|
11
|
+
dependent: :destroy,
|
12
|
+
inverse_of: :condition
|
11
13
|
has_many :stores, through: :condition_stores, class_name: "Spree::Store"
|
12
14
|
|
13
15
|
def preload_relations
|
@@ -5,8 +5,11 @@ module SolidusPromotions
|
|
5
5
|
class Taxon < Condition
|
6
6
|
include LineItemApplicableOrderLevelCondition
|
7
7
|
|
8
|
-
has_many :condition_taxons,
|
9
|
-
|
8
|
+
has_many :condition_taxons,
|
9
|
+
class_name: "SolidusPromotions::ConditionTaxon",
|
10
|
+
foreign_key: :condition_id,
|
11
|
+
dependent: :destroy,
|
12
|
+
inverse_of: :condition
|
10
13
|
has_many :taxons, through: :condition_taxons, class_name: "Spree::Taxon"
|
11
14
|
|
12
15
|
def preload_relations
|
@@ -8,7 +8,8 @@ module SolidusPromotions
|
|
8
8
|
has_many :condition_users,
|
9
9
|
class_name: "SolidusPromotions::ConditionUser",
|
10
10
|
foreign_key: :condition_id,
|
11
|
-
dependent: :destroy
|
11
|
+
dependent: :destroy,
|
12
|
+
inverse_of: :condition
|
12
13
|
has_many :users, through: :condition_users, class_name: Spree::UserClassHandle.new
|
13
14
|
|
14
15
|
def preload_relations
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusPromotions
|
4
|
+
class LoadPromotions
|
5
|
+
def initialize(order:, dry_run_promotion: nil)
|
6
|
+
@order = order
|
7
|
+
@dry_run_promotion = dry_run_promotion
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
promos = connected_order_promotions | sale_promotions
|
12
|
+
promos << dry_run_promotion if dry_run_promotion
|
13
|
+
promos.flat_map(&:benefits).group_by(&:preload_relations).each do |benefit_preload_relations, benefits|
|
14
|
+
preload(records: benefits, associations: benefit_preload_relations)
|
15
|
+
benefits.flat_map(&:conditions).group_by(&:preload_relations).each do |condition_preload_relations, conditions|
|
16
|
+
preload(records: conditions, associations: condition_preload_relations)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
promos.reject { |promotion| promotion.usage_limit_exceeded?(excluded_orders: [order]) }
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :order, :dry_run_promotion
|
25
|
+
|
26
|
+
def preload(records:, associations:)
|
27
|
+
ActiveRecord::Associations::Preloader.new(records: records, associations: associations).call
|
28
|
+
end
|
29
|
+
|
30
|
+
def connected_order_promotions
|
31
|
+
eligible_connected_promotion_ids = order.solidus_order_promotions.select do |order_promotion|
|
32
|
+
order_promotion.promotion.kept? && (order_promotion.promotion_code.nil? || !order_promotion.promotion_code.usage_limit_exceeded?(excluded_orders: [order]))
|
33
|
+
end.map(&:promotion_id)
|
34
|
+
order.solidus_promotions.active(reference_time).where(id: eligible_connected_promotion_ids).includes(promotion_includes)
|
35
|
+
end
|
36
|
+
|
37
|
+
def sale_promotions
|
38
|
+
SolidusPromotions::Promotion.kept.where(apply_automatically: true).active(reference_time).includes(promotion_includes)
|
39
|
+
end
|
40
|
+
|
41
|
+
def reference_time
|
42
|
+
order.completed_at || Time.current
|
43
|
+
end
|
44
|
+
|
45
|
+
def promotion_includes
|
46
|
+
{
|
47
|
+
benefits: :conditions
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -2,51 +2,10 @@
|
|
2
2
|
|
3
3
|
module SolidusPromotions
|
4
4
|
class OrderAdjuster
|
5
|
-
class LoadPromotions
|
6
|
-
def initialize(
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
def call
|
12
|
-
promos = connected_order_promotions | sale_promotions
|
13
|
-
promos << dry_run_promotion if dry_run_promotion
|
14
|
-
promos.flat_map(&:benefits).group_by(&:preload_relations).each do |benefit_preload_relations, benefits|
|
15
|
-
preload(records: benefits, associations: benefit_preload_relations)
|
16
|
-
benefits.flat_map(&:conditions).group_by(&:preload_relations).each do |condition_preload_relations, conditions|
|
17
|
-
preload(records: conditions, associations: condition_preload_relations)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
promos.reject { |promotion| promotion.usage_limit_exceeded?(excluded_orders: [order]) }
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
attr_reader :order, :dry_run_promotion
|
26
|
-
|
27
|
-
def preload(records:, associations:)
|
28
|
-
ActiveRecord::Associations::Preloader.new(records: records, associations: associations).call
|
29
|
-
end
|
30
|
-
|
31
|
-
def connected_order_promotions
|
32
|
-
eligible_connected_promotion_ids = order.solidus_order_promotions.select do |order_promotion|
|
33
|
-
order_promotion.promotion.kept? && (order_promotion.promotion_code.nil? || !order_promotion.promotion_code.usage_limit_exceeded?(excluded_orders: [order]))
|
34
|
-
end.map(&:promotion_id)
|
35
|
-
order.solidus_promotions.active(reference_time).where(id: eligible_connected_promotion_ids).includes(promotion_includes)
|
36
|
-
end
|
37
|
-
|
38
|
-
def sale_promotions
|
39
|
-
SolidusPromotions::Promotion.kept.where(apply_automatically: true).active(reference_time).includes(promotion_includes)
|
40
|
-
end
|
41
|
-
|
42
|
-
def reference_time
|
43
|
-
order.completed_at || Time.current
|
44
|
-
end
|
45
|
-
|
46
|
-
def promotion_includes
|
47
|
-
{
|
48
|
-
benefits: :conditions
|
49
|
-
}
|
5
|
+
class LoadPromotions < SolidusPromotions::LoadPromotions
|
6
|
+
def initialize(...)
|
7
|
+
Spree.deprecator.warn("Please use SolidusPromotions::LoadPromotions instead")
|
8
|
+
super
|
50
9
|
end
|
51
10
|
end
|
52
11
|
end
|
@@ -7,7 +7,10 @@ module SolidusPromotions
|
|
7
7
|
def initialize(order, dry_run_promotion: nil)
|
8
8
|
@order = order
|
9
9
|
@dry_run = !!dry_run_promotion
|
10
|
-
@promotions = LoadPromotions.new(
|
10
|
+
@promotions = SolidusPromotions::LoadPromotions.new(
|
11
|
+
order: order,
|
12
|
+
dry_run_promotion: dry_run_promotion
|
13
|
+
).call
|
11
14
|
end
|
12
15
|
|
13
16
|
def call
|
@@ -7,7 +7,7 @@ module SolidusPromotions
|
|
7
7
|
# 2. The specific code that they used
|
8
8
|
class OrderPromotion < Spree::Base
|
9
9
|
belongs_to :order, class_name: "Spree::Order"
|
10
|
-
belongs_to :promotion, -> { with_discarded }, class_name: "SolidusPromotions::Promotion"
|
10
|
+
belongs_to :promotion, -> { with_discarded }, class_name: "SolidusPromotions::Promotion", inverse_of: :order_promotions
|
11
11
|
belongs_to :promotion_code, class_name: "SolidusPromotions::PromotionCode", optional: true
|
12
12
|
|
13
13
|
validates :promotion_code, presence: true, if: :require_promotion_code?
|
@@ -6,8 +6,11 @@ module SolidusPromotions
|
|
6
6
|
|
7
7
|
include Spree::SoftDeletable
|
8
8
|
|
9
|
-
belongs_to :category,
|
10
|
-
|
9
|
+
belongs_to :category,
|
10
|
+
class_name: "SolidusPromotions::PromotionCategory",
|
11
|
+
foreign_key: :promotion_category_id,
|
12
|
+
optional: true,
|
13
|
+
inverse_of: :promotions
|
11
14
|
belongs_to :original_promotion, class_name: "Spree::Promotion", optional: true
|
12
15
|
has_many :benefits, class_name: "SolidusPromotions::Benefit", dependent: :destroy
|
13
16
|
has_many :conditions, through: :benefits
|
data/config/locales/en.yml
CHANGED
@@ -217,6 +217,9 @@ en:
|
|
217
217
|
solidus_promotions/conditions/user: User
|
218
218
|
solidus_promotions/conditions/user_logged_in: User Logged In
|
219
219
|
solidus_promotions/conditions/user_role: User Role(s)
|
220
|
+
solidus_promotions/promotion_category:
|
221
|
+
one: Promotion Category
|
222
|
+
other: Promotion Categories
|
220
223
|
solidus_promotions/promotion_code_batch:
|
221
224
|
one: Code batch
|
222
225
|
other: Code batches
|
@@ -311,6 +314,10 @@ en:
|
|
311
314
|
preferred_currency: Currency
|
312
315
|
solidus_promotions/calculators/percent:
|
313
316
|
description: Provides a discount calculated by percent of the discountable amount of the item being discounted
|
317
|
+
preferred_percent: Percent
|
318
|
+
solidus_promotions/calculators/percent_with_cap:
|
319
|
+
description: Calculates a discount by percent of the discountable amount of the item being discounted, with a cap on the maximum discount.
|
320
|
+
preferred_max_amount: Maximum Amount
|
314
321
|
solidus_promotions/calculators/distributed_amount:
|
315
322
|
description: Distributes the configured amount among all eligible line items of the order.
|
316
323
|
explanation: |
|
@@ -350,6 +357,7 @@ en:
|
|
350
357
|
</tbody>
|
351
358
|
</table>
|
352
359
|
preferred_amount: Amount
|
360
|
+
preferred_currency: Currency
|
353
361
|
|
354
362
|
errors:
|
355
363
|
models:
|
@@ -1,15 +1,15 @@
|
|
1
|
-
<%= turbo_frame_tag :
|
1
|
+
<%= turbo_frame_tag :resource_form, target: "_top" do %>
|
2
2
|
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
|
3
|
-
<%=
|
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
|
-
<%=
|
6
|
-
<%=
|
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
|
-
<%=
|
12
|
+
<%= f.submit %>
|
13
13
|
<% end %>
|
14
14
|
<% end %>
|
15
15
|
<% end %>
|
@@ -14,7 +14,7 @@ class SolidusPromotions::PromotionCategories::Index::Component < SolidusAdmin::U
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def turbo_frames
|
17
|
-
%w[
|
17
|
+
%w[resource_form]
|
18
18
|
end
|
19
19
|
|
20
20
|
def page_actions
|
@@ -22,7 +22,7 @@ class SolidusPromotions::PromotionCategories::Index::Component < SolidusAdmin::U
|
|
22
22
|
tag: :a,
|
23
23
|
text: t(".add"),
|
24
24
|
href: solidus_promotions.new_promotion_category_path(**search_filter_params),
|
25
|
-
data: { turbo_frame: :
|
25
|
+
data: { turbo_frame: :resource_form },
|
26
26
|
icon: "add-line"
|
27
27
|
)
|
28
28
|
end
|
@@ -50,7 +50,7 @@ class SolidusPromotions::PromotionCategories::Index::Component < SolidusAdmin::U
|
|
50
50
|
header: :name,
|
51
51
|
data: ->(record) do
|
52
52
|
link_to record.name, edit_path(record),
|
53
|
-
data: { turbo_frame: :
|
53
|
+
data: { turbo_frame: :resource_form },
|
54
54
|
class: 'body-link'
|
55
55
|
end
|
56
56
|
}
|
@@ -61,7 +61,7 @@ class SolidusPromotions::PromotionCategories::Index::Component < SolidusAdmin::U
|
|
61
61
|
header: :code,
|
62
62
|
data: ->(record) do
|
63
63
|
link_to record.code, edit_path(record),
|
64
|
-
data: { turbo_frame: :
|
64
|
+
data: { turbo_frame: :resource_form },
|
65
65
|
class: 'body-link'
|
66
66
|
end
|
67
67
|
}
|
@@ -1,15 +1,15 @@
|
|
1
|
-
<%= turbo_frame_tag :
|
1
|
+
<%= turbo_frame_tag :resource_form, target: "_top" do %>
|
2
2
|
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
|
3
|
-
<%=
|
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
|
-
<%=
|
6
|
-
<%=
|
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
|
-
<%=
|
12
|
+
<%= f.submit %>
|
13
13
|
<% end %>
|
14
14
|
<% end %>
|
15
15
|
<% end %>
|
@@ -1,12 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "logger"
|
4
|
+
|
3
5
|
module SolidusPromotions
|
4
6
|
class PromotionMigrator
|
5
7
|
PROMOTION_IGNORED_ATTRIBUTES = ["id", "type", "promotion_category_id", "promotion_id"]
|
6
8
|
|
7
|
-
attr_reader :promotion_map
|
9
|
+
attr_reader :promotion_map, :logger
|
8
10
|
|
9
|
-
def initialize(promotion_map)
|
11
|
+
def initialize(promotion_map, logger: nil)
|
12
|
+
@logger = logger || Logger.new($stdout)
|
10
13
|
@promotion_map = promotion_map
|
11
14
|
end
|
12
15
|
|
@@ -78,7 +81,7 @@ module SolidusPromotions
|
|
78
81
|
def generate_new_benefits(old_promotion_action)
|
79
82
|
promo_action_config = promotion_map[:actions][old_promotion_action.class]
|
80
83
|
if promo_action_config.nil?
|
81
|
-
|
84
|
+
logger.info("#{old_promotion_action.class} is not supported")
|
82
85
|
return nil
|
83
86
|
end
|
84
87
|
promo_action_config.call(old_promotion_action)
|
@@ -87,7 +90,7 @@ module SolidusPromotions
|
|
87
90
|
def generate_new_promotion_conditions(old_promotion_rule)
|
88
91
|
new_promo_condition_class = promotion_map[:conditions][old_promotion_rule.class]
|
89
92
|
if new_promo_condition_class.nil?
|
90
|
-
|
93
|
+
logger.info("#{old_promotion_rule.class} is not supported")
|
91
94
|
[]
|
92
95
|
elsif new_promo_condition_class.respond_to?(:call)
|
93
96
|
new_promo_condition_class.call(old_promotion_rule)
|
@@ -7,6 +7,6 @@ namespace :solidus_promotions do
|
|
7
7
|
task migrate_existing_promotions: :environment do
|
8
8
|
require "solidus_promotions/promotion_map"
|
9
9
|
|
10
|
-
SolidusPromotions::PromotionMigrator.new(SolidusPromotions::PROMOTION_MAP).call
|
10
|
+
SolidusPromotions::PromotionMigrator.new(SolidusPromotions::PROMOTION_MAP, logger: Rails.logger).call
|
11
11
|
end
|
12
12
|
end
|
@@ -2,5 +2,5 @@
|
|
2
2
|
<%= render "solidus_promotions/admin/shared/preference_fields/#{calculator.preference_type(name)}",
|
3
3
|
name: "#{prefix}[calculator_attributes][preferred_#{name}]",
|
4
4
|
value: calculator.get_preference(name),
|
5
|
-
label: t(name
|
5
|
+
label: calculator.class.human_attribute_name("preferred_#{name}", default: I18n.t(name, scope: :spree, default: name.humanize)) %>
|
6
6
|
<% end %>
|
data/solidus_promotions.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.files = files.grep_v(%r{^(spec|bin)/})
|
26
26
|
|
27
27
|
spec.add_dependency "csv", "~> 3.0"
|
28
|
-
spec.add_dependency "importmap-rails", "
|
28
|
+
spec.add_dependency "importmap-rails", [">= 2.0", "< 3"]
|
29
29
|
spec.add_dependency "ransack-enum", "~> 1.0"
|
30
30
|
spec.add_dependency "solidus_core", [">= 4.0.0", "< 5"]
|
31
31
|
spec.add_dependency "solidus_support", ">= 0.12.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_promotions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Meyerhoff
|
8
8
|
- Solidus Team
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: csv
|
@@ -28,16 +28,22 @@ dependencies:
|
|
28
28
|
name: importmap-rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.0'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '3'
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- - "
|
41
|
+
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
43
|
+
version: '2.0'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: ransack-enum
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -162,6 +168,7 @@ files:
|
|
162
168
|
- app/models/solidus_promotions/calculators/flat_rate.rb
|
163
169
|
- app/models/solidus_promotions/calculators/flexi_rate.rb
|
164
170
|
- app/models/solidus_promotions/calculators/percent.rb
|
171
|
+
- app/models/solidus_promotions/calculators/percent_with_cap.rb
|
165
172
|
- app/models/solidus_promotions/calculators/tiered_flat_rate.rb
|
166
173
|
- app/models/solidus_promotions/calculators/tiered_percent.rb
|
167
174
|
- app/models/solidus_promotions/calculators/tiered_percent_on_eligible_item_quantity.rb
|
@@ -192,6 +199,7 @@ files:
|
|
192
199
|
- app/models/solidus_promotions/eligibility_result.rb
|
193
200
|
- app/models/solidus_promotions/eligibility_results.rb
|
194
201
|
- app/models/solidus_promotions/item_discount.rb
|
202
|
+
- app/models/solidus_promotions/load_promotions.rb
|
195
203
|
- app/models/solidus_promotions/migration_support/order_promotion_syncer.rb
|
196
204
|
- app/models/solidus_promotions/order_adjuster.rb
|
197
205
|
- app/models/solidus_promotions/order_adjuster/choose_discounts.rb
|
@@ -376,7 +384,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
376
384
|
- !ruby/object:Gem::Version
|
377
385
|
version: '0'
|
378
386
|
requirements: []
|
379
|
-
rubygems_version: 3.6.
|
387
|
+
rubygems_version: 3.6.9
|
380
388
|
specification_version: 4
|
381
389
|
summary: New promotion system for Solidus
|
382
390
|
test_files: []
|