Sha256: 0036958deb1356e0de96d6ee5de9428e7db301ae601cd67442e7b10a33b3384c

Contents?: true

Size: 1.72 KB

Versions: 24

Compression:

Stored size: 1.72 KB

Contents

module Spree
  module Admin
    class VariantsController < ResourceController
      belongs_to 'spree/product', find_by: :slug
      new_action.before :new_before
      before_action :load_data, only: [:new, :create, :edit, :update]

      # override the destroy method to set deleted_at value
      # instead of actually deleting the product.
      def destroy
        @variant = Variant.find(params[:id])
        if @variant.destroy
          flash[:success] = Spree.t('notice_messages.variant_deleted')
        else
          flash[:error] = Spree.t('notice_messages.variant_not_deleted')
        end

        respond_with(@variant) do |format|
          format.html { redirect_to admin_product_variants_url(params[:product_id]) }
          format.js { render_js_for_destroy }
        end
      end

      protected

      def new_before
        master = @object.product.master
        @object.attributes = master.attributes.except(
          'id', 'created_at', 'deleted_at', 'sku', 'is_master'
        )

        # Shallow Clone of the default price to populate the price field.
        @object.default_price = master.default_price.clone if master.default_price.present?
      end

      def parent
        @product = Product.with_deleted.friendly.find(params[:product_id])
      end

      def collection
        @deleted = (params.key?(:deleted) && params[:deleted] == "on") ? "checked" : ""

        @collection ||=
          if @deleted.blank?
            super.includes(:default_price, option_values: :option_type)
          else
            Variant.only_deleted.where(product_id: parent.id)
          end
        @collection
      end

      private

      def load_data
        @tax_categories = TaxCategory.order(:name)
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
spree_backend-3.2.9 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.3.6 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.2.8 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.3.5 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.3.4 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.2.7 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.3.3 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.2.6 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.3.2 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.2.5 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.3.1 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.2.4 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.3.0 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.3.0.rc4 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.3.0.rc3 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.2.3 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.2.2 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.3.0.rc2 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.3.0.rc1 app/controllers/spree/admin/variants_controller.rb
spree_backend-3.2.1 app/controllers/spree/admin/variants_controller.rb