Include shipping cost in total, refactor shipping functions
parent
83d0262e73
commit
68d378d9ac
|
|
@ -12,7 +12,7 @@ public class Order {
|
|||
}
|
||||
|
||||
public float calculateTotalPriceWithVat() {
|
||||
return calculateTotalPrice() + calculateTotalVat();
|
||||
return calculateTotalPrice() + calculateTotalVat() + calculateShippingCost();
|
||||
}
|
||||
|
||||
public float calculateTotalPrice() {
|
||||
|
|
@ -20,22 +20,27 @@ public class Order {
|
|||
}
|
||||
|
||||
public float calculateTotalVat() {
|
||||
return getVat(this.products);
|
||||
return getVat(this.products) + calculateShippingVat(this.products);
|
||||
}
|
||||
|
||||
public float calculateShippingVat() {
|
||||
float totalWeight = calculateWeight(this.products);
|
||||
public float calculateShippingCost() {
|
||||
return calculateShippingCost(this.products);
|
||||
}
|
||||
|
||||
public float calculateShippingVat(List<Product> products) {
|
||||
float totalPrice = calculateTotalPrice();
|
||||
float baseShippingCost = calculateBaseShippingCost(totalWeight, totalPrice);
|
||||
List<Product> lowVatProducts = filterLowVatProducts(this.products);
|
||||
List<Product> highVatProducts = filterHighVatProducts(this.products);
|
||||
float baseShippingCost = calculateShippingCost(products);
|
||||
List<Product> lowVatProducts = filterLowVatProducts(products);
|
||||
List<Product> highVatProducts = filterHighVatProducts(products);
|
||||
float lowVatPortion = getPrice(lowVatProducts) / totalPrice;
|
||||
float highVatPortion = getPrice(highVatProducts) / totalPrice;
|
||||
return baseShippingCost * lowVatPortion / (1 + Constants.lowVat) + baseShippingCost * highVatPortion / (1 + Constants.highVat);
|
||||
}
|
||||
|
||||
public float calculateBaseShippingCost(float totalWeight, float price) {
|
||||
if (price >= 500f)
|
||||
public float calculateShippingCost(List<Product> products) {
|
||||
float totalWeight = calculateWeight(products);
|
||||
float totalPrice = calculateTotalPrice();
|
||||
if (totalPrice >= 500f)
|
||||
return 0f;
|
||||
if (totalWeight <= 0.1f)
|
||||
return 3.95f;
|
||||
|
|
|
|||
Loading…
Reference in New Issue