Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.8 kB
1
Indexable
Never
{ if(cartProductFromCart.equals(cartProductToBeAdded))
{
cartProductFromCart.setQuantity(cartProductToBeAdded.getQuantity()+cartProductFromCar
t.getQuantity());
checkProductAlreadyPresent=true;
}
}
if(checkProductAlreadyPresent==false)
{
cart.getCartProducts().add(cartProductToBeAdded);
}
}
cartId=cart.getCartId();
}
returncartId;
}
//thismethodretrievescustomerdatafromrepositoryandreturnscartdetails
//ofthatcustomer
@Override
public Set<CartProductDTO> getProductsFromCart(String customerEmailId) throws
EKartCustomerCartException{
Optional<CustomerCart> cartOptional =
customerCartRepository.findByCustomerEmailId(customerEmailId);
Set<CartProductDTO>cartProductsDTO=newHashSet<>();
CustomerCartcart=cartOptional
.orElseThrow(() -> new
EKartCustomerCartException("CustomerCartService.NO_CART_FOUND"));
if(cart.getCartProducts().isEmpty()){
throw new
EKartCustomerCartException("CustomerCartService.NO_PRODUCT_ADDED_TO_CART");
}
Set<CartProduct>cartProducts=cart.getCartProducts();
for(CartProductcartProduct:cartProducts){
CartProductDTOcartProductDTO=newCartProductDTO();
cartProductDTO.setCartProductId(cartProduct.getCartProductId());
cartProductDTO.setQuantity(cartProduct.getQuantity());
ProductDTOproductDTO=newProductDTO();
productDTO.setProductId(cartProduct.getProductId());
cartProductDTO.setProduct(productDTO);
cartProductsDTO.add(cartProductDTO);
}
returncartProductsDTO;
}
//thismethodretrievescustomerdatafromrepositoryandreturnscartdetails
//ofthatcustomer
@Override
publicvoiddeleteProductFromCart(StringcustomerEmailId,IntegerproductId)throws
EKartCustomerCartException{
Optional<CustomerCart> cartOptional =
customerCartRepository.findByCustomerEmailId(customerEmailId);
CustomerCartcart=cartOptional