Skip to content

Commit

Permalink
feat(cart): add SumPaymentSelectionCartSplitPriceAmountByMethods (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanMaidurov committed May 6, 2024
1 parent 2206c07 commit 4d5d020
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cart/interfaces/graphql/dto/cartSummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,35 @@ func (cs CartSummary) SumPaymentSelectionCartSplitValueAmountByMethods(methods [
return &price
}

// SumPaymentSelectionCartSplitPriceAmountByMethods sum
func (cs CartSummary) SumPaymentSelectionCartSplitPriceAmountByMethods(methods []string) *domain.Price {
if cs.cart.PaymentSelection == nil {
return nil
}

prices := make([]domain.Price, 0, len(methods))

for qualifier, charge := range cs.cart.PaymentSelection.CartSplit() {
found := contains(methods, qualifier.Method)
if !found {
continue
}

prices = append(prices, charge.Price)
}

if len(prices) == 0 {
return nil
}

price, err := domain.SumAll(prices...)
if err != nil {
return nil
}

return &price
}

// Contains tells whether a contains x.
func contains(a []string, x string) bool {
for _, n := range a {
Expand Down
1 change: 1 addition & 0 deletions cart/interfaces/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Commerce_Cart_Summary {
hasAppliedDiscounts: Boolean!
sumTaxes: Commerce_Cart_Taxes
sumPaymentSelectionCartSplitValueAmountByMethods(methods: [String!]): Commerce_Price
sumPaymentSelectionCartSplitPriceAmountByMethods(methods: [String!]): Commerce_Price
}

type Commerce_Cart_Cart {
Expand Down
90 changes: 90 additions & 0 deletions test/integrationtest/projecttest/graphql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Commerce_Cart_Summary {
hasAppliedDiscounts: Boolean!
sumTaxes: Commerce_Cart_Taxes
sumPaymentSelectionCartSplitValueAmountByMethods(methods: [String!]): Commerce_Price
sumPaymentSelectionCartSplitPriceAmountByMethods(methods: [String!]): Commerce_Price
}

type Commerce_Cart_Cart {
Expand Down

0 comments on commit 4d5d020

Please sign in to comment.