Sha256: 47dcc7e45a905029c9d1e650aa3e38582eef46b98034f77da96b1767d841d276

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

class SolidusAdmin::AdjustmentsController < SolidusAdmin::BaseController
  before_action :load_order

  def index
    load_adjustments
    set_page_and_extract_portion_from(@adjustments)

    respond_to do |format|
      format.html do
        render component('orders/show/adjustments/index').new(
          order: @order,
          adjustments: @adjustments,
        )
      end
    end
  end

  def lock
    @adjustments = @order.all_adjustments.not_finalized.where(id: params[:id])
    @adjustments.each(&:finalize!)
    flash[:success] = t('.success')

    redirect_to order_adjustments_path(@order), status: :see_other
  end

  def unlock
    @adjustments = @order.all_adjustments.finalized.where(id: params[:id])
    @adjustments.each(&:unfinalize!)
    flash[:success] = t('.success')

    redirect_to order_adjustments_path(@order), status: :see_other
  end

  def destroy
    @adjustments = @order.all_adjustments.where(id: params[:id])
    @adjustments.destroy_all
    flash[:success] = t('.success')

    redirect_to order_adjustments_path(@order), status: :see_other
  end

  private

  def load_adjustments
    @adjustments = @order
      .all_adjustments
      .order("adjustable_type ASC, created_at ASC")
      .ransack(params[:q])
      .result
  end

  def load_order
    @order = Spree::Order.find_by!(number: params[:order_id])
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solidus_admin-0.3.2 app/controllers/solidus_admin/adjustments_controller.rb
solidus_admin-0.3.1 app/controllers/solidus_admin/adjustments_controller.rb
solidus_admin-0.3.0 app/controllers/solidus_admin/adjustments_controller.rb