mirror of
https://github.com/foomo/shop.git
synced 2026-10-07 07:46:53 +00:00
Merge branch 'master' of github.com:foomo/shop
This commit is contained in:
@@ -30,7 +30,6 @@ func calculateDiscountsItemByAbsolute(priceRuleVoucherPair RuleVoucherPair, orde
|
||||
|
||||
func previouslyAppliedExclusionInPlace(rule *PriceRule, orderDiscountsForPosition DiscountCalculationData) bool {
|
||||
previouslyAppliedExclusion := false
|
||||
|
||||
if rule.Type == TypePromotionCustomer || rule.Type == TypePromotionProduct {
|
||||
if orderDiscountsForPosition.CustomerPromotionApplied || orderDiscountsForPosition.ProductPromotionApplied {
|
||||
previouslyAppliedExclusion = true
|
||||
|
||||
@@ -117,7 +117,7 @@ func ClearCache() {
|
||||
|
||||
// ApplyDiscounts applies all possible discounts on articleCollection ... if voucherCodes is "" the voucher is not applied
|
||||
// This is not yet used. ApplyDiscounts should at some point be able to consider previousle calculated discounts
|
||||
func ApplyDiscounts(articleCollection *ArticleCollection, existingDiscounts OrderDiscounts, voucherCodes []string, paymentMethod string, roundTo float64, customProvider PriceRuleCustomProvider) (OrderDiscounts, *OrderDiscountSummary, error) {
|
||||
func ApplyDiscounts(articleCollection *ArticleCollection, existingDiscounts OrderDiscounts, voucherCodes []string, paymentMethods []string, roundTo float64, customProvider PriceRuleCustomProvider) (OrderDiscounts, *OrderDiscountSummary, error) {
|
||||
calculationParameters := &CalculationParameters{}
|
||||
calculationParameters.articleCollection = articleCollection
|
||||
calculationParameters.roundTo = roundTo
|
||||
@@ -151,8 +151,8 @@ func ApplyDiscounts(articleCollection *ArticleCollection, existingDiscounts Orde
|
||||
|
||||
// find applicable payment discounts
|
||||
var paymentPriceRules []PriceRule
|
||||
if len(paymentMethod) > 0 {
|
||||
paymentPriceRules, err = GetValidPriceRulesForPaymentMethod(paymentMethod, customProvider)
|
||||
if len(paymentMethods) > 0 {
|
||||
paymentPriceRules, err = GetValidPriceRulesForPaymentMethods(paymentMethods, customProvider)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -243,7 +243,6 @@ func ApplyDiscounts(articleCollection *ArticleCollection, existingDiscounts Orde
|
||||
voucherDiscounts.DiscountAmount += appliedDiscount.DiscountAmountApplicable
|
||||
summary.VoucherDiscounts[appliedDiscount.VoucherCode] = voucherDiscounts
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,8 +165,8 @@ func CommitDiscounts(orderDiscounts *OrderDiscounts, customerID string) error {
|
||||
// IT IS IRREVERSIBLE!!!
|
||||
//
|
||||
// alternatively use CommitDiscounts
|
||||
func CommitOrderDiscounts(customerID string, articleCollection *ArticleCollection, voucherCodes []string, paymentMethod string, roundTo float64) error {
|
||||
orderDiscounts, _, err := ApplyDiscounts(articleCollection, nil, voucherCodes, paymentMethod, roundTo, nil)
|
||||
func CommitOrderDiscounts(customerID string, articleCollection *ArticleCollection, voucherCodes []string, paymentMethods []string, roundTo float64) error {
|
||||
orderDiscounts, _, err := ApplyDiscounts(articleCollection, nil, voucherCodes, paymentMethods, roundTo, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -261,8 +261,8 @@ func RemoveAllPriceRules() error {
|
||||
|
||||
// GetValidPriceRulesForPaymentMethod - find rule for payment
|
||||
// check ValidFrom, ValidTo
|
||||
func GetValidPriceRulesForPaymentMethod(paymentMethod string, customProvider PriceRuleCustomProvider) ([]PriceRule, error) {
|
||||
query := bson.M{"type": TypePaymentMethodDiscount, "includedpaymentmethods": bson.M{"$in": []string{paymentMethod}}, "validfrom": bson.M{"$lte": time.Now()}, "validto": bson.M{"$gte": time.Now()}}
|
||||
func GetValidPriceRulesForPaymentMethods(paymentMethods []string, customProvider PriceRuleCustomProvider) ([]PriceRule, error) {
|
||||
query := bson.M{"type": TypePaymentMethodDiscount, "includedpaymentmethods": bson.M{"$in": paymentMethods}, "validfrom": bson.M{"$lte": time.Now()}, "validto": bson.M{"$gte": time.Now()}}
|
||||
return getPromotions(query, customProvider)
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ func testShipping(t *testing.T) {
|
||||
positionVo.Quantity = 1
|
||||
orderVo.Articles = append(orderVo.Articles, positionVo)
|
||||
|
||||
discountsVo, summary, err := ApplyDiscounts(orderVo, nil, []string{""}, "", 0.05, nil)
|
||||
discountsVo, summary, err := ApplyDiscounts(orderVo, nil, []string{""}, []string{}, 0.05, nil)
|
||||
spew.Dump(discountsVo, summary, err)
|
||||
|
||||
}
|
||||
@@ -266,16 +266,15 @@ func testScaled(t *testing.T) {
|
||||
positionVo.Price = 500
|
||||
positionVo.Quantity = float64(2)
|
||||
orderVo.Articles = append(orderVo.Articles, positionVo)
|
||||
// Order -------------------------------------------------------------------------------
|
||||
|
||||
// Order -------------------------------------------------------------------------------
|
||||
now := time.Now()
|
||||
discountsVo, summary, err := ApplyDiscounts(orderVo, nil, []string{""}, "", 0.05, nil)
|
||||
discountsVo, summary, err := ApplyDiscounts(orderVo, nil, []string{""}, []string{}, 0.05, nil)
|
||||
timeTrack(now, "Apply scaled voucher")
|
||||
// defer removeOrder(orderVo)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("discounts for scaled percentage")
|
||||
spew.Dump(discountsVo)
|
||||
spew.Dump(*summary)
|
||||
@@ -341,7 +340,7 @@ func testBuyXGetY(t *testing.T) {
|
||||
positionVo.Quantity = float64(2)
|
||||
orderVo.Articles = append(orderVo.Articles, positionVo)
|
||||
// Order -------------------------------------------------------------------------------
|
||||
discountsVo, summary, err := ApplyDiscounts(orderVo, nil, []string{""}, "", 0.05, nil)
|
||||
discountsVo, summary, err := ApplyDiscounts(orderVo, nil, []string{""}, []string{}, 0.05, nil)
|
||||
// defer removeOrder(orderVo)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -405,7 +404,7 @@ func testExclude(t *testing.T) {
|
||||
log.Println(article.ID + " " + priceRule.ID + " " + strconv.FormatBool(ok))
|
||||
}
|
||||
|
||||
discountsVo, summary, err := ApplyDiscounts(orderVo, nil, []string{}, "blah", 0.05, nil)
|
||||
discountsVo, summary, err := ApplyDiscounts(orderVo, nil, []string{}, []string{"blah"}, 0.05, nil)
|
||||
spew.Dump(discountsVo)
|
||||
spew.Dump(*summary)
|
||||
|
||||
@@ -488,7 +487,7 @@ func testMaxOrder(t *testing.T) {
|
||||
|
||||
// PRICERULES --------------------------------------------------------------------------------------
|
||||
now := time.Now()
|
||||
discountsVo, summary, err := ApplyDiscounts(orderVo, nil, []string{}, PaymentMethodID1, 0.05, nil)
|
||||
discountsVo, summary, err := ApplyDiscounts(orderVo, nil, []string{}, []string{PaymentMethodID1}, 0.05, nil)
|
||||
timeTrack(now, "Apply multiple price rules")
|
||||
// defer removeOrder(orderVo)
|
||||
if err != nil {
|
||||
@@ -623,7 +622,7 @@ func testTwoStepWorkflow(t *testing.T) {
|
||||
|
||||
// PRICERULES --------------------------------------------------------------------------------------
|
||||
now := time.Now()
|
||||
discountsVo, summary, err := ApplyDiscounts(orderVo, nil, []string{VoucherCode2, VoucherCode1}, PaymentMethodID1, 0.05, nil)
|
||||
discountsVo, summary, err := ApplyDiscounts(orderVo, nil, []string{VoucherCode2, VoucherCode1}, []string{PaymentMethodID1}, 0.05, nil)
|
||||
timeTrack(now, "Apply multiple price rules")
|
||||
// defer removeOrder(orderVo)
|
||||
if err != nil {
|
||||
@@ -646,7 +645,7 @@ func testPricerulesWorkflow(t *testing.T) {
|
||||
panic(err)
|
||||
}
|
||||
now := time.Now()
|
||||
discountsVo, summary, err := ApplyDiscounts(orderVo, nil, []string{VoucherCode1}, PaymentMethodID1, 0.05, nil)
|
||||
discountsVo, summary, err := ApplyDiscounts(orderVo, nil, []string{VoucherCode1}, []string{PaymentMethodID1}, 0.05, nil)
|
||||
timeTrack(now, "Apply multiple price rules")
|
||||
// defer removeOrder(orderVo)
|
||||
if err != nil {
|
||||
@@ -669,7 +668,7 @@ func testCheckoutWorkflow(t *testing.T) {
|
||||
panic(err)
|
||||
}
|
||||
now := time.Now()
|
||||
discountsVo, _, err := ApplyDiscounts(orderVo, nil, []string{VoucherCode1}, PaymentMethodID1, 0.05, nil)
|
||||
discountsVo, _, err := ApplyDiscounts(orderVo, nil, []string{VoucherCode1}, []string{PaymentMethodID1}, 0.05, nil)
|
||||
timeTrack(now, "Apply multiple price rules")
|
||||
// defer removeOrder(orderVo)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user