Skip to content

fix(plugin-ecommerce): return CartOperationResult and propagate errors in cart operations#16081

Open
teastudiopl wants to merge 4 commits intopayloadcms:mainfrom
teastudiopl:fix/cart-return-operation-result
Open

fix(plugin-ecommerce): return CartOperationResult and propagate errors in cart operations#16081
teastudiopl wants to merge 4 commits intopayloadcms:mainfrom
teastudiopl:fix/cart-return-operation-result

Conversation

@teastudiopl
Copy link
Copy Markdown
Contributor

@teastudiopl teastudiopl commented Mar 27, 2026

Previously, addItem, removeItem, incrementItem, decrementItem and clearCart
swallowed errors in catch blocks and returned void, making it impossible for
consumers to determine whether an operation succeeded or failed.

Changes:

  • return CartOperationResult (including refreshed cart) on success
  • re-throw errors in catch blocks so consumers can use try/catch
  • update defaultContext placeholders to match new return types

This allows consumers to handle cart operation results:

  try {
   const result: CartOperationResult | undefined  = await addItem(newItem)
    // result contains the updated cart and success (true/false) flag
  } catch (error) {
    // handle failure
  }

usage:

    
        try {
          const result = await addItem(newItem)

          console.log(result)

          result?.success ? toast.success(t('addedToCart')) : toast.error(t('failedAddedToCart'))
        } catch (error) {
          toast.error(t('failedAddedToCart'))
        }


      

@teastudiopl teastudiopl changed the title fix(cart): return CartOperationResult and propagate errors in cart operations fix(plugin-eccommerce): return CartOperationResult and propagate errors in cart operations Mar 27, 2026
@teastudiopl teastudiopl changed the title fix(plugin-eccommerce): return CartOperationResult and propagate errors in cart operations fix(plugin-ecommerce): return CartOperationResult and propagate errors in cart operations Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant