Sha256: c7c1b110c1cb6cbac560fe1c5b06d7c6eba1fa0fd06c1dbd02c3270691c838dd

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module SolidusAdmin
  class LineItemsController < SolidusAdmin::BaseController
    def destroy
      load_order
      load_line_item

      @line_item.destroy!

      redirect_to order_path(@order), status: :see_other, notice: t('.success')
    end

    def create
      load_order
      variant_id = params.require(:line_item).require(:variant_id)
      @variant = Spree::Variant.find(variant_id)
      @line_item = @order.contents.add(@variant)

      redirect_to order_path(@order), status: :see_other, notice: t('.success')
    end

    def update
      load_order
      load_line_item

      desired_quantity = params[:line_item][:quantity].to_i

      @line_item = @order.contents.add(@line_item.variant, desired_quantity - @line_item.quantity)

      redirect_to order_path(@order), status: :see_other, notice: t('.success')
    end

    private

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

    def load_line_item
      @line_item = @order.line_items.find(params[:id])
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
solidus_admin-0.3.2 app/controllers/solidus_admin/line_items_controller.rb
solidus_admin-0.3.1 app/controllers/solidus_admin/line_items_controller.rb
solidus_admin-0.3.0 app/controllers/solidus_admin/line_items_controller.rb
solidus_admin-0.2.0 app/controllers/solidus_admin/line_items_controller.rb
solidus_admin-0.1.0 app/controllers/solidus_admin/line_items_controller.rb