Sha256: 21c2c0f7b2f5fce6dc26ef6c59a53a52f106e844e7ed538c578e94a4eb47a1ba

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module SolidusVolumePricing
  module Spree
    module Admin
      module VariantsControllerDecorator
        def edit
          @variant.volume_prices.build if @variant.volume_prices.empty?
          super
        end

        def volume_prices
          @product = @variant.product
          @variant.volume_prices.build if @variant.volume_prices.empty?
        end

        private

        # this loads the variant for the master variant volume price editing
        def load_resource_instance
          parent

          if new_actions.include?(params[:action].to_sym)
            build_resource
          elsif params[:id]
            ::Spree::Variant.find(params[:id])
          end
        end

        def location_after_save
          if @product.master.id == @variant.id && params[:variant].key?(:volume_prices_attributes)
            return volume_prices_admin_product_variant_url(@product, @variant)
          end

          super
        end

        ::Spree::Admin::VariantsController.prepend self
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
solidus_volume_pricing-1.2.0 app/decorators/controllers/solidus_volume_pricing/spree/admin/variants_controller_decorator.rb
solidus_volume_pricing-1.1.1 app/decorators/controllers/solidus_volume_pricing/spree/admin/variants_controller_decorator.rb
solidus_volume_pricing-1.1.0 app/decorators/controllers/solidus_volume_pricing/spree/admin/variants_controller_decorator.rb
solidus_volume_pricing-1.0.0 app/decorators/controllers/solidus_volume_pricing/spree/admin/variants_controller_decorator.rb