terminado carrito

This commit is contained in:
2025-10-31 11:36:03 +01:00
parent 90c191d8f8
commit 40dc719e89
13 changed files with 234 additions and 59 deletions

View File

@ -112,8 +112,9 @@ public class CartService {
@Transactional
public void removeByPresupuesto(Long userId, Long presupuestoId) {
Cart cart = getOrCreateActiveCart(userId);
itemRepo.findByCartIdAndPresupuestoId(cart.getId(), presupuestoId)
.ifPresent(itemRepo::delete);
CartItem item = itemRepo.findByCartIdAndPresupuestoId(cart.getId(), presupuestoId)
.orElseThrow(() -> new IllegalArgumentException("Item no encontrado"));
itemRepo.deleteById(item.getId());
}
/** Vacía todo el carrito activo. */
@ -355,6 +356,33 @@ public class CartService {
}
}
public Boolean moveCartToCustomer(Long cartId, Long customerId) {
try {
// Remove the cart from the customer if they have one
Cart existingCart = cartRepo.findByUserIdAndStatus(customerId, Cart.Status.ACTIVE)
.orElse(null);
if (existingCart != null) {
cartRepo.delete(existingCart);
}
Cart cart = cartRepo.findById(cartId)
.orElseThrow(() -> new IllegalArgumentException("Carrito no encontrado"));
cart.setUserId(customerId);
cartRepo.save(cart);
return true;
} catch (Exception e) {
// Manejo de excepciones
return false;
}
}
/***************************************
* MÉTODOS PRIVADOS
***************************************/
private Map<String, Object> getShippingCost(
CartDireccion cd,
Double peso,