I am trying to create a new order with line items based on data sent from a Lightning Web Component to my Apex class.
I have managed to send the data by using the following function:
newOrder(){
let Items = JSON.stringify(this.cartItems);
createCheckoutOrder({lstProds: Items});
window.console.log('Cart Items '+ Items);
}
This is the apex class that I am using:
public static void createCheckoutOrder(List<Map<string, object>> lstProds){
system.debug(lstProds);
list<OrderItem> orderItems = new list<OrderItem>();
for(Object pl: lstProds){
orderItems.add(new OrderItem(UnitPrice = pl.UnitPrice,
OrderId = ord.id,
Quantity = pl.quantity,
Product2Id = pl.Id,
PricebookEntryId = pl.PricebookEntryId
));
}
system.debug(orderItems);
insert orderItems;
}
This is the form of the data in the debug log:
({element={Id=01t0X000008AclSQAS, PricebookEntryId=01u0X000011uFBwQAM, UnitPrice=25000, quantity=1}}, {element={Id=01t0X000008AclVQAS, PricebookEntryId=01u0X000011uFBzQAM, UnitPrice=20000, quantity=1}}, {element={Id=01t0X000008AclbQAC, PricebookEntryId=01u0X000011uFC5QAM, UnitPrice=10000, quantity=1}})
I have tried to create a new OrderItem List and add items to the list based on the data received form the LWC. How can I correctly assign values to the order item fields with the correct values from the LWC?