How to map and save Cart Collection product references and quantities to Orders Collection in FlutterFlow?

Actions & Logic

I’m working on a FlutterFlow project where I need to map product references and quantities from the Cart Collection to the Orders Collection’s cartItemRef field during the checkout process. The cartItemRef is a custom datatype that holds ProductRef (as DocumentReference) and Product_quantity (as an integer).

Cart Collection Schema:

• Product_quantity (Integer)

• ProductRef (Doc Reference to Product)


Orders Collection Schema:

• Order_id (String)

• Order_amount (Double)

• Customer_email (String)

• Order_date (DateTime)

• Order_items (List of Strings)

• cartItemRef (List of cartOrderRef)


cartOrderRef Schema:

• ProductRef (List of Doc Reference to Product)

• Product_quantity (List of Integers)

I’ve already created a backend query to retrieve the ProductRef and Product_quantity from the Cart Collection. I need to create a custom function that takes these two as inputs and returns a mapped list.

What have you tried so far?

1. Created a backend query to retrieve ProductRef and Product_quantity from the Cart Collection.

2. Defined a custom function in FlutterFlow to map these fields to cartItemRef.

3. Encountered issues with data types and mismatched lengths of lists.

Did you check FlutterFlow's Documentation for this topic?
Yes