solidus_promotions 4.6.2 → 4.6.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44e6ef32330806227c8239658e08e9f599d444c1f96a15443288b32b7fee8379
4
- data.tar.gz: aebf74184b3cf794eabf351af8644bf6a265ba4025e26ceed606e8a8282d4e34
3
+ metadata.gz: 6f0d673a8fd62d82e0efd7cf970a65d91e580c234933414e8a21e9f7d4e94851
4
+ data.tar.gz: fafb075b7983e18e6b026a06f17873d835e8218d79a3304d988d010d846208bb
5
5
  SHA512:
6
- metadata.gz: 28202f4a0e0742bbd7d8e630a236fa1727b63f6ba09c62002387583badfe485705166c9357c1122404863165298a29366b2ed94d52ec71ad37d8739ea20855ac
7
- data.tar.gz: fd89c707aa64689661b424b9726c3624a5f4f30b9fe589255081a87081ac6756ac176472c8c4d1536a5a44775c9b94e4a83e4b71a5f6527f61b583c970c47e8d
6
+ metadata.gz: 245250786e0a04e6137ffbedd7f21b36447b19974c0f636ca1f6d19ce13763505adb5c802f456c0db4fbfaa1cb60a8fc84722e668c32a8c0bec579370cadd245
7
+ data.tar.gz: e22b24de21453c50f17eb794a530da1bb361883f6597a86c5fdfcc78f9ea3530522f267a7c62f8493316b91231f5f82438d729b1285d3f8c50b576eeb4164eb4
@@ -6,8 +6,6 @@ export default class extends Controller {
6
6
  connect() {
7
7
  this.wrapperClass =
8
8
  this.data.get("wrapperClass") || "promo-condition-option-value";
9
-
10
- this.element.querySelectorAll("." + this.wrapperClass).forEach((element) => this.buildSelects(element))
11
9
  }
12
10
 
13
11
  add_row(event) {
@@ -15,7 +13,6 @@ export default class extends Controller {
15
13
 
16
14
  var content = this.templateTarget.innerHTML;
17
15
  this.linksTarget.insertAdjacentHTML("beforebegin", content);
18
- this.buildSelects(this.linksTarget.previousElementSibling)
19
16
  }
20
17
 
21
18
  propagate_product_id_to_value_input(event) {
@@ -24,7 +21,9 @@ export default class extends Controller {
24
21
  // we first need to greedily match all other square brackets
25
22
  const regEx = /(\[.*\])\[.*?\]$/;
26
23
  let wrapper = event.target.closest("." + this.wrapperClass);
27
- let optionValuesInput = wrapper.querySelector(".option-values-select[type='hidden']");
24
+ let optionValuesInput = wrapper.querySelector("[is=option-value-picker]");
25
+ optionValuesInput.dataset.productId = event.target.value;
26
+ optionValuesInput.value = "";
28
27
  optionValuesInput.name = optionValuesInput.name.replace(
29
28
  regEx,
30
29
  `$1[${event.target.value}]`
@@ -37,26 +36,4 @@ export default class extends Controller {
37
36
  let wrapper = event.target.closest("." + this.wrapperClass);
38
37
  wrapper.remove();
39
38
  }
40
-
41
- // helper functions
42
-
43
- buildSelects(wrapper) {
44
- let productSelect = wrapper.querySelector(".product-select")
45
- let optionValueSelect = wrapper.querySelector(".option-values-select[type='hidden']")
46
- this.buildProductSelect(productSelect)
47
- $(optionValueSelect).optionValueAutocomplete({ productSelect });
48
- }
49
-
50
- buildProductSelect(productSelect) {
51
- var jQueryProductSelect = $(productSelect)
52
- jQueryProductSelect.productAutocomplete({
53
- multiple: false,
54
- })
55
- // capture the jQuery "change" event and re-emit it as DOM event "select2Change"
56
- // so that Stimulus can capture it
57
- jQueryProductSelect.on('change', function () {
58
- let event = new Event('select2Change', { bubbles: true }) // fire a native event
59
- productSelect.dispatchEvent(event);
60
- });
61
- }
62
39
  }
@@ -1,11 +1,9 @@
1
1
  $.fn.optionValueAutocomplete = function (options) {
2
- 'use strict';
2
+ "use strict";
3
3
 
4
4
  // Default options
5
- options = options || {}
6
- var multiple = typeof(options['multiple']) !== 'undefined' ? options['multiple'] : true;
7
- var productSelect = options['productSelect'];
8
-
5
+ options = options || {};
6
+ var multiple = typeof options["multiple"] !== "undefined" ? options["multiple"] : true;
9
7
  function formatOptionValue(option_value) {
10
8
  return Select2.util.escapeMarkup(option_value.name);
11
9
  }
@@ -14,39 +12,58 @@ $.fn.optionValueAutocomplete = function (options) {
14
12
  minimumInputLength: 3,
15
13
  multiple: multiple,
16
14
  initSelection: function (element, callback) {
17
- $.get(Spree.pathFor('api/option_values'), {
18
- ids: element.val().split(','),
19
- token: Spree.api_key
20
- }, function (data) {
21
- callback(multiple ? data : data[0]);
22
- });
15
+ $.get(
16
+ Spree.pathFor("api/option_values"),
17
+ {
18
+ ids: element.val().split(","),
19
+ token: Spree.api_key,
20
+ },
21
+ function (data) {
22
+ callback(multiple ? data : data[0]);
23
+ }
24
+ );
23
25
  },
24
26
  ajax: {
25
- url: Spree.pathFor('api/option_values'),
26
- datatype: 'json',
27
+ url: Spree.pathFor("api/option_values"),
28
+ datatype: "json",
27
29
  data: function (term, page) {
28
- var productId = typeof(productSelect) !== 'undefined' ? $(productSelect).select2('val') : null;
30
+ var productId = this[0].dataset.productId;
29
31
  return {
30
32
  q: {
31
33
  name_cont: term,
32
- variants_product_id_eq: productId
34
+ variants_product_id_eq: productId,
33
35
  },
34
- token: Spree.api_key
36
+ token: Spree.api_key,
35
37
  };
36
38
  },
37
39
  results: function (data, page) {
38
40
  return { results: data };
39
- }
41
+ },
40
42
  },
41
43
  formatResult: formatOptionValue,
42
- formatSelection: formatOptionValue
44
+ formatSelection: formatOptionValue,
43
45
  });
44
46
  };
45
47
 
46
48
  class OptionValuePicker extends HTMLInputElement {
47
49
  connectedCallback() {
48
50
  $(this).optionValueAutocomplete();
51
+
52
+ this.observer = new MutationObserver((muts) => {
53
+ for (const m of muts) {
54
+ if (m.attributeName.startsWith("data-product-id")) {
55
+ this.restart();
56
+ }
57
+ }
58
+ });
59
+
60
+ this.observer.observe(this, { attributes: true });
61
+ }
62
+
63
+ restart() {
64
+ $(this).select2("destroy");
65
+ $(this).optionValueAutocomplete();
49
66
  }
50
67
  }
51
68
 
52
- customElements.define('option-value-picker', OptionValuePicker, { extends: 'input' });
69
+ customElements.define("option-value-picker", OptionValuePicker, { extends: "input" });
@@ -1,6 +1,11 @@
1
1
  class ProductPicker extends HTMLInputElement {
2
2
  connectedCallback() {
3
- $(this).productAutocomplete();
3
+ const multiple = this.dataset.multiple !== "false";
4
+ $(this).productAutocomplete({ multiple });
5
+ $(this).on("change", (_) => {
6
+ let event = new Event('select2Change', { bubbles: true }) // fire a native event
7
+ this.dispatchEvent(event)
8
+ })
4
9
  }
5
10
  }
6
11
 
@@ -195,6 +195,7 @@ en:
195
195
  solidus_promotions/benefits/adjust_line_item_quantity_groups: Discount matching line items based on quantity groups
196
196
  solidus_promotions/calculators/distributed_amount: Distributed Amount
197
197
  solidus_promotions/calculators/percent: Percent
198
+ solidus_promotions/calculators/percent_with_cap: Distributed Percent with cap
198
199
  solidus_promotions/calculators/flat_rate: Flat Rate
199
200
  solidus_promotions/calculators/flexi_rate: Flexible Rate
200
201
  solidus_promotions/calculators/tiered_flat_rate: Tiered Flat Rate
@@ -70,6 +70,7 @@ module SolidusPromotions
70
70
  "SolidusPromotions::Calculators::FlatRate",
71
71
  "SolidusPromotions::Calculators::FlexiRate",
72
72
  "SolidusPromotions::Calculators::Percent",
73
+ "SolidusPromotions::Calculators::PercentWithCap",
73
74
  "SolidusPromotions::Calculators::TieredFlatRate",
74
75
  "SolidusPromotions::Calculators::TieredPercent",
75
76
  "SolidusPromotions::Calculators::TieredPercentOnEligibleItemQuantity"
@@ -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: calculator.class.human_attribute_name("preferred_#{name}", default: I18n.t(name, scope: :spree, default: name.humanize)) %>
5
+ label: calculator.class.human_attribute_name("preferred_#{name}", default: I18n.t(name, scope: :spree, default: name.to_s.humanize)) %>
6
6
  <% end %>
@@ -5,19 +5,20 @@
5
5
  <div class="field promo-condition-option-values">
6
6
  <div class="param-prefix hidden" data-param-prefix="<%= param_prefix %>"></div>
7
7
  <div class="row">
8
- <div class="col-6"><%= label_tag nil, Spree::Product.model_name.human %></div>
8
+ <div class="col-5"><%= label_tag nil, Spree::Product.model_name.human %></div>
9
9
  <div class="col-6"><%= label_tag nil, plural_resource_name(Spree::OptionValue) %></div>
10
+ <div class="col-1">&nbsp;</div>
10
11
  </div>
11
12
 
12
13
  <div class="form-group">
13
14
  <div data-controller="product-option-values">
14
15
  <template data-product-option-values-target="template">
15
- <%= render "solidus_promotions/admin/condition_fields/line_item_option_value/option_value_fields", product_option_values: [nil, []], form: form %>
16
+ <%= render "solidus_promotions/admin/condition_fields/line_item_option_value/option_value_fields", product_option_values: [nil, []], form: form, index: 0 %>
16
17
  </template>
17
- <% form.object.preferred_eligible_values.each do |product_option_values| %>
18
- <%= render "solidus_promotions/admin/condition_fields/line_item_option_value/option_value_fields", product_option_values: product_option_values, form: form %>
18
+ <% form.object.preferred_eligible_values.each.with_index do |product_option_values, index| %>
19
+ <%= render "solidus_promotions/admin/condition_fields/line_item_option_value/option_value_fields", product_option_values:, form:, index: %>
19
20
  <% end %>
20
- <div class="mb-3" data-product-option-values-target="links">
21
+ <div class="mt-3" data-product-option-values-target="links">
21
22
  <%= link_to t(:add_product, scope: [:solidus_promotions, :line_item_option_value_condition]), "#", class: "btn btn-outline-primary", data: { action: "click->product-option-values#add_row" } %>
22
23
  </div>
23
24
  </div>
@@ -7,19 +7,20 @@
7
7
  <div class="field promo-condition-option-values">
8
8
  <div class="param-prefix hidden" data-param-prefix="<%= param_prefix %>"></div>
9
9
  <div class="row">
10
- <div class="col-6"><%= label_tag nil, Spree::Product.model_name.human %></div>
10
+ <div class="col-5"><%= label_tag nil, Spree::Product.model_name.human %></div>
11
11
  <div class="col-6"><%= label_tag nil, plural_resource_name(Spree::OptionValue) %></div>
12
+ <div class="col-1">&nbsp;</div>
12
13
  </div>
13
14
 
14
15
  <div class="form-group">
15
16
  <div data-controller="product-option-values">
16
17
  <template data-product-option-values-target="template">
17
- <%= render "solidus_promotions/admin/condition_fields/line_item_option_value/option_value_fields", product_option_values: [nil, []], form: form %>
18
+ <%= render "solidus_promotions/admin/condition_fields/line_item_option_value/option_value_fields", product_option_values: [nil, []], form:, index: 0 %>
18
19
  </template>
19
- <% form.object.preferred_eligible_values.each do |product_option_values| %>
20
- <%= render "solidus_promotions/admin/condition_fields/line_item_option_value/option_value_fields", product_option_values: product_option_values, form: form %>
20
+ <% form.object.preferred_eligible_values.each.with_index do |product_option_values, index| %>
21
+ <%= render "solidus_promotions/admin/condition_fields/line_item_option_value/option_value_fields", product_option_values:, form:, index: %>
21
22
  <% end %>
22
- <div class="mb-3" data-product-option-values-target="links">
23
+ <div class="mt-3" data-product-option-values-target="links">
23
24
  <%= link_to t(:add_product, scope: [:solidus_promotions, :option_value_condition]), "#", class: "btn btn-outline-primary", data: { action: "click->product-option-values#add_row" } %>
24
25
  </div>
25
26
  </div>
@@ -1,21 +1,27 @@
1
- <div class="fullwidth promo-condition-option-value d-flex align-content-stretch mb-3">
2
- <div class="mr-2" style="flex-grow: 1;">
1
+ <div class="promo-condition-option-value row">
2
+ <div class="col-5">
3
3
  <input
4
4
  is="product-picker"
5
+ id="ov-product-picker-<%= index %>"
5
6
  class="w-100"
6
7
  data-action="select2Change->product-option-values#propagate_product_id_to_value_input"
8
+ data-multiple="false"
7
9
  type="hidden"
8
10
  value="<%= product_option_values[0] %>"
9
11
  >
10
12
  </div>
11
- <div class="mr-2 ml-2" style="flex-grow: 1;">
13
+ <div class="col-6">
12
14
  <input
13
15
  is="option-value-picker"
16
+ id="option-value-picker-<%= index %>"
14
17
  class="fullwidth"
15
18
  name="<%= form.object_name %>[preferred_eligible_values][<%= product_option_values[0] %>]"
16
19
  type="hidden"
20
+ data-product-id="<%= product_option_values[0] %>"
17
21
  value="<%= product_option_values[1].join(",") %>"
18
22
  >
19
23
  </div>
20
- <a class="fa fa-trash remove p-2" data-action="click->product-option-values#remove_row"></a>
24
+ <div class="col-1">
25
+ <a class="fa fa-trash remove p-2 float-right" data-action="click->product-option-values#remove_row"></a>
26
+ </div>
21
27
  </div>
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.6.2
4
+ version: 4.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Meyerhoff
@@ -384,7 +384,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
384
384
  - !ruby/object:Gem::Version
385
385
  version: '0'
386
386
  requirements: []
387
- rubygems_version: 3.7.2
387
+ rubygems_version: 4.0.10
388
388
  specification_version: 4
389
389
  summary: New promotion system for Solidus
390
390
  test_files: []