package io.github.zutherb.appstash.shop.service.cart.impl;

import io.github.zutherb.appstash.shop.service.cart.model.CartItemInfo;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import io.github.zutherb.appstash.shop.Config;

public abstract class AbstractFulfillmentProvider {
    
    public BigDecimal getTotalSum() {
        BigDecimal sum = BigDecimal.ZERO;
        for (CartItemInfo cartItemInfo : getAllItems()) {
            sum = sum.add(cartItemInfo.getTotalSum());
        }
        
        double globalDiscount = Double.parseDouble(Config.getProperty("GLOBAL_DISCOUNT"));
        double factor = globalDiscount/100.0; 
        double result = sum.doubleValue() - (sum.doubleValue() * factor);
        return new BigDecimal(result);
    }
    
    public BigDecimal getDiscountSum() {
        BigDecimal sum = BigDecimal.ZERO;
        for (CartItemInfo cartItemInfo : getAllItems()) {
            sum = sum.add(cartItemInfo.getTotalSum());
        }

        double globalDiscount = Double.parseDouble(Config.getProperty("GLOBAL_DISCOUNT"));
        double factor = globalDiscount/100.0;
        double result = sum.doubleValue() * factor;
        
        return new BigDecimal(result);
    }

    public abstract List<CartItemInfo> getAllItems();
}

@@ -124,16 +124,63 @@
 temInfo;
+%0Aimport io.github.zutherb.appstash.shop.Config;
 %0A%0Aimport

Update AbstractFulfillmentProvider.java