Beispiel #1
0
Datei: atp.go Projekt: foomo/shop
func CreateATPRequestFromOrder(order *order.Order) *ATPRequest {

	requestItems := []*RequestItem{}
	for _, position := range order.GetPositions() {

		reqItem := &RequestItem{
			AssociatedOrder:     order,
			ItemNumber:          position.ItemID,
			DesiredQuantity:     position.Quantity,
			QuantityUnit:        position.QuantityUnit,
			DesiredDeliveryDate: order.GetLastModifiedAt().Add(time.Duration(1) * time.Hour * time.Duration(24)), // set day after orderdate as default for DesiredDeliveryDate
		}
		requestItems = append(requestItems, reqItem)
	}

	return &ATPRequest{
		Items: requestItems,
	}

}
Beispiel #2
0
// CalculateDiscountsCartByAbsolute -
func calculateDiscountsCartByAbsolute(order *order.Order, priceRuleVoucherPair RuleVoucherPair, orderDiscounts OrderDiscounts, productGroupIDsPerPosition map[string][]string, groupIDsForCustomer []string, roundTo float64) OrderDiscounts {
	if priceRuleVoucherPair.Rule.Action != ActionCartByAbsolute {
		panic("CalculateDiscountsCartByAbsolute called with pricerule of action " + priceRuleVoucherPair.Rule.Action)
	}

	//collect item values = price * qty for applicable items
	amounts := getAmountsOfApplicablePositions(priceRuleVoucherPair.Rule, order, productGroupIDsPerPosition, groupIDsForCustomer)

	// the tricky part - stolen code from Florian - distribute the amount proportional to the price
	distributedAmounts, err := Distribute(amounts, priceRuleVoucherPair.Rule.Amount)
	distribution := map[string]float64{}
	for i, distributedAmount := range distributedAmounts {
		distribution[order.GetPositions()[i].ItemID] = distributedAmount
	}

	if err != nil {
		panic(err)
	}

	for _, position := range order.Positions {

		// if we have the distributed amount
		if discountAmount, ok := distribution[position.ItemID]; ok {
			// and rule can still be applied
			orderDiscountsForPosition := orderDiscounts[position.ItemID]

			if !orderDiscounts[position.ItemID].StopApplyingDiscounts && ok && !previouslyAppliedExclusionInPlace(priceRuleVoucherPair.Rule, orderDiscountsForPosition) {
				if !orderDiscounts[position.ItemID].StopApplyingDiscounts {
					//apply the discount here
					discountApplied := getInitializedDiscountApplied(priceRuleVoucherPair, orderDiscounts, position.ItemID)

					//calculate the actual discount
					discountApplied.DiscountAmount = discountAmount
					discountApplied.DiscountSingle = discountAmount / orderDiscounts[position.ItemID].Quantity
					discountApplied.Quantity = orderDiscounts[position.ItemID].Quantity

					//pointer assignment WTF !!!
					orderDiscountsForPosition := orderDiscounts[position.ItemID]
					orderDiscountsForPosition = calculateCurrentPriceAndApplicableDiscountsEnforceRules(*discountApplied, position.ItemID, orderDiscountsForPosition, orderDiscounts, *priceRuleVoucherPair.Rule, roundTo)

					orderDiscounts[position.ItemID] = orderDiscountsForPosition
				}
			}
		}
	}
	return orderDiscounts
}
Beispiel #3
0
func removeOrder(order *order.Order) {
	order.Delete()
}