From b7455b581022059a87633864c2ac2751b035e1e1 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Thu, 6 Apr 2023 13:29:17 -0600 Subject: AƱadido controlador de carrito MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/serializers/cart_serializer.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 app/serializers/cart_serializer.rb (limited to 'app/serializers/cart_serializer.rb') diff --git a/app/serializers/cart_serializer.rb b/app/serializers/cart_serializer.rb new file mode 100644 index 0000000..cbe46d8 --- /dev/null +++ b/app/serializers/cart_serializer.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +# CartSerializer +class CartSerializer < BaseSerializer + attribute :products do |object| + ProductSerializer.new( + Product.joins(:product_carts).select('products.*', 'product_carts.quantity AS quantity') + .includes(picture_attachment: :blob).where('product_carts.cart_id = ?', object.id) + ).serializable_hash + end +end -- cgit v1.2.3