Created
April 19, 2021 09:26
-
-
Save viggin543/02bea89f6439cbdbca5ce85e014c9ce4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func calcTotalDiscount(currentCart *commercetools.Cart, response *cart_service.CartPriceSummeryResponse) { | |
| if len(currentCart.DiscountCodes) != 0 { | |
| for _, lineItem := range currentCart.LineItems { | |
| for _, discountedPrice := range lineItem.DiscountedPricePerQuantity { | |
| response.TotalDiscount += centAmount(discountedPrice.DiscountedPrice.Value) * int32(discountedPrice.Quantity) | |
| } | |
| } | |
| for _,code := range currentCart.DiscountCodes { | |
| if code.State == commercetools.DiscountCodeStateMatchesCart { | |
| for _, cartDiscount := range code.DiscountCode.Obj.CartDiscounts { | |
| switch v := cartDiscount.Obj.Value.(type) { | |
| case commercetools.CartDiscountValueAbsolute: | |
| for _, m := range v.Money { | |
| response.TotalDiscount += centAmount(m) | |
| } | |
| default: | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment