Sha256: 7b3b4629e5e1b47ee5c161ee340577902c319649a5619f3c46e0373caf59c9bd

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

class OrdersController < ApplicationController
  include Devise::Controllers::Helpers
  layout 'cabinet'

  before_action :load_structure
  respond_to :json, only: [:create]
  skip_before_action :verify_authenticity_token, only: [:create]

  def new
    @account = current_account
    @form = OrderForm.new(
      account: { country_code: request_country_code },
      order: { fileupload_token: SecureRandom.base64(15).tr('+/=', 'xyz') },
      customer_mode_id: @account.blank? ? CustomerMode.sign_up.id : CustomerMode.signed.id
    )
    respond_with(@form)
  end

  def create
    @form = OrderForm.new(params)
    # @customer.assign_attributes(customer_params)

    if @form.valid? && @form.submit && current_account.blank? && @form.session
      account = TranslationCms::Api::Customer.new(session: @form.session)
      _signed = sign_in(:account, account) if account
    end

    respond_with(@form, location: order_payment_provider_redirect_url(@form.order))
  end

  private

  def load_structure
    @structure = structure_by(slug: 'additional-order-page')
    @structure ||= structure_by(structure_type_id: StructureType.main.id)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
translation_cms-0.1.5 app/controllers/orders_controller.rb