Skip to content

fix: restaurar carrito al volver del redirect sin completar pago#2

Open
mateogs wants to merge 1 commit intomainfrom
feature/fix-cart-restore-on-back
Open

fix: restaurar carrito al volver del redirect sin completar pago#2
mateogs wants to merge 1 commit intomainfrom
feature/fix-cart-restore-on-back

Conversation

@mateogs
Copy link
Copy Markdown
Collaborator

@mateogs mateogs commented Mar 19, 2026

Contexto

Cuando el cliente vuelve al store sin completar el pago en Fintoc (usando el botón atrás del navegador, cerrando la pestaña, etc.), el carrito aparece vacío. Esto ocurre porque Magento consume el quote al crear la orden antes del redirect.

Causa raíz

El flujo actual es:

  1. placeOrderAction() en el JS crea la orden → consume el quote (carrito)
  2. Se llama a /fintoc/checkout/create → redirige al usuario a Fintoc
  3. Si el usuario usa el botón atrás del navegador, nunca pasa por el Commit controller
  4. El Commit controller (acción cancel) ya tiene restoreQuote(), pero solo se ejecuta cuando Fintoc redirige a la cancel_url

Solución

Se agrega un plugin (before-interceptor) en Magento\Checkout\Controller\Cart\Index que detecta la situación y restaura el quote automáticamente.

El plugin verifica las siguientes condiciones antes de restaurar:

Condición Acción
No hay orden reciente o no es Fintoc No hace nada
Orden en estado terminal (PROCESSING, CANCELED, etc.) No hace nada
Pago ya marcado como exitoso (fintoc_transaction_status = success) No hace nada
Carrito ya tiene productos No hace nada
Orden Fintoc pendiente + carrito vacío Restaura el quote

Archivos agregados

  • Plugin/RestoreQuoteOnCartLoad.php — Plugin con la lógica de restauración
  • etc/frontend/di.xml — Registro del plugin (scope frontend)

Plan de pruebas

  • Iniciar pago con Fintoc, usar botón atrás del navegador → carrito debe restaurarse
  • Completar pago exitosamente → carrito NO debe restaurarse al visitar /checkout/cart
  • Cancelar pago vía botón de Fintoc (cancel_url) → carrito debe restaurarse (flujo existente, sin regresión)
  • Visitar carrito sin orden Fintoc pendiente → sin efecto
  • Requiere bin/magento setup:upgrade + bin/magento cache:flush post-deploy

🤖 Generated with Claude Code

Magento consumes the quote when the order is placed. If the customer
navigates back from Fintoc without completing payment, the cart
appeared empty even though items were still in the database.

Changes:

- Create controller: restore the quote after obtaining the redirect URL
  so the cart stays active during the external payment flow.
- JS payment renderer: reload the cart customer-data section before
  redirecting to Fintoc so localStorage reflects the restored cart.
- Commit controller (success path): deactivate the quote, clear the
  session, and set order data so the success page renders correctly.
- Success template: inline JS to invalidate and reload the cart section
  so the mini-cart clears after successful payment.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mateogs mateogs force-pushed the feature/fix-cart-restore-on-back branch from d06769c to 47e8166 Compare March 31, 2026 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant