Sha256: d78d1e2e8c737fab7cfd7f1ff29c66c99146381d3652433252dec31133c8c86d
Contents?: true
Size: 1.97 KB
Versions: 2
Compression:
Stored size: 1.97 KB
Contents
# frozen_string_literal: true module Spree module Core module ControllerHelpers # Spree::Core::ControllerHelpers::Order decorator to inject Flow.io Experience into the order, if such an # Experience is present in the Order's zone module FlowIoOrderHelperDecorator private def adjust_zone_and_ip update_meta = @current_order.zone_id ? nil : true @current_order.zone = current_zone if @current_order.zone&.flow_io_active_experience? && @current_order.flow_io_experience_key.nil? @current_order.flow_io_experience_from_zone order_flow_io_session_id = @current_order.flow_data['session_id'] flow_io_session_id = session['_f60_session'] if order_flow_io_session_id.present? && flow_io_session_id.blank? session['_f60_session'] = order_flow_io_session_id elsif flow_io_session_id.present? @current_order.flow_data['session_id'] = flow_io_session_id end update_meta = true end if @current_order.new_record? @current_order.last_ip_address = ip_address return @current_order.save end attrs_to_update = {} # Update last_ip_address only for a new request_id attrs_to_update = { last_ip_address: ip_address } if @request_id != request_id # :meta is a jsonb column costly to update every time, especially with all the flow.io data, that's why # here it is updated only if no zone_id there was inside :meta attrs_to_update[:meta] = @current_order.meta.to_json if update_meta @current_order.update_columns(attrs_to_update) if attrs_to_update.present? attrs_to_update end def request_id @request_id ||= env['action_dispatch.request_id'] end ApplicationController.prepend(self) if ApplicationController.included_modules.exclude?(self) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems