flamingo.me/flamingo-commerce/v3@v3.11.0/cart/interfaces/graphql/dto/pricedItems.go (about) 1 package dto 2 3 import ( 4 "flamingo.me/flamingo-commerce/v3/cart/domain/cart" 5 "flamingo.me/flamingo-commerce/v3/price/domain" 6 ) 7 8 type ( 9 // PricedItems – provides custom graphql interface methods 10 PricedItems struct { 11 items cart.PricedItems 12 } 13 14 // PricedShippingItem – shipping item with price 15 PricedShippingItem struct { 16 Amount domain.Price 17 DeliveryInfoCode string 18 } 19 20 // PricedTotalItem – total item with price 21 PricedTotalItem struct { 22 Amount domain.Price 23 Code string 24 } 25 26 // PricedCartItem – cart item with price 27 PricedCartItem struct { 28 Amount domain.Price 29 ItemID string 30 } 31 ) 32 33 // CartItems – return all cart items 34 func (pr PricedItems) CartItems() []PricedCartItem { 35 var items []PricedCartItem 36 37 for CartItemID, price := range pr.items.CartItems() { 38 items = append(items, PricedCartItem{ 39 Amount: price, 40 ItemID: CartItemID, 41 }) 42 } 43 44 return items 45 } 46 47 // TotalItems – return all total items 48 func (pr PricedItems) TotalItems() []PricedTotalItem { 49 var items []PricedTotalItem 50 51 for totalItemCode, price := range pr.items.TotalItems() { 52 items = append(items, PricedTotalItem{ 53 Amount: price, 54 Code: totalItemCode, 55 }) 56 } 57 58 return items 59 } 60 61 // ShippingItems – return all shipping items 62 func (pr PricedItems) ShippingItems() []PricedShippingItem { 63 var items []PricedShippingItem 64 65 for deliveryInfoCode, price := range pr.items.ShippingItems() { 66 items = append(items, PricedShippingItem{ 67 Amount: price, 68 DeliveryInfoCode: deliveryInfoCode, 69 }) 70 } 71 72 return items 73 }