spree_cm_commissioner 2.14.10 → 2.14.11
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 404c51ec35ca9f40be93a12f9d7c9af99621231ec51b47b4300e34570e0ee2c6
|
|
4
|
+
data.tar.gz: 4cc03fe1be1e9dbae9b4e7eca107e1b882b34fb2d0bb0ff6372c6d55f24935a2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2d8d4d96eeb4e6b3e659cdc3660cb0213fb3da8b39ea09f680b8eb116e028c2205ebabf74cab3fcc6b1146725f25d7035d212b22215522b7b8950bd84b9ab88d
|
|
7
|
+
data.tar.gz: fab1f613701eec7c9ce563bf668781a8356d9cabd088cc3f55cf59a70eb527d8cb29fd6b5658272f871831ba17641a1c0914b63c971f9d0e5dd920311d37649d
|
data/Gemfile.lock
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# A guest only stores what its line item collects (kyc_fields + dynamic fields), whatever a client
|
|
2
|
+
# submits. Clients may send every guest with prefilled values — the app seeds guest #1 with the
|
|
3
|
+
# buyer's contact info even for products that collect nothing — which would make guest #1 read as
|
|
4
|
+
# the buyer while the others stay blank. Unenabled attributes are dropped rather than rejected so a
|
|
5
|
+
# client that over-sends still checks out.
|
|
6
|
+
module SpreeCmCommissioner
|
|
7
|
+
module Checkout
|
|
8
|
+
class StripUncollectedGuestFields
|
|
9
|
+
ALWAYS_ALLOWED = %w[id guest_dynamic_fields_attributes].freeze
|
|
10
|
+
|
|
11
|
+
# Not in KYC_FIELD_ATTRIBUTES; each only means something alongside the field it pairs with.
|
|
12
|
+
PAIRED_ATTRIBUTES = {
|
|
13
|
+
guest_phone_number: %w[country_code],
|
|
14
|
+
guest_id_card: %w[upload_later]
|
|
15
|
+
}.freeze
|
|
16
|
+
|
|
17
|
+
def self.call(order:, params:)
|
|
18
|
+
new.call(order: order, params: params)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def call(order:, params:)
|
|
22
|
+
line_items_params = params[:order]&.[](:line_items_attributes)
|
|
23
|
+
return if line_items_params.blank?
|
|
24
|
+
|
|
25
|
+
each_entry(line_items_params) do |line_item_params|
|
|
26
|
+
guests_params = line_item_params[:guests_attributes]
|
|
27
|
+
next if guests_params.blank?
|
|
28
|
+
|
|
29
|
+
line_item = order.line_items.find { |item| item.id.to_s == line_item_params[:id].to_s }
|
|
30
|
+
next if line_item.nil?
|
|
31
|
+
|
|
32
|
+
allowed = allowed_attributes(line_item)
|
|
33
|
+
each_entry(guests_params) do |guest_params|
|
|
34
|
+
rejected = guest_params.keys.reject { |key| allowed.include?(key.to_s) }
|
|
35
|
+
rejected.each { |key| guest_params.delete(key) }
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def allowed_attributes(line_item)
|
|
43
|
+
kyc_fields = line_item.kyc.nil? ? [] : line_item.kyc_fields
|
|
44
|
+
|
|
45
|
+
ALWAYS_ALLOWED + kyc_fields.flat_map do |field|
|
|
46
|
+
Array(SpreeCmCommissioner::KycBitwise::KYC_FIELD_ATTRIBUTES[field]).map(&:to_s) + PAIRED_ATTRIBUTES.fetch(field, [])
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Nested attributes arrive either as an array or as an index-keyed hash ({ '0' => {...} }).
|
|
51
|
+
def each_entry(collection)
|
|
52
|
+
entries = collection.is_a?(Array) ? collection : collection.values
|
|
53
|
+
entries.each { |entry| yield(entry) if entry.respond_to?(:delete) && entry.respond_to?(:keys) }
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -5,6 +5,7 @@ module SpreeCmCommissioner
|
|
|
5
5
|
# 1. Validate line items are in stock before updating address
|
|
6
6
|
# 2. Skip automatic state transitions (lines 17-18 commented out)
|
|
7
7
|
# State changes are handled by the advance action, not update
|
|
8
|
+
# 3. Drop guest attributes the line item doesn't collect (see StripUncollectedGuestFields)
|
|
8
9
|
def call(order:, params:, permitted_attributes:, request_env:)
|
|
9
10
|
return failure(order) unless order.ensure_line_items_are_in_stock
|
|
10
11
|
|
|
@@ -17,6 +18,8 @@ module SpreeCmCommissioner
|
|
|
17
18
|
# order.state = 'address' if (ship_changed || bill_changed) && order.has_checkout_step?('address')
|
|
18
19
|
# order.state = 'delivery' if selected_shipping_rate_present?(params) && order.has_checkout_step?('delivery')
|
|
19
20
|
|
|
21
|
+
SpreeCmCommissioner::Checkout::StripUncollectedGuestFields.call(order: order, params: params)
|
|
22
|
+
|
|
20
23
|
if order.update_from_params(params, permitted_attributes, request_env)
|
|
21
24
|
# Recalculate pricing models after order/guest updates to ensure adjustments reflect current rules
|
|
22
25
|
SpreeCmCommissioner::PricingModels::Activate.call(order: order)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: spree_cm_commissioner
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.14.
|
|
4
|
+
version: 2.14.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- You
|
|
@@ -2347,6 +2347,7 @@ files:
|
|
|
2347
2347
|
- app/services/spree_cm_commissioner/checkout/advance_to_payment.rb
|
|
2348
2348
|
- app/services/spree_cm_commissioner/checkout/complete_decorator.rb
|
|
2349
2349
|
- app/services/spree_cm_commissioner/checkout/remove_store_credit_decorator.rb
|
|
2350
|
+
- app/services/spree_cm_commissioner/checkout/strip_uncollected_guest_fields.rb
|
|
2350
2351
|
- app/services/spree_cm_commissioner/checkout/update_decorator.rb
|
|
2351
2352
|
- app/services/spree_cm_commissioner/completion_steps/mark_line_item_as_completed.rb
|
|
2352
2353
|
- app/services/spree_cm_commissioner/completion_steps/regenerate_for_line_items.rb
|