solidus_friendly_promotions 1.0.0 → 1.0.1

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: 5cc3437f15c2341c8a233e48b1443996b09e923cf84727fb834baa766dd1bee7
4
- data.tar.gz: 9c534dc4a7ce6f3a09bb6c14d046ea8d6c9e313dbea3c5f1e6767000d8eb0cca
3
+ metadata.gz: a6735f8983491ab3b703bc8c095f8331efb28e58b9a59fde2e74a338dc60c03f
4
+ data.tar.gz: 4f4ecb6904c2aba33880b6601bd3a1efb3d72c283f6c1a6aab3167bc2739767d
5
5
  SHA512:
6
- metadata.gz: c345c4dbd052db90957b5a2c886c39c7a328452b616822ce326b2b4170d6b2232be827dc43f7374a33e116fc50b2f9229c5d0b34c46ca3d2a09e26a486319143
7
- data.tar.gz: 9a2ef29fa7045ae95d884903fe80beadacfc6e89f5fa096f61c5c53709f836f3cf76b6483e11fc488d9140ad1720dee41cdd7cb78f22c1649b1bb107540ef609
6
+ metadata.gz: b6a4ae6ae4f22709c40865d60e125f07ac55bd58cf944415f41c6431d8260da20d16f4b33b78d2a0219366c58d13441d5701bc935d09760751a413fceed487e2
7
+ data.tar.gz: 640c4da14f4f8d70fb7f8d9fce147f0344a4812384f44a5da379e61c55a5cafacb0b8ff161f752930523c0ad198dadfd1fd047c577976f1818e28938b5631277
data/.circleci/config.yml CHANGED
@@ -6,7 +6,7 @@ jobs:
6
6
  lint:
7
7
  executor:
8
8
  name: solidusio_extensions/sqlite-memory
9
- ruby_version: '3.0'
9
+ ruby_version: '3.1'
10
10
  steps:
11
11
  - checkout
12
12
  - solidusio_extensions/test-branch:
@@ -15,7 +15,7 @@ jobs:
15
15
  run-specs-with-mysql:
16
16
  executor:
17
17
  name: solidusio_extensions/mysql
18
- ruby_version: '3.1'
18
+ ruby_version: '3.2'
19
19
  steps:
20
20
  - browser-tools/install-chrome
21
21
  - checkout
@@ -25,7 +25,7 @@ jobs:
25
25
  run-specs-with-postgres:
26
26
  executor:
27
27
  name: solidusio_extensions/postgres
28
- ruby_version: '3.2'
28
+ ruby_version: '3.3'
29
29
  steps:
30
30
  - browser-tools/install-chrome
31
31
  - checkout
@@ -35,7 +35,7 @@ jobs:
35
35
  run-specs-with-sqlite:
36
36
  executor:
37
37
  name: solidusio_extensions/sqlite
38
- ruby_version: '3.0'
38
+ ruby_version: '3.1'
39
39
  steps:
40
40
  - browser-tools/install-chrome
41
41
  - checkout
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [v1.0.1](https://github.com/friendlycart/solidus_friendly_promotions/tree/v1.0.1) (2024-05-07)
4
+
5
+ [Full Changelog](https://github.com/friendlycart/solidus_friendly_promotions/compare/v1.0.0...v1.0.1)
6
+
7
+ **Closed issues:**
8
+
9
+ - Ransack scope missing [\#105](https://github.com/friendlycart/solidus_friendly_promotions/issues/105)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Fix selenium path [\#108](https://github.com/friendlycart/solidus_friendly_promotions/pull/108) ([mamhoff](https://github.com/mamhoff))
14
+ - Restrict SQLite to "~\> 1.3" [\#107](https://github.com/friendlycart/solidus_friendly_promotions/pull/107) ([mamhoff](https://github.com/mamhoff))
15
+ - Fix ShippingRateDiscount\#promotion\_action [\#106](https://github.com/friendlycart/solidus_friendly_promotions/pull/106) ([mamhoff](https://github.com/mamhoff))
16
+ - Fix specs [\#104](https://github.com/friendlycart/solidus_friendly_promotions/pull/104) ([mamhoff](https://github.com/mamhoff))
17
+ - Fix Promotion Rule Unique per promotion validation [\#103](https://github.com/friendlycart/solidus_friendly_promotions/pull/103) ([mamhoff](https://github.com/mamhoff))
18
+
3
19
  ## [v1.0.0](https://github.com/friendlycart/solidus_friendly_promotions/tree/v1.0.0) (2024-01-25)
4
20
 
5
21
  [Full Changelog](https://github.com/friendlycart/solidus_friendly_promotions/compare/v1.0.0.rc.3...v1.0.0)
data/Gemfile CHANGED
@@ -24,14 +24,9 @@ when "mysql"
24
24
  when "postgresql"
25
25
  gem "pg"
26
26
  else
27
- gem "sqlite3"
27
+ gem "sqlite3", "~> 1.3"
28
28
  end
29
29
 
30
- # While we still support Ruby < 3 we need to workaround a limitation in
31
- # the 'async' gem that relies on the latest ruby, since RubyGems doesn't
32
- # resolve gems based on the required ruby version.
33
- gem "async", "< 3" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3")
34
-
35
30
  gemspec
36
31
 
37
32
  # Use a local Gemfile to include development dependencies that might not be
@@ -3,7 +3,7 @@
3
3
  module SolidusFriendlyPromotions
4
4
  module Admin
5
5
  class PromotionRulesController < Spree::Admin::BaseController
6
- helper "spree/promotion_rules"
6
+ helper "solidus_friendly_promotions/admin/promotion_rules"
7
7
 
8
8
  before_action :validate_level, only: [:new, :create]
9
9
  before_action :load_promotion, only: [:create, :destroy, :update, :new]
@@ -7,6 +7,7 @@ module SolidusFriendlyPromotions
7
7
 
8
8
  helper "solidus_friendly_promotions/admin/promotion_rules"
9
9
  helper "solidus_friendly_promotions/admin/promotion_actions"
10
+ helper "solidus_friendly_promotions/admin/promotions"
10
11
 
11
12
  def create
12
13
  @promotion = model_class.new(permitted_resource_params)
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusFriendlyPromotions
4
+ module Admin
5
+ module PromotionsHelper
6
+ def admin_promotion_status(promotion)
7
+ return :active if promotion.active?
8
+ return :not_started if promotion.not_started?
9
+ return :expired if promotion.expired?
10
+
11
+ :inactive
12
+ end
13
+ end
14
+ end
15
+ end
@@ -19,6 +19,9 @@ module SolidusFriendlyPromotions
19
19
  validates :per_code_usage_limit, numericality: {greater_than_or_equal_to: 0, allow_nil: true}
20
20
  validates :description, length: {maximum: 255}
21
21
  validate :apply_automatically_disallowed_with_paths
22
+ validate :apply_automatically_disallowed_with_promotion_codes
23
+
24
+ before_save :normalize_blank_values
22
25
 
23
26
  scope :active, ->(time = Time.current) { has_actions.started_and_unexpired(time) }
24
27
  scope :advertised, -> { where(advertise: true) }
@@ -165,10 +168,20 @@ module SolidusFriendlyPromotions
165
168
 
166
169
  private
167
170
 
171
+ def normalize_blank_values
172
+ self[:path] = nil if self[:path].blank?
173
+ end
174
+
168
175
  def apply_automatically_disallowed_with_paths
169
176
  return unless apply_automatically
170
177
 
171
178
  errors.add(:apply_automatically, :disallowed_with_path) if path.present?
172
179
  end
180
+
181
+ def apply_automatically_disallowed_with_promotion_codes
182
+ return unless apply_automatically
183
+
184
+ errors.add(:apply_automatically, :disallowed_with_promotion_codes) if codes.present?
185
+ end
173
186
  end
174
187
  end
@@ -17,6 +17,7 @@ module SolidusFriendlyPromotions
17
17
  belongs_to :promotion, inverse_of: :actions
18
18
  belongs_to :original_promotion_action, class_name: "Spree::PromotionAction", optional: true
19
19
  has_many :adjustments, class_name: "Spree::Adjustment", as: :source
20
+ has_many :shipping_rate_discounts, class_name: "SolidusFriendlyPromotions::ShippingRateDiscount", inverse_of: :promotion_action
20
21
 
21
22
  scope :of_type, ->(type) { where(type: Array.wrap(type).map(&:to_s)) }
22
23
 
@@ -45,7 +45,7 @@ module SolidusFriendlyPromotions
45
45
  def unique_per_promotion
46
46
  return unless self.class.exists?(promotion_id: promotion_id, type: self.class.name)
47
47
 
48
- errors[:base] << "Promotion already contains this rule type"
48
+ errors.add(:promotion, :already_contains_rule_type)
49
49
  end
50
50
 
51
51
  def eligibility_error_message(key, options = {})
@@ -3,7 +3,7 @@
3
3
  module SolidusFriendlyPromotions
4
4
  class ShippingRateDiscount < Spree::Base
5
5
  belongs_to :shipping_rate, inverse_of: :discounts, class_name: "Spree::ShippingRate"
6
- belongs_to :promotion_action, -> { with_discarded }, inverse_of: false
6
+ belongs_to :promotion_action, inverse_of: :shipping_rate_discounts
7
7
 
8
8
  extend Spree::DisplayMoney
9
9
  money_methods :amount
@@ -1,6 +1,6 @@
1
- <% admin_breadcrumb(link_to plural_resource_name(Spree::Promotion), spree.admin_promotions_path) %>
2
- <% admin_breadcrumb(link_to @promotion.name, spree.admin_promotion_path(@promotion.id)) %>
3
- <% admin_breadcrumb(plural_resource_name(Spree::PromotionCodeBatch)) %>
1
+ <% admin_breadcrumb(link_to plural_resource_name(SolidusFriendlyPromotions::Promotion), solidus_friendly_promotions.admin_promotions_path) %>
2
+ <% admin_breadcrumb(link_to @promotion.name, solidus_friendly_promotions.admin_promotion_path(@promotion.id)) %>
3
+ <% admin_breadcrumb(plural_resource_name(SolidusFriendlyPromotions::PromotionCodeBatch)) %>
4
4
  <%= form_for :promotion_code_batch, url: collection_url do |batch| %>
5
5
  <%= batch.hidden_field :promotion_id, value: params[:promotion_id] %>
6
6
  <%= render partial: 'form_fields', locals: {batch: batch, promotion_id: params[:promotion_id]} %>
@@ -85,12 +85,40 @@
85
85
  </div>
86
86
  </fieldset>
87
87
 
88
- <fieldset class="form-group no-border-bottom">
88
+ <fieldset class="form-group row no-border-bottom">
89
89
  <legend><%= t '.activation' %></legend>
90
90
 
91
- <% if @promotion.new_record? %>
92
- <%= render 'spree/admin/promotions/activations_new', f: f %>
93
- <% else %>
94
- <%= render 'spree/admin/promotions/activations_edit', f: f %>
91
+ <div class="col-4">
92
+ <%= f.field_container :apply_automatically do %>
93
+ <%= f.label :apply_automatically do %>
94
+ <%= f.check_box :apply_automatically, disabled: f.object.codes.any? || f.object.path.present? %>
95
+ <%= SolidusFriendlyPromotions::Promotion.human_attribute_name(:apply_automatically) %>
96
+ <%= f.field_hint :promo_code_will_be_disabled %>
97
+ <% end %>
98
+ <% end %>
99
+ </div>
100
+
101
+ <% if f.object.new_record? || f.object.present? %>
102
+ <div class="col-4">
103
+ <%= f.field_container :path do %>
104
+ <%= f.label :path %>
105
+ <%= f.text_field :path, class: "fullwidth", disabled: f.object.apply_automatically || f.object.codes.present? %>
106
+ <% end %>
107
+ </div>
95
108
  <% end %>
109
+
110
+ <div class="col-4">
111
+ <% if f.object.new_record? %>
112
+ <div id="promotion_single_code" class="field">
113
+ <%= label_tag :single_code, SolidusFriendlyPromotions::PromotionCode.model_name.human %>
114
+ <%= text_field_tag :single_code, @promotion.codes.first.try!(:value), class: "fullwidth", disabled: f.object.apply_automatically || f.object.path.present? %>
115
+ </div>
116
+ <% else %>
117
+ <div class="codes-present">
118
+ <p>
119
+ <%= t('.codes_present') %>
120
+ </p>
121
+ </div>
122
+ <% end %>
123
+ </div>
96
124
  </fieldset>
@@ -9,6 +9,13 @@ en:
9
9
  promotion_categories: Promotion Categories
10
10
  legacy_promotions: Legacy Promotions
11
11
  legacy_promotion_categories: Legacy Promotion Categories
12
+ hints:
13
+ solidus_friendly_promotions/calculator:
14
+ promotions: This is used to determine the promotional discount to be applied to an order, an item, or shipping charges.
15
+ solidus_friendly_promotions/promotion:
16
+ expires_at: This determines when the promotion expires. <br> If no value is specified, the promotion will never expire.
17
+ promo_code_will_be_disabled: Selecting this option, promo codes will be disabled for this promotion because all its rules / actions will be applied automatically to all orders.
18
+ starts_at: This determines when the promotion can be applied to orders. <br> If no value is specified, the promotion will be immediately available.
12
19
  solidus_friendly_promotions:
13
20
  actions: Actions
14
21
  adjustment_labels:
@@ -52,9 +59,6 @@ en:
52
59
  match_policies:
53
60
  include: Line item's product has one of the chosen taxons
54
61
  exclude: Line item's product does not have one of the chosen taxons
55
- hints:
56
- solidus_friendly_promotions/calculator:
57
- promotions: This is used to determine the promotional discount to be applied to an order, an item, or shipping charges.
58
62
  coupon_code: Coupon code
59
63
  eligibility_results:
60
64
  coupon_code_applied: The coupon code was successfully applied to your order.
@@ -147,6 +151,7 @@ en:
147
151
  expires_at_placeholder: Never
148
152
  general: General
149
153
  starts_at_placeholder: Immediately
154
+ codes_present: This promotion has promotion codes defined. You cannot select the apply automatically option.
150
155
  edit:
151
156
  order_rules: Order Rules
152
157
  calculator:
@@ -318,6 +323,10 @@ en:
318
323
  attributes:
319
324
  base:
320
325
  cannot_destroy_if_order_completed: Action has been applied to complete orders. It cannot be destroyed.
326
+ solidus_friendly_promotions/promotion_rule:
327
+ attributes:
328
+ promotion:
329
+ already_contains_rule_type: already contains this rule type
321
330
  solidus_friendly_promotions/promotion_code:
322
331
  attributes:
323
332
  base:
@@ -326,3 +335,8 @@ en:
326
335
  attributes:
327
336
  quantity:
328
337
  cannot_be_changed_for_automated_items: cannot be changed on a line item managed by a promotion action
338
+ solidus_friendly_promotions/promotion:
339
+ attributes:
340
+ apply_automatically:
341
+ disallowed_with_path: cannot be set to true when path is present
342
+ disallowed_with_promotion_codes: cannot be set to true when promotion code is present
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusFriendlyPromotions
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end
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.0.0
4
+ version: 1.0.1
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-01-25 00:00:00.000000000 Z
11
+ date: 2024-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -193,6 +193,7 @@ files:
193
193
  - app/decorators/models/solidus_friendly_promotions/shipping_rate_decorator.rb
194
194
  - app/helpers/solidus_friendly_promotions/admin/promotion_actions_helper.rb
195
195
  - app/helpers/solidus_friendly_promotions/admin/promotion_rules_helper.rb
196
+ - app/helpers/solidus_friendly_promotions/admin/promotions_helper.rb
196
197
  - app/javascript/solidus_friendly_promotions.js
197
198
  - app/javascript/solidus_friendly_promotions/controllers/application.js
198
199
  - app/javascript/solidus_friendly_promotions/controllers/calculator_tiers_controller.js
@@ -318,8 +319,6 @@ files:
318
319
  - app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_user_logged_in.html.erb
319
320
  - app/views/solidus_friendly_promotions/admin/promotion_rules/rules/_user_role.html.erb
320
321
  - app/views/solidus_friendly_promotions/admin/promotion_rules/rules/line_item_option_value/_option_value_fields.html.erb
321
- - app/views/solidus_friendly_promotions/admin/promotions/_activations_edit.html.erb
322
- - app/views/solidus_friendly_promotions/admin/promotions/_activations_new.html.erb
323
322
  - app/views/solidus_friendly_promotions/admin/promotions/_form.html.erb
324
323
  - app/views/solidus_friendly_promotions/admin/promotions/_table.html.erb
325
324
  - app/views/solidus_friendly_promotions/admin/promotions/_table_filter.html.erb
@@ -1,22 +0,0 @@
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 %>
@@ -1,43 +0,0 @@
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, SolidusFriendlyPromotions::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>