Skip to content

Commit

Permalink
WIP #2112 create job when add to cart
Browse files Browse the repository at this point in the history
  • Loading branch information
LengTech11 committed Dec 6, 2024
1 parent b011684 commit 94893db
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ def ensure_cart_exist

@spree_current_order ||= create_service.call(create_cart_params).value
end

def add_item_queue
spree_authorize! :update, spree_current_order, order_token
spree_authorize! :show, @variant

AddItemJob.perform_later(
spree_current_order,
@variant,
add_item_params[:quantity],
add_item_params[:public_metadata],
add_item_params[:private_metadata],
add_item_params[:options]
)

render json: { message: 'Item added to queue' }, status: :ok
end
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions app/jobs/spree_cm_commissioner/add_item_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module SpreeCmCommissioner
class AddItemJob < ApplicationJob
queue_as :default

def perform(order, variant, quantity, public_metadata, private_metadata, options) # rubocop:disable Metrics/ParameterLists
SpreeCmCommissioner::Cart::AddItem.call(
order: order,
variant: variant,
quantity: quantity,
public_metadata: public_metadata,
private_metadata: private_metadata,
options: options
)
end
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@

resource :cart, controller: :cart, only: %i[show create destroy] do
patch :restart_checkout_flow
post :add_item_queue
end

resources :wished_items
Expand Down

0 comments on commit 94893db

Please sign in to comment.