solidus_promotions 4.4.1 → 4.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d6349051a6426b230165c4ddb9d0f3e3dc90ea2c27ed9e80b5968757135fe67
4
- data.tar.gz: d51b5804b5bcdcfed387a4508bc4cbd7593ee311284b51886cde909423fab6e6
3
+ metadata.gz: 6c806b16cf91750622bd6577afe715ac790b156131f78111827f6fd357cd3fcb
4
+ data.tar.gz: 35a5c2ec0bbf7d6edb53b1322da77c4128336ae805d94c4579e9e40e25ad574b
5
5
  SHA512:
6
- metadata.gz: 014bfa7ca43f1c7033656d059e26dd7822188b3c024e5e8ca80ef88c981d6569b5abba6712a230ecb15129baf9f94757af9c6bb2b98b5450d63a18c5c2ce1434
7
- data.tar.gz: b5e9de86e525f26598e37514f2314e3ee47d5ce9c03cfcfae618f92e18f75ef540da6aa43d36e31dd5a4eafc0491c1003b6a6dff82878eec40a4916962bcdee4
6
+ metadata.gz: 8a470f82057f41699defd90c694caba8c525ff7d54b0672c0f1ea27b5bf9786512b6b2f87b4d0f4f9c326c7e0a8b2bf6c6a4660589285f58509ff67c2d6e7030
7
+ data.tar.gz: 74f76a2e69d156e4104dd80934867fa96fac155df112c5799309e715475f9be5a6f4ca92d2aac49d4aecc6acd0fd06eaacc3cf9113ab103be8225a7e666c74e2
@@ -13,7 +13,7 @@ module SolidusPromotions
13
13
  def call
14
14
  order.reset_current_discounts
15
15
 
16
- return order if (!SolidusPromotions.config.recalculate_complete_orders && order.complete?) || order.shipped?
16
+ return order unless SolidusPromotions::Promotion.order_activatable?(order)
17
17
 
18
18
  discounted_order = DiscountOrder.new(order, promotions, dry_run: dry_run).call
19
19
 
@@ -2,6 +2,8 @@
2
2
 
3
3
  module SolidusPromotions
4
4
  class Promotion < Spree::Base
5
+ UNACTIVATABLE_ORDER_STATES = ["awaiting_return", "returned", "canceled"]
6
+
5
7
  include Spree::SoftDeletable
6
8
 
7
9
  belongs_to :category, class_name: "SolidusPromotions::PromotionCategory",
@@ -9,7 +11,7 @@ module SolidusPromotions
9
11
  belongs_to :original_promotion, class_name: "Spree::Promotion", optional: true
10
12
  has_many :benefits, class_name: "SolidusPromotions::Benefit", dependent: :destroy
11
13
  has_many :conditions, through: :benefits
12
- has_many :codes, class_name: "SolidusPromotions::PromotionCode", dependent: :destroy
14
+ has_many :codes, class_name: "SolidusPromotions::PromotionCode", dependent: :destroy, inverse_of: :promotion
13
15
  has_many :code_batches, class_name: "SolidusPromotions::PromotionCodeBatch", dependent: :destroy
14
16
  has_many :order_promotions, class_name: "SolidusPromotions::OrderPromotion", dependent: :destroy
15
17
 
@@ -59,6 +61,14 @@ module SolidusPromotions
59
61
  lanes.sort_by(&:last).to_h
60
62
  end
61
63
 
64
+ def self.order_activatable?(order)
65
+ return false if UNACTIVATABLE_ORDER_STATES.include?(order.state)
66
+ return false if order.shipped?
67
+ return false if order.complete? && !SolidusPromotions.config.recalculate_complete_orders
68
+
69
+ true
70
+ end
71
+
62
72
  self.allowed_ransackable_associations = ["codes"]
63
73
  self.allowed_ransackable_attributes = %w[name customer_label path promotion_category_id lane updated_at]
64
74
  self.allowed_ransackable_scopes = %i[active with_discarded]
@@ -26,6 +26,10 @@ module SolidusPromotions
26
26
  self
27
27
  end
28
28
 
29
+ def can_apply?
30
+ SolidusPromotions::Promotion.order_activatable?(order)
31
+ end
32
+
29
33
  def remove
30
34
  if promotion.blank?
31
35
  set_error_code :coupon_code_not_found
@@ -14,7 +14,7 @@ class SolidusPromotions::Promotions::Index::Component < SolidusAdmin::UI::Pages:
14
14
  end
15
15
 
16
16
  def row_url(promotion)
17
- solidus_promotions.admin_promotion_path(promotion)
17
+ solidus_promotions.edit_admin_promotion_path(promotion)
18
18
  end
19
19
 
20
20
  def page_actions
@@ -63,14 +63,16 @@ class SolidusPromotions::Promotions::Index::Component < SolidusAdmin::UI::Pages:
63
63
  {
64
64
  header: :name,
65
65
  data: ->(promotion) do
66
- content_tag :div, promotion.name
66
+ link_to promotion.name, row_url(promotion)
67
67
  end
68
68
  },
69
69
  {
70
70
  header: :code,
71
71
  data: ->(promotion) do
72
- count = promotion.codes.count
73
- (count == 1) ? promotion.codes.pick(:value) : t("spree.number_of_codes", count: count)
72
+ link_to solidus_promotions.admin_promotion_promotion_codes_path(promotion), title: t(".codes") do
73
+ count = promotion.codes.count
74
+ (count == 1) ? promotion.codes.pick(:value) : t("spree.number_of_codes", count: count)
75
+ end
74
76
  end
75
77
  },
76
78
  {
@@ -8,3 +8,4 @@ en:
8
8
  status:
9
9
  active: Active
10
10
  inactive: Inactive
11
+ codes: Codes
@@ -25,5 +25,11 @@ module SolidusPromotions
25
25
  flash[:notice] = t(".success")
26
26
  redirect_back_or_to solidus_promotions.promotion_categories_path, status: :see_other
27
27
  end
28
+
29
+ private
30
+
31
+ def authorization_subject
32
+ SolidusPromotions::PromotionCategory
33
+ end
28
34
  end
29
35
  end
@@ -42,5 +42,9 @@ module SolidusPromotions
42
42
  def promotion_params
43
43
  params.require(:promotion).permit(:user_id, permitted_promotion_attributes)
44
44
  end
45
+
46
+ def authorization_subject
47
+ SolidusPromotions::Promotion
48
+ end
45
49
  end
46
50
  end
@@ -14,12 +14,12 @@ module SolidusPromotions
14
14
  def create
15
15
  @benefit = @benefit_type.new(benefit_params)
16
16
  @benefit.promotion = @promotion
17
- if @benefit.save(validate: false)
17
+ if @benefit.save
18
18
  flash[:success] =
19
19
  t("spree.successfully_created", resource: SolidusPromotions::Benefit.model_name.human)
20
20
  redirect_to location_after_save, format: :html
21
21
  else
22
- render :new, layout: false
22
+ render :new, layout: false, status: :unprocessable_entity
23
23
  end
24
24
  end
25
25
 
@@ -28,7 +28,7 @@ module SolidusPromotions
28
28
  if params.dig(:benefit, :calculator_type)
29
29
  @benefit.calculator_type = params[:benefit][:calculator_type]
30
30
  end
31
- render layout: false
31
+ render layout: false, status: :unprocessable_entity
32
32
  end
33
33
 
34
34
  def update
@@ -39,7 +39,7 @@ module SolidusPromotions
39
39
  t("spree.successfully_updated", resource: SolidusPromotions::Benefit.model_name.human)
40
40
  redirect_to location_after_save, format: :html
41
41
  else
42
- render :edit
42
+ render :edit, status: :unprocessable_entity
43
43
  end
44
44
  end
45
45
 
@@ -48,6 +48,10 @@ module SolidusPromotions
48
48
 
49
49
  private
50
50
 
51
+ def model_class
52
+ SolidusPromotions::PromotionCode
53
+ end
54
+
51
55
  def load_promotion
52
56
  @promotion = SolidusPromotions::Promotion
53
57
  .accessible_by(current_ability, :show)
@@ -24,6 +24,8 @@ Gem::Specification.new do |spec|
24
24
  files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
25
25
  spec.files = files.grep_v(%r{^(spec|bin)/})
26
26
 
27
+ spec.add_development_dependency "solidus_legacy_promotions"
28
+
27
29
  spec.add_dependency "importmap-rails", "~> 1.2"
28
30
  spec.add_dependency "ransack-enum", "~> 1.0"
29
31
  spec.add_dependency "solidus_core", [">= 4.0.0", "< 5"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_promotions
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.1
4
+ version: 4.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Meyerhoff
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-11-18 00:00:00.000000000 Z
12
+ date: 2024-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: solidus_legacy_promotions
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: importmap-rails
16
30
  requirement: !ruby/object:Gem::Requirement
@@ -358,7 +372,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
358
372
  - !ruby/object:Gem::Version
359
373
  version: '0'
360
374
  requirements: []
361
- rubygems_version: 3.5.22
375
+ rubygems_version: 3.5.3
362
376
  signing_key:
363
377
  specification_version: 4
364
378
  summary: New promotion system for Solidus