mirror of
https://github.com/foomo/shop.git
synced 2026-08-12 04:30:19 +00:00
IsAmountIndependentOfQty
This commit is contained in:
@@ -15,7 +15,12 @@ func calculateDiscountsItemByAbsolute(priceRuleVoucherPair RuleVoucherPair, orde
|
||||
discountApplied := getInitializedDiscountApplied(priceRuleVoucherPair, orderDiscounts, article.ID)
|
||||
|
||||
//calculate the actual discount
|
||||
discountApplied.DiscountAmount = roundToStep((orderDiscounts[article.ID].Quantity * priceRuleVoucherPair.Rule.Amount), calculationParameters.roundTo)
|
||||
if !priceRuleVoucherPair.Rule.IsAmountIndependentOfQty {
|
||||
discountApplied.DiscountAmount = roundToStep((orderDiscounts[article.ID].Quantity * priceRuleVoucherPair.Rule.Amount), calculationParameters.roundTo)
|
||||
} else {
|
||||
discountApplied.DiscountAmount = priceRuleVoucherPair.Rule.Amount
|
||||
}
|
||||
|
||||
discountApplied.DiscountSingle = priceRuleVoucherPair.Rule.Amount
|
||||
discountApplied.Quantity = orderDiscounts[article.ID].Quantity
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package pricerule
|
||||
|
||||
// CalculateDiscountsItemByPercent -
|
||||
func calculateDiscountsItemByPercent(priceRuleVoucherPair RuleVoucherPair, orderDiscounts OrderDiscounts, calculationParameters *CalculationParameters) OrderDiscounts {
|
||||
|
||||
if priceRuleVoucherPair.Rule.Action != ActionItemByPercent {
|
||||
panic("CalculateDiscountsItemByPercent called with pricerule of action " + priceRuleVoucherPair.Rule.Action)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func calculateItemSetAbsoluteDiscount(priceRuleVoucherPair RuleVoucherPair, orde
|
||||
tempPriceRule := *priceRuleVoucherPair.Rule
|
||||
tempPriceRule.Amount = cartDiscountAmount
|
||||
tempPriceRule.Action = ActionCartByAbsolute
|
||||
//tempPriceRule.IncludedProductGroupIDS = append(tempPriceRule.IncludedProductGroupIDS, orderItemsThatBelongToSet...)
|
||||
tempPriceRule.IsAmountIndependentOfQty = priceRuleVoucherPair.Rule.IsAmountIndependentOfQty
|
||||
log.Println("rule action ActionItemSetAbsolute internally converted to ActionCartAbsolute")
|
||||
priceRuleVoucherPair.Rule = &tempPriceRule
|
||||
return calculateDiscountsCartByAbsolute(priceRuleVoucherPair, orderDiscounts, calculationParameters)
|
||||
|
||||
@@ -52,6 +52,5 @@ func getTotalQuantityForRule(priceRule PriceRule, calculationParameters *Calcula
|
||||
totalQty += article.Quantity
|
||||
}
|
||||
}
|
||||
|
||||
return totalQty
|
||||
}
|
||||
|
||||
@@ -63,6 +63,8 @@ type PriceRule struct {
|
||||
|
||||
Amount float64 //the value depending on action
|
||||
|
||||
IsAmountIndependentOfQty bool // do we apply the discount as amount * qty // false by default
|
||||
|
||||
Priority int // the articleCollection in which rule is applied
|
||||
|
||||
ValidFrom time.Time // valid from timestamp
|
||||
@@ -153,6 +155,7 @@ func NewPriceRule(ID string) *PriceRule {
|
||||
priceRule.Description = map[string]string{}
|
||||
priceRule.Action = ActionItemByPercent
|
||||
priceRule.Amount = 0
|
||||
priceRule.IsAmountIndependentOfQty = false
|
||||
priceRule.MinOrderAmount = 0
|
||||
priceRule.QtyThreshold = 0
|
||||
priceRule.MaxUses = MaxInt
|
||||
@@ -168,6 +171,7 @@ func NewPriceRule(ID string) *PriceRule {
|
||||
priceRule.ValidTo = time.Date(9999, time.January, 1, 0, 0, 0, 0, time.UTC) // far in the future
|
||||
priceRule.WhichXYFree = XYCheapestFree
|
||||
priceRule.ItemSets = [][]string{}
|
||||
|
||||
return priceRule
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ func Init(t *testing.T) {
|
||||
checkVouchersExists(t)
|
||||
}
|
||||
|
||||
func TestBestOption(t *testing.T) {
|
||||
func testBestOption(t *testing.T) {
|
||||
RemoveAllGroups()
|
||||
RemoveAllPriceRules()
|
||||
RemoveAllVouchers()
|
||||
@@ -221,7 +221,7 @@ func TestBestOption(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func testDiscountFoItemSets(t *testing.T) {
|
||||
func TestDiscountFoItemSets(t *testing.T) {
|
||||
RemoveAllGroups()
|
||||
RemoveAllPriceRules()
|
||||
RemoveAllVouchers()
|
||||
@@ -242,7 +242,7 @@ func testDiscountFoItemSets(t *testing.T) {
|
||||
"fr": "itemset-discount",
|
||||
"it": "itemset-discount",
|
||||
}
|
||||
priceRule.Type = TypePromotionProduct
|
||||
priceRule.Type = TypePromotionOrder
|
||||
priceRule.Description = priceRule.Name
|
||||
priceRule.Action = ActionItemSetAbsolute
|
||||
priceRule.Amount = 10
|
||||
@@ -267,7 +267,7 @@ func testDiscountFoItemSets(t *testing.T) {
|
||||
positionVo := &Article{}
|
||||
positionVo.ID = ProductID1SKU1
|
||||
positionVo.Price = 100
|
||||
positionVo.Quantity = 2
|
||||
positionVo.Quantity = 4
|
||||
orderVo.Articles = append(orderVo.Articles, positionVo)
|
||||
|
||||
positionVo = &Article{}
|
||||
@@ -279,7 +279,7 @@ func testDiscountFoItemSets(t *testing.T) {
|
||||
positionVo = &Article{}
|
||||
positionVo.ID = ProductID3SKU2
|
||||
positionVo.Price = 500
|
||||
positionVo.Quantity = 33
|
||||
positionVo.Quantity = 5
|
||||
orderVo.Articles = append(orderVo.Articles, positionVo)
|
||||
|
||||
discountsVo, summary, err := ApplyDiscounts(orderVo, nil, []string{}, []string{PaymentMethodID1}, 0.05, nil)
|
||||
|
||||
Reference in New Issue
Block a user