From fa71ad1786a9d9a3d9d6725dfc0858e393293a7b Mon Sep 17 00:00:00 2001 From: LengTech11 Date: Tue, 17 Dec 2024 11:30:03 +0700 Subject: [PATCH] WIP #2129 fix calculate ticket flow --- .../operator/recalculate_ticket_controller.rb | 31 +++++++++++++++++++ config/routes.rb | 1 + 2 files changed, 32 insertions(+) create mode 100644 app/controllers/spree/api/v2/operator/recalculate_ticket_controller.rb diff --git a/app/controllers/spree/api/v2/operator/recalculate_ticket_controller.rb b/app/controllers/spree/api/v2/operator/recalculate_ticket_controller.rb new file mode 100644 index 000000000..8204db7c0 --- /dev/null +++ b/app/controllers/spree/api/v2/operator/recalculate_ticket_controller.rb @@ -0,0 +1,31 @@ +module Spree + module Api + module V2 + module Operator + class RecalculateTicketController < ::Spree::Api::V2::ResourceController + before_action :require_spree_current_user, only: :create + before_action :load_taxon, only: :create + + def create + @taxons.each do |taxon| + taxon.products.each do |product| + product.classification_ids.each do |classification_id| + SpreeCmCommissioner::ConversionPreCalculator.call(product_taxon: Spree::Classification.find(classification_id)) + end + end + end + + render json: { message: 'Conversions recalculated successfully' }, status: :ok + end + + private + + def load_taxon + parent_taxon = Spree::Taxon.find(params[:taxon_id]) + @taxons = parent_taxon.children + end + end + end + end + end +end diff --git a/config/routes.rb b/config/routes.rb index d4d008b83..6dcca108d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -487,6 +487,7 @@ resources :taxons, only: %i[show] do resource :event_ticket_aggregators, only: %i[show] resource :pie_chart_event_aggregators, only: %i[show] + resources :recalculate_ticket, only: [:create] end end end