PageRenderTime 1306ms CodeModel.GetById 52ms RepoModel.GetById 11ms app.codeStats 0ms

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

https://github.com/fig/spree
Ruby | 37 lines | 30 code | 7 blank | 0 comment | 2 complexity | 68ed9bb32e45895538e9b9087d967d2b MD5 | raw file
Possible License(s): BSD-3-Clause
  1. module Spree
  2. module Admin
  3. class PromotionsController < ResourceController
  4. before_action :load_data
  5. helper 'spree/admin/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[:admin_promotions_per_page])
  24. end
  25. def promotion_includes
  26. [:promotion_actions]
  27. end
  28. end
  29. end
  30. end