/backend/app/controllers/spree/admin/promotions_controller.rb
Ruby | 38 lines | 31 code | 7 blank | 0 comment | 2 complexity | b32b12ec19d8e53c16e8e96af16a59a7 MD5 | raw file
- module Spree
- module Admin
- class PromotionsController < ResourceController
- before_action :load_data
- helper 'spree/promotion_rules'
- protected
- def location_after_save
- spree.edit_admin_promotion_url(@promotion)
- end
- def load_data
- @calculators = Rails.application.config.spree.calculators.promotion_actions_create_adjustments
- @promotion_categories = Spree::PromotionCategory.order(:name)
- end
- def collection
- return @collection if defined?(@collection)
- params[:q] ||= HashWithIndifferentAccess.new
- params[:q][:s] ||= 'id desc'
- @collection = super
- @search = @collection.ransack(params[:q])
- @collection = @search.result(distinct: true).
- includes(promotion_includes).
- page(params[:page]).
- per(params[:per_page] || Spree::Config[:promotions_per_page])
- @collection
- end
- def promotion_includes
- [:promotion_actions]
- end
- end
- end
- end