Skip to content

✨ Sync Host Cart on VTEX IO After WebChat Add-to-Cart#87

Open
cristiantela wants to merge 2 commits intov3-mainfrom
feat/update-for-vtex-io
Open

✨ Sync Host Cart on VTEX IO After WebChat Add-to-Cart#87
cristiantela wants to merge 2 commits intov3-mainfrom
feat/update-for-vtex-io

Conversation

@cristiantela
Copy link
Copy Markdown
Collaborator

Description

Type of Change

    • Bugfix
    • Feature
    • Code style update (formatting, local variables)
    • Refactoring (no functional changes, no api changes)
    • Tests
    • Other

Motivation and Context

After a product is added through the webchat, the host storefront should reflect the new cart. FastStore exposes faststore_sdk_stores so the cart can be refreshed with a simple read/set. On VTEX IO storefronts that is not available, so the minicart could stay stale even though the checkout order form was updated server-side. This change adds a fallback that refreshes the VTEX IO minicart by syncing React state with the latest order form when FastStore sync is not used.

Summary of Changes

  • Added src/utils/VTEXIOMinicartBridge.js: loads the current order form from /api/checkout/pub/orderForm?allowedOutdatedData=false, locates a minicart-related DOM node, walks the React fiber tree to find an OrderForm-style provider and the hook whose state includes items[], then dispatches the fresh order form (and attempts to refresh adjacent numeric hooks used as item count). Exposes updateVTEXIOMinicart and registers window.updateMinicart for manual or external use after cart changes. Errors are handled internally so failures do not break the webchat flow.
  • OrderFormContext: replaced trySyncFaststoreCart with trySyncHostCart. It first tries FastStore’s cart store when present; if that path does not apply or throws, it awaits updateVTEXIOMinicart() inside a try/catch so VTEX IO sync never propagates errors to the UI.
  • CounterControls: after a successful add-to-cart, calls void trySyncHostCart() so the async host sync is fire-and-forget without an unhandled promise.

@cristiantela cristiantela requested a review from Aldemylla as a code owner April 16, 2026 19:56
@cristiantela cristiantela marked this pull request as draft April 16, 2026 19:56
@cristiantela cristiantela marked this pull request as ready for review April 16, 2026 20:14
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.

2 participants