Sha256: f7c850c22fdb1b0e3489097e56056e532af17224e787c947e4549c45fc9751d3

Contents?: true

Size: 1.66 KB

Versions: 62

Compression:

Stored size: 1.66 KB

Contents

module Workarea
  module Admin
    class PricesController < Admin::ApplicationController
      required_permissions :catalog

      before_action :check_publishing_authorization
      before_action :find_sku
      before_action :find_price, except: [:index, :new]

      def index
      end

      def new
      end

      def create
        if @price.save
          flash[:success] =
            t('workarea.admin.prices.flash_messages.saved', sku: @sku.id)
          redirect_to pricing_sku_prices_path(@sku)
        else
          render :index, status: :unprocessable_entity
        end
      end

      def edit
      end

      def update
        if @price.update_attributes(price_params)
          flash[:success] =
            t('workarea.admin.prices.flash_messages.saved', sku: @sku.id)
          redirect_to pricing_sku_prices_path(@sku)
        else
          render :edit, status: :unprocessable_entity
        end
      end

      def destroy
        @price.destroy

        flash[:success] =
          t('workarea.admin.prices.flash_messages.deleted', sku: @sku.id)
        redirect_to pricing_sku_prices_path(@sku)
      end

      private

      def price_params
        # Blank strings convert to $0 when to_money is called
        (params[:price] || {}).transform_values(&:presence)
      end

      def find_sku
        @sku = PricingSkuViewModel.wrap(
          Pricing::Sku.find(params[:pricing_sku_id])
        )
      end

      def find_price
        @price = if params[:id].present?
                   @sku.prices.find_or_create_by(id: params[:id])
                 else
                   @sku.prices.build(price_params)
                 end
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.5.26 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.4.45 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.5.25 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.5.23 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.4.44 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.5.22 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.4.43 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.5.21 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.4.42 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.5.20 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.4.41 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.5.19 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.4.40 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.5.18 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.4.39 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.5.17 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.4.38 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.5.16 app/controllers/workarea/admin/prices_controller.rb
workarea-admin-3.4.37 app/controllers/workarea/admin/prices_controller.rb