spree_api 6.0.5 → 6.0.6

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/spree/api/v3/error_handler.rb +4 -0
  3. data/app/controllers/spree/api/v3/admin/gift_cards_controller.rb +6 -0
  4. data/app/controllers/spree/api/v3/admin/order_groups_controller.rb +1 -1
  5. data/app/controllers/spree/api/v3/admin/orders/payments_controller.rb +10 -6
  6. data/app/controllers/spree/api/v3/store/products/filters_controller.rb +1 -0
  7. data/app/controllers/spree/api/v3/webhooks/payments_controller.rb +36 -6
  8. data/app/serializers/spree/api/v3/admin/admin_user_serializer.rb +4 -2
  9. data/app/serializers/spree/api/v3/admin/commission_rule_serializer.rb +3 -3
  10. data/app/serializers/spree/api/v3/admin/consent_record_serializer.rb +1 -1
  11. data/app/serializers/spree/api/v3/admin/import_serializer.rb +4 -1
  12. data/app/serializers/spree/api/v3/admin/order_serializer.rb +11 -0
  13. data/app/serializers/spree/api/v3/admin/payment_capture_event_serializer.rb +5 -1
  14. data/app/serializers/spree/api/v3/admin/payment_serializer.rb +5 -2
  15. data/app/serializers/spree/api/v3/admin/promotion_action_serializer.rb +3 -1
  16. data/app/serializers/spree/api/v3/admin/promotion_rule_serializer.rb +4 -4
  17. data/app/serializers/spree/api/v3/admin/refund_serializer.rb +5 -2
  18. data/app/serializers/spree/api/v3/cart_serializer.rb +16 -3
  19. data/app/serializers/spree/api/v3/company_serializer.rb +2 -2
  20. data/app/serializers/spree/api/v3/credit_card_serializer.rb +5 -1
  21. data/app/serializers/spree/api/v3/fulfillment_serializer.rb +4 -1
  22. data/app/serializers/spree/api/v3/payment_serializer.rb +3 -1
  23. data/app/serializers/spree/api/v3/product_filters_serializer.rb +1 -1
  24. data/app/serializers/spree/api/v3/product_serializer.rb +9 -1
  25. data/app/serializers/spree/api/v3/seller/import_serializer.rb +4 -1
  26. data/app/serializers/spree/api/v3/variant_serializer.rb +3 -1
  27. data/app/services/spree/api/v3/filter_table.rb +11 -26
  28. data/app/services/spree/api/v3/filters_aggregator.rb +13 -18
  29. data/config/locales/en.yml +1 -0
  30. data/lib/spree/api/enum_types.rb +7 -4
  31. data/lib/spree/api/openapi/schema_helper.rb +15 -234
  32. data/lib/spree/api/sdk_types.rb +5 -5
  33. data/openapi/admin.yaml +149 -151
  34. data/openapi/store.yaml +84 -144
  35. metadata +8 -9
  36. data/lib/spree/api/testing_support/always_register_type_hints.rb +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f34f6665b12790e158bff2ef546d9d5b055e1c8e86c2e2331868dbcecda9285f
4
- data.tar.gz: 64ca7895cf3891dbaf1c0ec665408a42eec99aa197b7788c13f7ce45be151611
3
+ metadata.gz: 4c9c668a0a2a022baab4a46225033a2db830c03710a05610630d994ab1ee769d
4
+ data.tar.gz: 2e094bd51c9c1b004e2f268b43255299c75e146198084d232b738023c4825c2c
5
5
  SHA512:
6
- metadata.gz: 95a763713fde3a71aa0f01e23761d6dd63a6662f50ca58a21e4c63a5492cb1938c206783d837ad5292fcd008bf4267beba2df7345a1c177d36a97781bb80f936
7
- data.tar.gz: dea78274d81838b3bce43dbb0db6cf67b393819b1e9ac4ed790d184b95c3f7870c3c83e8f701dac85c9a5ca3ecab46a892b70a8e5869c24a589c77f355d1a07b
6
+ metadata.gz: e08693f225926e85bee796f333f2cdeae0a44a714fafc6761f3666da01efea4c9193cfad5ba5fd3e50d82c6ba8ac24a1196858565f4da26a7cc665cc43a719e2
7
+ data.tar.gz: 609aaee1a7a16894f7a6c4a5d328eb3dc7279d730fd6b1932ffdf4e080e27b97af4e07520efffbe8a8ed36d20ecdc2d0baf370b54ab08bd9176c40419892dbac
@@ -128,6 +128,8 @@ module Spree
128
128
 
129
129
  # Main error rendering method with Stripe-style structure
130
130
  def render_error(code:, message:, status:, details: nil)
131
+ message = I18n.t('spree.api.errors.request_failed') if message.blank?
132
+
131
133
  error_response = {
132
134
  error: {
133
135
  code: code,
@@ -171,6 +173,8 @@ module Spree
171
173
 
172
174
  # Convenience method for service result errors
173
175
  def render_service_error(error, code: ERROR_CODES[:processing_error], status: :unprocessable_content)
176
+ error = error.value if error.is_a?(Spree::ServiceModule::ResultError) && error.value.is_a?(Symbol)
177
+
174
178
  if error.is_a?(ActiveModel::Errors)
175
179
  render_validation_error(error, code: code)
176
180
  elsif error.is_a?(String)
@@ -33,6 +33,12 @@ module Spree
33
33
 
34
34
  before_action :resolve_customer, only: [:create, :update]
35
35
 
36
+ # Locked so a checkout drawing the card down cannot commit between
37
+ # the model's used-card check and this write.
38
+ def update
39
+ @resource.with_lock { super }
40
+ end
41
+
36
42
  protected
37
43
 
38
44
  def model_class
@@ -32,7 +32,7 @@ module Spree
32
32
  def collection_includes
33
33
  [
34
34
  :customer, :ship_address, :bill_address,
35
- { payments: %i[payment_method source capture_events] },
35
+ { payments: %i[payment_method source capture_events refunds] },
36
36
  { orders: %i[market gift_card] }
37
37
  ]
38
38
  end
@@ -8,14 +8,18 @@ module Spree
8
8
 
9
9
  request_params :payment do |body|
10
10
  body.attribute :payment_method_id, :id, required: true, on: :create
11
- body.attribute :amount, :decimal, description: "Defaults to the order total left after store credit."
11
+ body.attribute :amount, :decimal,
12
+ description: 'Defaults to what the order still owes after the payments already recorded on it ' \
13
+ '(failed, invalid and void payments are not counted).'
12
14
  body.attribute :source_id, :id,
13
15
  description: "A saved payment source of the order's customer (a credit card), for an off-session charge. Used only by payment methods that require a source."
14
16
  end
15
17
 
16
18
  request_params 'PaymentCaptureParams', action: :capture do |body|
17
19
  body.attribute :amount, :decimal,
18
- description: 'Captures part of the authorized amount. Defaults to all of it.'
20
+ description: 'Captures part of the authorized amount. Defaults to all of it, ' \
21
+ 'or to what the order still owes when that is less. A capture another ' \
22
+ 'payment is waiting on its provider to confirm counts as paid.'
19
23
  end
20
24
 
21
25
  before_action :set_resource, only: [:show, :capture, :void]
@@ -28,10 +32,10 @@ module Spree
28
32
  def create
29
33
  with_order_lock do
30
34
  payment_method = current_store.payment_methods.accessible_by(current_ability, :show).find_by_prefix_id!(params[:payment_method_id])
31
- # The default is what the order still owes, which is nothing
32
- # once store credit covers it — a zero payment is refused the
33
- # same way a zero amount is.
34
- amount = money_param(:amount, @parent.currency) || @parent.order_total_after_store_credit
35
+ # The default is what the order still owes beside the payments
36
+ # already recorded, which is nothing once they cover it — a zero
37
+ # payment is refused the same way a zero amount is.
38
+ amount = money_param(:amount, @parent.currency) || @parent.amount_left_to_pay
35
39
  raise Spree::Money::InvalidFormat.new('must be greater than 0', field: :amount) unless amount.positive?
36
40
 
37
41
  @resource = @parent.payments.build(amount: amount, payment_method: payment_method)
@@ -42,6 +42,7 @@ module Spree
42
42
  current_currency,
43
43
  current_locale,
44
44
  (hide_prices? ? 'prices_hidden' : nil),
45
+ (current_store.preferred_show_products_without_price ? 'unpriced_shown' : nil),
45
46
  buyer_catalog_fragment,
46
47
  category&.cache_key_with_version,
47
48
  collection&.cache_key_with_version,
@@ -37,12 +37,10 @@ module Spree
37
37
  return head :ok if result.nil?
38
38
 
39
39
  # Process asynchronously — gateways have timeout limits and will
40
- # retry on timeouts, so we must return 200 quickly.
41
- Spree::Payments::HandleWebhookJob.set(wait: 30.seconds).perform_later(
42
- payment_method_id: payment_method.id,
43
- action: result[:action].to_s,
44
- payment_session_id: result[:payment_session].id
45
- )
40
+ # retry on timeouts, so we must return 200 quickly. A delivery that
41
+ # could not be queued is refused, so the provider sends it again;
42
+ # perform_later answers false rather than the job when it was not.
43
+ return head :service_unavailable unless enqueue(payment_method, result)
46
44
 
47
45
  head :ok
48
46
  rescue Spree::PaymentMethod::WebhookSignatureError
@@ -53,6 +51,38 @@ module Spree
53
51
  Rails.error.report(e, source: 'spree.webhooks.payments')
54
52
  head :ok
55
53
  end
54
+
55
+ private
56
+
57
+ # The outcome of a capture, void or refund the provider accepted
58
+ # earlier names its record by reference (PaymentMethod#parse_webhook_event).
59
+ def enqueue(payment_method, result)
60
+ if result.key?(:reference)
61
+ enqueue_modification(payment_method, result)
62
+ else
63
+ Spree::Payments::HandleWebhookJob.set(wait: 30.seconds).perform_later(
64
+ payment_method_id: payment_method.id,
65
+ action: result[:action].to_s,
66
+ payment_session_id: result[:payment_session].id,
67
+ metadata: result[:metadata] || {}
68
+ )
69
+ end
70
+ # Any adapter error, not only Active Job's own, means nothing was queued.
71
+ rescue StandardError => e
72
+ Rails.error.report(e, handled: true, source: 'spree.webhooks.payments')
73
+ nil
74
+ end
75
+
76
+ def enqueue_modification(payment_method, result)
77
+ Spree::Payments::HandleModificationWebhookJob.perform_later(
78
+ payment_method_id: payment_method.id,
79
+ action: result[:action].to_s,
80
+ reference: result[:reference].to_s,
81
+ payment_id: result[:payment]&.id,
82
+ metadata: result[:metadata] || {},
83
+ received_at: Time.current.iso8601
84
+ )
85
+ end
56
86
  end
57
87
  end
58
88
  end
@@ -43,7 +43,8 @@ module Spree
43
43
  # we fall back to `Spree::Current.store` if not.
44
44
  # Filtered in Ruby rather than with `for_resource`, so the staff
45
45
  # index's preloaded roles are used instead of a query per user.
46
- typelize({ id: :string, name: :string }, multi: true)
46
+ typelize({ id: [:string, comment: 'Role ID'], name: [:string, comment: 'Role name, e.g. admin'] },
47
+ multi: true, comment: 'Role assignments on the current store')
47
48
  attribute :roles do |user, params|
48
49
  store = params&.dig(:store) || Spree::Current.store
49
50
  roles = user.spree_roles.to_a
@@ -56,7 +57,8 @@ module Spree
56
57
  # store switcher can offer all accessible stores. Read off the same
57
58
  # preloaded roles, and deduped/sorted in Ruby, so the staff index
58
59
  # spends no extra query per user.
59
- typelize({ id: :string, name: :string, code: :string }, multi: true)
60
+ typelize({ id: [:string, comment: 'Store ID'], name: [:string, comment: 'Store name'], code: [:string, comment: 'Store code'] },
61
+ multi: true, comment: 'Stores the staff member can access through a role assignment')
60
62
  attribute :stores do |user|
61
63
  stores = user.spree_roles.filter_map { |role| role.resource if role.resource.is_a?(Spree::Store) }
62
64
 
@@ -13,9 +13,9 @@ module Spree
13
13
  typelize type: [:string, comment: 'Rule type. Built-in: seller_rule, category_rule, product_rule, item_total_rule. Extensions may register more.'],
14
14
  commission_rate_id: :string,
15
15
  preferences: 'Record<string, unknown>',
16
- product_ids: 'Array<string> | null',
17
- seller_ids: 'Array<string> | null',
18
- category_ids: 'Array<string> | null'
16
+ product_ids: [:string, multi: true, nullable: true],
17
+ seller_ids: [:string, multi: true, nullable: true],
18
+ category_ids: [:string, multi: true, nullable: true]
19
19
 
20
20
  attributes created_at: :iso8601, updated_at: :iso8601
21
21
 
@@ -9,7 +9,7 @@ module Spree
9
9
  email: [:string, nullable: true],
10
10
  ip_address: [:string, nullable: true],
11
11
  recorded_at: [:string, nullable: true],
12
- documents: 'Array<Record<string, unknown>>'
12
+ documents: ['Record<string, unknown>', multi: true]
13
13
 
14
14
  attributes :purpose, :source, :accepted, :email, :ip_address,
15
15
  created_at: :iso8601
@@ -57,7 +57,10 @@ module Spree
57
57
  import.rows_status_counts['failed'] || 0
58
58
  end
59
59
 
60
- typelize({ name: :string, label: :string, required: :boolean }, multi: true)
60
+ typelize({ name: [:string, comment: 'Canonical field name used in mappings, e.g. slug'],
61
+ label: [:string, comment: 'Human-readable label'],
62
+ required: [:boolean, comment: 'Whether the field must be mapped before processing'] },
63
+ multi: true, comment: 'Canonical columns of this import type, including per-store custom field columns')
61
64
  attribute :schema_fields do |import|
62
65
  import.schema_fields.map do |field|
63
66
  { name: field[:name], label: field[:label], required: field[:required].present? }
@@ -60,6 +60,17 @@ module Spree
60
60
  money_attributes :payment_total
61
61
  typelize payment_total: [:string, nullable: false]
62
62
 
63
+ # What a new payment should be for: the amount due less the payments
64
+ # recorded and not yet captured. The server owns the rule, so a client
65
+ # does not repeat which payment statuses count.
66
+ money_attributes :amount_left_to_pay
67
+ typelize amount_left_to_pay: [
68
+ :string,
69
+ { nullable: false,
70
+ comment: 'What a new payment should be for, the amount due less the payments recorded and not yet ' \
71
+ "captured. Failed, invalid and void payments don't count. Never negative." }
72
+ ]
73
+
63
74
  # Back-office only: what the marketplace earned on this sale — the fee,
64
75
  # the tax charged on it, and the two together. Never on the store
65
76
  # serializer: a commission settles between the platform and the
@@ -5,7 +5,11 @@ module Spree
5
5
  # Serializes Spree::PaymentCaptureEvent — one capture of money a
6
6
  # payment had authorized. A payment captured in parts has one per part.
7
7
  class PaymentCaptureEventSerializer < V3::BaseSerializer
8
- attributes created_at: :iso8601, updated_at: :iso8601
8
+ typelize status: [:string, enum: Spree::PaymentCaptureEvent.statuses, enum_type_name: 'PaymentCaptureEventStatus',
9
+ comment: '`requested` until the payment provider answers a capture it accepted.'],
10
+ transaction_id: [:string, nullable: true, comment: "The payment provider's reference for this capture, when it gave one."]
11
+
12
+ attributes :status, :transaction_id, created_at: :iso8601, updated_at: :iso8601
9
13
 
10
14
  money_attributes :amount
11
15
  typelize amount: [:string, nullable: false]
@@ -18,10 +18,13 @@ module Spree
18
18
  avs_risky: [:boolean, comment: 'Whether the card issuer reported that the billing address did not match.'],
19
19
  cvv_risky: [:boolean, comment: 'Whether the card issuer reported that the security code did not match.'],
20
20
  can_void: [:boolean, comment: 'Whether the payment can be voided now, as decided by its payment method.'],
21
- can_capture: [:boolean, comment: 'Whether the payment can be captured now, as decided by its payment method.']
21
+ can_capture: [:boolean, comment: 'Whether the payment can be captured now, as decided by its payment method.'],
22
+ requested_action: [:string, nullable: true,
23
+ comment: 'What the payment provider is still answering for a `requested` payment: ' \
24
+ '`capture` or `void`. Null otherwise.']
22
25
 
23
26
  attributes :metadata, :avs_response, :cvv_response_code, :cvv_response_message,
24
- :gateway_dashboard_payment_url,
27
+ :gateway_dashboard_payment_url, :requested_action,
25
28
  created_at: :iso8601, updated_at: :iso8601
26
29
 
27
30
  attribute(:avs_risky, &:is_avs_risky?)
@@ -43,7 +43,9 @@ module Spree
43
43
  # Line items the action will add for CreateLineItems. variant_id
44
44
  # is prefixed for consistency with the rest of the API. Null on
45
45
  # actions that don't have the association.
46
- typelize({ variant_id: :string, quantity: :number }, multi: true, nullable: true)
46
+ typelize({ variant_id: :string, quantity: :number },
47
+ multi: true, nullable: true,
48
+ comment: 'Rows of a `create_line_items` action: the variant added to the order and how many')
47
49
  attribute :line_items do |action|
48
50
  next nil unless action.respond_to?(:promotion_action_line_items)
49
51
 
@@ -11,10 +11,10 @@ module Spree
11
11
  typelize type: [:string, comment: 'Rule type. Built-in: currency, country, channel, market, item_total, product, customer, customer_group, first_order, customer_logged_in, one_use_per_user, category, option_value. Extensions may register more.'],
12
12
  promotion_id: :string,
13
13
  preferences: 'Record<string, unknown>',
14
- product_ids: 'Array<string> | null',
15
- category_ids: 'Array<string> | null',
16
- customer_ids: 'Array<string> | null',
17
- option_value_ids: 'Array<string> | null'
14
+ product_ids: [:string, multi: true, nullable: true],
15
+ category_ids: [:string, multi: true, nullable: true],
16
+ customer_ids: [:string, multi: true, nullable: true],
17
+ option_value_ids: [:string, multi: true, nullable: true]
18
18
 
19
19
  attributes created_at: :iso8601, updated_at: :iso8601
20
20
 
@@ -10,9 +10,12 @@ module Spree
10
10
  refund_reason_id: [:string, nullable: true],
11
11
  refunder_id: [:string, nullable: true],
12
12
  refunder_type: [:string, nullable: true, enum: Spree::Actor::BUILT_IN_KINDS, enum_type_name: 'ActorKind'],
13
- metadata: 'Record<string, unknown>'
13
+ metadata: 'Record<string, unknown>',
14
+ status: [:string, enum: Spree::Refund.statuses, enum_type_name: 'RefundStatus',
15
+ comment: '`requested` until the payment provider answers a refund it accepted.'],
16
+ failure_reason: [:string, nullable: true, comment: "The payment provider's reason, when the refund failed."]
14
17
 
15
- attributes :metadata,
18
+ attributes :metadata, :status, :failure_reason,
16
19
  created_at: :iso8601, updated_at: :iso8601
17
20
 
18
21
  # The tax inside the amount, when what was refunded carried tax.
@@ -15,9 +15,7 @@ module Spree
15
15
  po_document_byte_size: ['number | null'], order_minimum: [:string, nullable: true],
16
16
  order_minimum_shortfall: [:string, nullable: true], below_order_minimum: ['boolean | null'],
17
17
  freight_summary: [:FreightSummary, nullable: true],
18
- requirements: 'Array<{step: string, field: string, code: string, message: string}>',
19
18
  shipping_eq_billing_address: :boolean,
20
- warnings: 'Array<{code: string, message: string, line_item_id?: string, variant_id?: string, item_index?: number}>',
21
19
  billing_address: { nullable: true }, shipping_address: { nullable: true },
22
20
  gift_card: { nullable: true }, market: { nullable: true }
23
21
 
@@ -55,7 +53,17 @@ module Spree
55
53
  # @deprecated `number` mirrors `id` (carts have no order-style
56
54
  # number) — kept until 6.5 for 5.x clients.
57
55
  attributes :number, :token, :email, :customer_note, :po_number,
58
- :currency, :locale, :total_quantity, :warnings, :coupon_code
56
+ :currency, :locale, :total_quantity
57
+
58
+ typelize({ code: [:string, comment: 'Machine-readable warning code, e.g. line_item_removed'],
59
+ message: [:string, comment: 'Human-readable warning message'],
60
+ line_item_id?: [:string, comment: 'Line item the warning is about, when there is one'],
61
+ variant_id?: [:string, comment: 'Variant the warning is about, when there is one'],
62
+ item_index?: [:number, comment: 'Position in the submitted items, for a warning raised while applying a batch of item changes'] },
63
+ multi: true, comment: 'Problems found with the cart, such as an item removed after a stock change')
64
+ attribute(:warnings, &:warnings)
65
+
66
+ attributes :coupon_code
59
67
 
60
68
  # Nulled for gated (prices_hidden) guests so the cart can't leak the
61
69
  # prices that product/variant serializers already withhold.
@@ -74,6 +82,11 @@ module Spree
74
82
  # The order-minimum requirement names both amounts in its message, so
75
83
  # it is dropped rather than redacted for a gated guest: a requirement
76
84
  # with its numbers stripped tells them nothing they can act on.
85
+ typelize({ step: [:string, comment: 'Checkout step this requirement belongs to, e.g. payment'],
86
+ field: [:string, comment: 'Field that needs to be satisfied'],
87
+ code: [:string, comment: 'Machine-readable requirement code, e.g. order_minimum_not_met'],
88
+ message: [:string, comment: 'Human-readable requirement message'] },
89
+ multi: true, comment: 'What is still missing before the cart can be completed')
77
90
  attribute :requirements do |order|
78
91
  # 5.6 storefronts matched the delivery requirement by its field, so
79
92
  # it keeps the old name until 6.5; `code` already carries the new one.
@@ -8,8 +8,7 @@ module Spree
8
8
  class CompanySerializer < BaseSerializer
9
9
  typelize name: :string,
10
10
  kind: [:string, enum: Spree::Company::KINDS, enum_type_name: 'CompanyKind'], parent_id: [:string, nullable: true],
11
- po_number_required: :boolean,
12
- ancestors: 'Array<{id: string, name: string, kind: string}>'
11
+ po_number_required: :boolean
13
12
 
14
13
  # `po_number_required` is buyer-facing by design: the checkout marks
15
14
  # the PO field required from it.
@@ -20,6 +19,7 @@ module Spree
20
19
  # The path above this node, root first — lets a client render
21
20
  # "Acme / EMEA / Berlin" without a request per level. Bounded by the
22
21
  # tree's depth cap.
22
+ typelize({ id: :string, name: :string, kind: :string }, multi: true)
23
23
  attribute :ancestors do |company|
24
24
  company.ancestors.reverse.map do |node|
25
25
  { 'id' => node.prefixed_id, 'name' => node.name, 'kind' => node.kind }
@@ -4,10 +4,14 @@ module Spree
4
4
  class CreditCardSerializer < BaseSerializer
5
5
  typelize brand: :string, last4: :string, month: :number, year: :number,
6
6
  name: [:string, nullable: true], default: :boolean,
7
- gateway_payment_profile_id: [:string, nullable: true]
7
+ gateway_payment_profile_id: [:string, nullable: true],
8
+ # Null when that payment method was deleted since.
9
+ payment_method_id: [:string, nullable: true, comment: 'The payment method the card was saved with; a card is offered only for it.']
8
10
 
9
11
  attributes :brand, :last4, :month, :year, :name, :default, :gateway_payment_profile_id
10
12
 
13
+ prefixed_id_attributes :payment_method
14
+
11
15
  expandable_custom_fields
12
16
  end
13
17
  end
@@ -39,7 +39,10 @@ module Spree
39
39
 
40
40
  # Which items (and how many) are in this fulfillment.
41
41
  # A line item can be split across fulfillments with different quantities.
42
- typelize({ item_id: :string, variant_id: :string, quantity: :number }, multi: true)
42
+ typelize({ item_id: [:string, comment: 'Line item ID'],
43
+ variant_id: [:string, comment: 'Variant ID'],
44
+ quantity: [:number, comment: 'Quantity in this fulfillment'] },
45
+ multi: true, comment: 'Which line items, and how many units of each, are in this fulfillment')
43
46
  attribute :items do |fulfillment|
44
47
  fulfillment.manifest.filter_map do |item|
45
48
  next unless item.line_item
@@ -2,7 +2,9 @@ module Spree
2
2
  module Api
3
3
  module V3
4
4
  class PaymentSerializer < BaseSerializer
5
- typelize status: [:string, enum: Spree::Payment.statuses, enum_type_name: 'PaymentStatus'],
5
+ typelize status: [:string, enum: Spree::Payment.statuses, enum_type_name: 'PaymentStatus',
6
+ comment: '`requested` means the payment provider accepted a capture or void and has not answered yet. ' \
7
+ 'Extensions may add statuses.'],
6
8
  payment_method_id: :string, response_code: [:string, nullable: true], number: :string,
7
9
  source_type: [:string, nullable: true, enum: %w[credit_card store_credit payment_source], enum_type_name: 'PaymentSourceType'],
8
10
  source_id: [:string, nullable: true], source: 'CreditCard | StoreCredit | PaymentSource | null'
@@ -4,7 +4,7 @@ module Spree
4
4
  class ProductFiltersSerializer < BaseSerializer
5
5
  typelize default_sort: :string,
6
6
  total_count: :number,
7
- filters: 'Array<ProductFilterPriceRange | ProductFilterAvailability | ProductFilterOption | ProductFilterCategory>',
7
+ filters: [%i[ProductFilterPriceRange ProductFilterAvailability ProductFilterOption ProductFilterCategory], { multi: true }],
8
8
  sort_options: [:ProductFilterSortOption, { multi: true }]
9
9
 
10
10
  attributes :default_sort, :total_count
@@ -24,7 +24,15 @@ module Spree
24
24
  :variant_count,
25
25
  available_on: :iso8601, preorder_ships_at: :iso8601
26
26
 
27
- attribute :purchasable, &:purchasable?
27
+ # A variant priced only for this shopper (a price list, a pricing
28
+ # provider) has no base price, so when none has one the shopper's own
29
+ # quotes are asked, resolving them only for variants that have stock.
30
+ attribute :purchasable do |product|
31
+ product.any_variant_available?(current_currency) ||
32
+ product.sellable_variants.any? do |variant|
33
+ variant.purchasable? && variant.purchasable_in?(current_currency, quote: price_for(variant))
34
+ end
35
+ end
28
36
 
29
37
  # True when this product is currently offered as a pre-order on the
30
38
  # requesting channel.
@@ -51,7 +51,10 @@ module Spree
51
51
  import.rows_status_counts['failed'] || 0
52
52
  end
53
53
 
54
- typelize({ name: :string, label: :string, required: :boolean }, multi: true)
54
+ typelize({ name: [:string, comment: 'Canonical field name used in mappings, e.g. slug'],
55
+ label: [:string, comment: 'Human-readable label'],
56
+ required: [:boolean, comment: 'Whether the field must be mapped before processing'] },
57
+ multi: true, comment: 'Canonical columns of this import type, including per-store custom field columns')
55
58
  attribute :schema_fields do |import|
56
59
  import.schema_fields.map do |field|
57
60
  { name: field[:name], label: field[:label], required: field[:required].present? }
@@ -32,7 +32,9 @@ module Spree
32
32
  image_url_for(variant.primary_media)
33
33
  end
34
34
 
35
- attribute :purchasable, &:purchasable?
35
+ attribute :purchasable do |variant|
36
+ variant.purchasable_in?(current_currency, quote: price_for(variant))
37
+ end
36
38
 
37
39
  attribute :in_stock, &:in_stock?
38
40
 
@@ -173,12 +173,15 @@ module Spree
173
173
  # one kind, a list of kinds (positional arguments), or
174
174
  # `{ 'list' => kind }` for any number of arguments
175
175
  def scopes
176
- @scopes ||= begin
177
- declared = (model.respond_to?(:ransackable_scope_types) ? model.ransackable_scope_types : {}).
178
- merge(Spree.ransack.custom_scope_types_for(model)).stringify_keys
179
- model.ransackable_scopes(audience).map(&:to_s).sort.index_with do |scope|
180
- normalize_scope_type(declared.fetch(scope) { inferred_scope_type(scope) })
181
- end
176
+ @scopes ||= model.ransackable_scopes(audience).map(&:to_s).sort.index_with do |scope|
177
+ # A model reached through an association may be an app's own,
178
+ # without Spree's allowlists.
179
+ type = if model.respond_to?(:ransackable_scope_type)
180
+ model.ransackable_scope_type(scope)
181
+ else
182
+ Spree::RansackableAttributes.scope_type_from_signature(model.method(scope))
183
+ end
184
+ normalize_scope_type(type)
182
185
  end
183
186
  end
184
187
 
@@ -218,9 +221,8 @@ module Spree
218
221
  @kinds ||= model.ransackable_attributes(audience).map(&:to_s).uniq.sort.index_with { |attribute| attribute_kind(attribute) }
219
222
  end
220
223
 
221
- # @return [String, Hash, Symbol, nil] the kind; nil for a default
222
- # attribute the model does not have (`position` on a table without
223
- # one), `:unclassified` for one the contract cannot describe
224
+ # @return [String, Hash, Symbol] the kind; `:unclassified` for one the
225
+ # contract cannot describe
224
226
  def attribute_kind(attribute)
225
227
  if (code_type = code_type(attribute))
226
228
  return { 'code' => code_type }
@@ -239,7 +241,6 @@ module Spree
239
241
  column = model.columns_hash[attribute]
240
242
  return COLUMN_KINDS.fetch(column.type, :unclassified) if column
241
243
  return 'text' if translated_attribute?(attribute)
242
- return nil if model.default_ransackable_attributes.include?(attribute)
243
244
 
244
245
  :unclassified
245
246
  end
@@ -273,22 +274,6 @@ module Spree
273
274
  model.respond_to?(:translatable_fields) && model.translatable_fields.map(&:to_s).include?(attribute)
274
275
  end
275
276
 
276
- # What a class method's signature says about its arguments. A `scope`
277
- # lambda hides its signature behind `(*args, **)`, so an undeclared one
278
- # is published as taking one text value.
279
- def inferred_scope_type(scope)
280
- parameters = model.method(scope).parameters
281
- return 'text' if parameters.any? { |type, _| type == :keyrest }
282
- return { 'list' => 'text' } if parameters.any? { |type, _| type == :rest }
283
-
284
- required = parameters.count { |type, _| type == :req }
285
- case required
286
- when 0 then 'boolean'
287
- when 1 then 'text'
288
- else Array.new(required, 'text')
289
- end
290
- end
291
-
292
277
  def normalize_scope_type(type)
293
278
  case type
294
279
  when Hash then { 'list' => validate_kind(type.stringify_keys.fetch('list')) }
@@ -8,13 +8,15 @@ module Spree
8
8
  # @param sort_order [String, nil] Optional grouping sort_order (space format, e.g. a collection's 'price asc') that drives default_sort
9
9
  # @param option_value_ids [Array<String>] Currently selected option value prefixed IDs (for disjunctive facet counts)
10
10
  # @param scope_before_options [ActiveRecord::Relation] Scope before option value filters (for disjunctive counts)
11
- def initialize(scope:, currency:, category: nil, sort_order: nil, option_value_ids: [], scope_before_options: nil)
11
+ # @param variants [ActiveRecord::Relation<Spree::Variant>, nil] Variants an option value is counted through (see Spree::Variant.for_option_filters); every variant when nil
12
+ def initialize(scope:, currency:, category: nil, sort_order: nil, option_value_ids: [], scope_before_options: nil, variants: nil)
12
13
  @scope = scope
13
14
  @currency = currency
14
15
  @category = category
15
16
  @sort_order = sort_order
16
17
  @option_value_ids = option_value_ids
17
18
  @scope_before_options = scope_before_options || scope
19
+ @variants = variants
18
20
  end
19
21
 
20
22
  def call
@@ -139,13 +141,13 @@ module Spree
139
141
  ovv_table = Spree::OptionValueVariant.table_name
140
142
  var_table = Spree::Variant.table_name
141
143
 
142
- Spree::OptionValueVariant
143
- .joins("INNER JOIN #{var_table} ON #{var_table}.id = #{ovv_table}.variant_id AND #{var_table}.deleted_at IS NULL")
144
- .where(var_table => { product_id: product_scope.reorder('').select(:id) })
145
- .where(ovv_table => { option_value_id: option_value_ids })
146
- .group("#{ovv_table}.option_value_id")
147
- .distinct
148
- .count("#{var_table}.product_id")
144
+ counted = Spree::OptionValueVariant
145
+ .joins("INNER JOIN #{var_table} ON #{var_table}.id = #{ovv_table}.variant_id AND #{var_table}.deleted_at IS NULL")
146
+ .where(var_table => { product_id: product_scope.reorder('').select(:id) })
147
+ .where(ovv_table => { option_value_id: option_value_ids })
148
+ counted = counted.where(var_table => { id: @variants.select(:id) }) if @variants
149
+
150
+ counted.group("#{ovv_table}.option_value_id").distinct.count("#{var_table}.product_id")
149
151
  end
150
152
 
151
153
  # Load translated labels for option values.
@@ -224,16 +226,9 @@ module Spree
224
226
  # If this type has selections but no other types do, use scope before any option filters
225
227
  return @scope_before_options if other_groups.empty?
226
228
 
227
- # Rebuild: start from scope before options, apply only other option types
228
- scope = @scope_before_options
229
- other_groups.each_value do |ov_ids|
230
- matching = Spree::Variant.where(deleted_at: nil)
231
- .joins(:option_value_variants)
232
- .where(Spree::OptionValueVariant.table_name => { option_value_id: ov_ids })
233
- .select(:product_id)
234
- scope = scope.where(id: matching)
235
- end
236
- scope
229
+ # Rebuild: start from scope before options, apply only other option
230
+ # types — matched the way the listing matches them
231
+ @scope_before_options.with_option_value_ids(other_groups.values.flatten, variants: @variants)
237
232
  end
238
233
 
239
234
  # Group selected option value IDs by option type (cached, single query)
@@ -16,6 +16,7 @@ en:
16
16
  media_not_deleted: The file could not be deleted. Nothing was changed.
17
17
  media_url_import_requires_product: Importing media from a URL needs a product to import it into. Upload the file instead, or post it to a product's media.
18
18
  order_sales_context_exclusive: An order already fixes its sales context, so order_id cannot be combined with %{params}.
19
+ request_failed: The request could not be completed.
19
20
  store_mismatch: The requested store does not match the store this API key belongs to.
20
21
  storefront_login_required: Authentication required to access this store.
21
22
  unsupported_export_type: 'Unsupported export type. Supported types: %{types}'
@@ -24,11 +24,14 @@ module Spree
24
24
  # keeps one property per name within a serializer and so would hide two
25
25
  # attributes of one serializer that disagree.
26
26
  #
27
- # @return [Array<Typelizer::Property>] the named enum properties of every serializer each Typelizer writer emits
27
+ # Typelizer's default writer is left out: Spree writes nothing with it,
28
+ # and it takes every serializer class, an unnamed one from a spec included.
29
+ #
30
+ # @return [Array<Typelizer::Property>] the named enum properties of every serializer Spree's writers emit
28
31
  def self.serializer_properties
29
- Typelizer.configuration.writers.keys
30
- .flat_map { |writer_name| Typelizer.interfaces(writer_name: writer_name) }
31
- .flat_map { |interface| named_properties(interface.properties + interface.trait_interfaces.flat_map(&:properties)) }
32
+ writers = Typelizer.configuration.writers.keys - [Typelizer::Configuration::DEFAULT_WRITER_NAME]
33
+ writers.flat_map { |writer_name| Typelizer.interfaces(writer_name: writer_name) }.
34
+ flat_map { |interface| named_properties(interface.properties + interface.trait_interfaces.flat_map(&:properties)) }
32
35
  end
33
36
 
34
37
  # @param properties [Array<Typelizer::Property>]