@@ -19,7 +19,7 @@ final class AggregateDataHelper {
1919
2020 /// Combine all refunded products into a single data source
2121 ///
22- static func combineRefundedProducts( from refunds: [ Refund ] ) -> [ AggregateOrderItem ] ? {
22+ static func combineRefundedProducts( from refunds: [ Refund ] , orderItems : [ OrderItem ] ) -> [ AggregateOrderItem ] ? {
2323 /// OrderItemRefund.orderItemID isn't useful for finding duplicates
2424 /// because multiple refunds cause orderItemIDs to be unique.
2525 /// Instead, we need to find duplicate *Products*.
@@ -49,6 +49,8 @@ final class AggregateDataHelper {
4949 . compactMap { currency. convertToDecimal ( $0. total) }
5050 . reduce ( NSDecimalNumber ( value: 0 ) , { $0. adding ( $1) } )
5151
52+ let attributes = orderItems. first ( where: { $0. itemID == item. refundedItemID } ) ? . attributes ?? [ ]
53+
5254 return AggregateOrderItem (
5355 productID: item. productID,
5456 variationID: item. variationID,
@@ -57,7 +59,7 @@ final class AggregateDataHelper {
5759 quantity: totalQuantity,
5860 sku: item. sku,
5961 total: total,
60- attributes: [ ]
62+ attributes: attributes
6163 )
6264 }
6365
@@ -70,7 +72,7 @@ final class AggregateDataHelper {
7072 /// to get a tally for the quantity and item total
7173 ///
7274 static func combineOrderItems( _ items: [ OrderItem ] , with refunds: [ Refund ] ) -> [ AggregateOrderItem ] {
73- guard let refundedProducts = combineRefundedProducts ( from: refunds) else {
75+ guard let refundedProducts = combineRefundedProducts ( from: refunds, orderItems : items ) else {
7476 fatalError ( " Error: attempted to calculate aggregate order item data with no refunded products. " )
7577 }
7678
0 commit comments