Sha256: 1e783c3982f015da9350e8184e9de69b6131e59eaab786e3d45a1feeb559599e

Contents?: true

Size: 1.5 KB

Versions: 131

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

module Spree
  module Admin
    class ShippingMethodsController < ResourceController
      before_action :load_data, except: :index
      before_action :set_shipping_category, only: [:create, :update]
      before_action :set_zones, only: [:create, :update]

      def destroy
        @object.discard

        flash[:success] = flash_message_for(@object, :successfully_removed)

        respond_with(@object) do |format|
          format.html { redirect_to collection_url }
          format.js { render_js_for_destroy }
        end
      end

      private

      def set_shipping_category
        return true if params["shipping_method"][:shipping_categories] == ""
        @shipping_method.shipping_categories = Spree::ShippingCategory.where(id: params["shipping_method"][:shipping_categories])
        @shipping_method.save
        params[:shipping_method].delete(:shipping_categories)
      end

      def set_zones
        return true if params["shipping_method"][:zones] == ""
        @shipping_method.zones = Spree::Zone.where(id: params["shipping_method"][:zones])
        @shipping_method.save
        params[:shipping_method].delete(:zones)
      end

      def location_after_save
        edit_admin_shipping_method_path(@shipping_method)
      end

      def load_data
        @available_zones = Spree::Zone.order(:name)
        @tax_categories = Spree::TaxCategory.order(:name)
        @calculators = Rails.application.config.spree.calculators.shipping_methods
      end
    end
  end
end

Version data entries

131 entries across 131 versions & 2 rubygems

Version Path
solidus_backend-4.4.1 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-4.4.0 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-4.3.4 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-4.2.4 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-4.1.5 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-4.3.3 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-4.3.2 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-4.1.4 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-4.3.1 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-4.3.0 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-4.2.3 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-4.1.3 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-4.0.4 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-3.4.6 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-4.0.3 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-4.1.2 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-4.2.2 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-3.4.5 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-4.2.1 app/controllers/spree/admin/shipping_methods_controller.rb
solidus_backend-4.2.0 app/controllers/spree/admin/shipping_methods_controller.rb