Class: SpreeCmCommissioner::ProductCompletionSteps::SocialEntryUrl

Inherits:
SpreeCmCommissioner::ProductCompletionStep show all
Defined in:
app/models/spree_cm_commissioner/product_completion_steps/social_entry_url.rb

Constant Summary collapse

ORDER_ALLOWED_FIELDS =

Allowed fields per object (excludes private/reference fields like *_id, *_by_id, metadata, etc.)

%w[
  qr_data
  number
  state
  email
  total
  item_total
  created_at
  completed_at
  token
  phone_number
  country_code
  currency
  item_count
  channel
].freeze
LINE_ITEM_ALLOWED_FIELDS =
%w[
  qr_data
  quantity
  price
  from_date
  to_date
  number
  remark
  created_at
  updated_at
].freeze
GUEST_ALLOWED_FIELDS =
%w[
  qr_data
  first_name
  last_name
  full_name
  dob
  gender
  age
  email
  phone_number
  address
  seat_number
  bib_number
  bib_prefix
  bib_index
  formatted_bib_number
  token
  social_contact
  country_code
  emergency_contact
  expectation
  other_occupation
  other_organization
  entry_type
  upload_later
  data_fill_stage_phase
  created_at
  updated_at
].freeze

Instance Method Summary collapse

Methods inherited from SpreeCmCommissioner::ProductCompletionStep

#construct_hash

Instance Method Details

#action_url_for(line_item) ⇒ Object

override



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/spree_cm_commissioner/product_completion_steps/social_entry_url.rb', line 71

def action_url_for(line_item)
  return nil if preferred_entry_point_link.blank?

  url = preferred_entry_point_link.dup

  # Replace order placeholders: {order.field_name}
  line_item.order.attributes.each do |field, value|
    url.gsub!("{order.#{field}}", value.to_s) if ORDER_ALLOWED_FIELDS.include?(field)
  end

  # Replace line_item placeholders: {line_item.field_name}
  line_item.attributes.each do |field, value|
    url.gsub!("{line_item.#{field}}", value.to_s) if LINE_ITEM_ALLOWED_FIELDS.include?(field)
  end

  # Replace guest placeholders: {guests[index].field_name}
  line_item.guests.each_with_index do |guest, index|
    guest.attributes.each do |field, value|
      url.gsub!("{guests[#{index}].#{field}}", value.to_s) if GUEST_ALLOWED_FIELDS.include?(field)
    end
  end

  url
end

#completed?(line_item) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
99
100
101
# File 'app/models/spree_cm_commissioner/product_completion_steps/social_entry_url.rb', line 96

def completed?(line_item)
  return false if line_item.completion_steps.blank?

  step_data = line_item.completion_steps.find { |step| step['position'].to_s == position.to_s }
  step_data&.dig('completed_at').present?
end