PageRenderTime 1537ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/backend/app/controllers/spree/admin/promotions_controller.rb

https://gitlab.com/adamlwalker/spree
Ruby | 38 lines | 31 code | 7 blank | 0 comment | 2 complexity | b32b12ec19d8e53c16e8e96af16a59a7 MD5 | raw file
  1. module Spree
  2. module Admin
  3. class PromotionsController < ResourceController
  4. before_action :load_data
  5. helper 'spree/promotion_rules'
  6. protected
  7. def location_after_save
  8. spree.edit_admin_promotion_url(@promotion)
  9. end
  10. def load_data
  11. @calculators = Rails.application.config.spree.calculators.promotion_actions_create_adjustments
  12. @promotion_categories = Spree::PromotionCategory.order(:name)
  13. end
  14. def collection
  15. return @collection if defined?(@collection)
  16. params[:q] ||= HashWithIndifferentAccess.new
  17. params[:q][:s] ||= 'id desc'
  18. @collection = super
  19. @search = @collection.ransack(params[:q])
  20. @collection = @search.result(distinct: true).
  21. includes(promotion_includes).
  22. page(params[:page]).
  23. per(params[:per_page] || Spree::Config[:promotions_per_page])
  24. @collection
  25. end
  26. def promotion_includes
  27. [:promotion_actions]
  28. end
  29. end
  30. end
  31. end