Repository navigation
[v4 beta][plugin-ecommerce] Guest cart merge ignores the configured cartItemMatcher #19422
|
Configure a custom cart item field via cartsCollectionOverride and include it in carts.cartItemMatcher. Put the same product and variant in an existing account cart and a guest cart, with different values for that field. Then sign in as the account owner. Expected: Two separate line items, each retaining its custom field value. Reproduced with @payloadcms/plugin-ecommerce@4.0.0-beta.7. In createCartsCollection, addItemEndpoint receives cartItemMatcher, but mergeCartEndpoint does not. The merge endpoint already accepts the matcher, so the proposed fix is to pass it during registration. |
Replies: 1 comment
|
Your reading is right for beta.7, and main still has the same line. In The comment above that line hints at why it was left out: the types don't line up. At runtime it's safe. Until it's fixed you can't swap the endpoint through pnpm patch @payloadcms/plugin-ecommerce@4.0.0-beta.7In mergeCartEndpoint({
+ cartItemMatcher,
cartsSlug
}),Then run |
Your reading is right for beta.7, and main still has the same line. In
createCartsCollection.tsonlyaddItemEndpointgetscartItemMatcher.mergeCartEndpoint({ cartsSlug })gets none, so the merge operation falls back todefaultMergeItemMatcher, which compares product and variant IDs only.The comment above that line hints at why it was left out: the types don't line up.
CartItemMatchertakesnewItem: NewCartItem, where product/variant are plain IDs, while the merge matcher takesnewItem: CartItemData, where they can be populated docs. Passing the plugin matcher straight through doesn't type-check, so the fix needs a cast or a wider matcher type.At runtime it's safe.
mergeCartloads both …