From 4fa1f4ac81951f9b373d2167413ac3401fd8d060 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Thu, 13 Apr 2023 18:14:25 -0600 Subject: AƱade servicios y validaciones de pago MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/payment/cart_to_order_service.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 app/services/payment/cart_to_order_service.rb (limited to 'app/services/payment/cart_to_order_service.rb') diff --git a/app/services/payment/cart_to_order_service.rb b/app/services/payment/cart_to_order_service.rb new file mode 100644 index 0000000..8dff43e --- /dev/null +++ b/app/services/payment/cart_to_order_service.rb @@ -0,0 +1,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 -- cgit v1.2.3