mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-12 16:38:48 +00:00
falta precio completo del item del carrito y devolver que ya existe el presupuesto en el carro
This commit is contained in:
@ -5,13 +5,20 @@ import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.imprimelibros.erp.users.UserDetailsImpl;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.imprimelibros.erp.users.User;
|
||||
|
||||
import org.springframework.boot.autoconfigure.graphql.GraphQlProperties.Http;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/cart")
|
||||
@ -62,8 +69,15 @@ public class CartController {
|
||||
|
||||
/** Añadir presupuesto con ruta REST (opcional) */
|
||||
@PostMapping("/add/{presupuestoId}")
|
||||
public String addPath(@PathVariable Long presupuestoId, Principal principal) {
|
||||
public Object addPath(@PathVariable Long presupuestoId, Principal principal, HttpServletRequest request) {
|
||||
service.addPresupuesto(currentUserId(principal), presupuestoId);
|
||||
boolean isAjax = "XMLHttpRequest".equals(request.getHeader("X-Requested-With"));
|
||||
if (isAjax) {
|
||||
// Responder 200 con la URL a la que quieres ir
|
||||
return ResponseEntity.ok(
|
||||
Map.of("redirect", "/cart"));
|
||||
}
|
||||
// Navegación normal: redirección server-side
|
||||
return "redirect:/cart";
|
||||
}
|
||||
|
||||
|
||||
@ -70,7 +70,7 @@ public class CartService {
|
||||
elemento.put("cartItemId", item.getId());
|
||||
resultados.add(elemento);
|
||||
}
|
||||
System.out.println("Cart items: " + resultados);
|
||||
//System.out.println("Cart items: " + resultados);
|
||||
return resultados;
|
||||
}
|
||||
|
||||
|
||||
@ -274,13 +274,16 @@ export default class PresupuestoWizard {
|
||||
$('.add-cart-btn').on('click', async () => {
|
||||
const success = await this.#guardarPresupuesto();
|
||||
if (success) {
|
||||
await $.ajax({
|
||||
const res = await $.ajax({
|
||||
url: `/cart/add/${this.opts.presupuestoId}`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
|
||||
// Si el backend devuelve { redirect: "/cart" }
|
||||
if (res?.redirect) {
|
||||
window.location.assign(res.redirect); // o replace()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -843,7 +846,7 @@ export default class PresupuestoWizard {
|
||||
const errors = xhr.responseJSON;
|
||||
if (errors && typeof errors === 'object') {
|
||||
this.interior_alert.find('#form-errors-alert-list').append(`<li>${errors.message}</li>`);
|
||||
|
||||
|
||||
}
|
||||
console.error("Error al obtener los gramajes de interior: ", xhr.responseText);
|
||||
});
|
||||
|
||||
@ -53,14 +53,15 @@
|
||||
<form th:action="@{|/cart/${item.cartItemId}/remove|}" method="post" class="d-inline">
|
||||
<input type="hidden" name="_method" value="delete" />
|
||||
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}" />
|
||||
<button type="submit" class="btn btn-sm btn-link text-body p-1 px-2">
|
||||
<a href="#" class="d-block text-body p-1 px-2"
|
||||
onclick="this.closest('form').submit(); return false;">
|
||||
<i class="ri-delete-bin-fill text-muted align-bottom me-1"></i> Eliminar
|
||||
</button>
|
||||
</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user