Skip to content

Commit

Permalink
Add Shippin fee
Browse files Browse the repository at this point in the history
  • Loading branch information
Chainarong Boonsangiem committed Mar 31, 2024
1 parent ee507c2 commit 347af35
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ public class CartResponse {
private BigDecimal subtotal;
private BigDecimal grandTotal;
private String promotionCodes;
private double shippingFee;
private BigDecimal shippingFee;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class CartItemService {

@Value("${enabled.shipping.fee:false}")
private boolean enableShippingFee;

private final CartItemRepository cartItemRepository;
private final CartRepository cartRepository;

Expand Down Expand Up @@ -46,8 +51,18 @@ public CartResponse getCartByUsername(String username) {
.map(BigDecimal::new)
.reduce(BigDecimal.ZERO, BigDecimal::add));

// shipping fee
if (enableShippingFee) {
cartResponse.setShippingFee(BigDecimal.valueOf(25));
} else {
cartResponse.setShippingFee(BigDecimal.valueOf(0));
}

cartResponse.setGrandTotal(
cartResponse.getSubtotal().subtract(cartResponse.getTotalDiscount()));
cartResponse.getSubtotal()
.subtract(cartResponse.getTotalDiscount())
.add(cartResponse.getShippingFee())
);

} else {
Cart cart = new Cart();
Expand Down

0 comments on commit 347af35

Please sign in to comment.