summaryrefslogtreecommitdiff
path: root/app/services/payment/cart_to_order_service.rb
blob: 8dff43ea67b3a7cebc7c03e289cb7ee125174f6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# frozen_string_literal: true

module Payment
  # CartToOrderService
  class CartToOrderService
    def initialize(user_account)
      @user_account = user_account
      @cart = @user_account.cart
    end

    def call
      order = Order.create(user_account_id: @user_account.id)

      @cart.product_carts.pluck(:product_id, :quantity).each do |data|
        ProductOrder.create(order_id: order.id, product_id: data[0], quantity: data[1])
      end

      order
    end
  end
end